Skip to content

Instantly share code, notes, and snippets.

@dhont
Last active December 22, 2015 07:49
Show Gist options
  • Save dhont/6441082 to your computer and use it in GitHub Desktop.
Save dhont/6441082 to your computer and use it in GitHub Desktop.
using System;
using AutoMapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AutoMapperSpecificTests
{
public class FirstClass
{
public Guid? SomeGuidProperty { get; set; }
public Guid? SomeAloneProperty { get; set; }
public int OtherProperty { get; set; }
}
public class SecondClass
{
public Guid SomeGuidProperty { get; set; }
public int OtherProperty { get; set; }
}
[TestClass]
public class AutoMapperGuidTests
{
//[AssemblyInitialize]
//public static void TestInit(TestContext context)
//{
//}
[TestMethod]
public void FromGivenGuidToNullableGuid()
{
// Arrange
var s = new SecondClass { SomeGuidProperty = Guid.NewGuid() };
// Act
var f = Mapper.Map<FirstClass>(s);
// Assert
Assert.AreEqual(s.SomeGuidProperty, f.SomeGuidProperty);
}
[TestMethod]
public void FromMissingGuidToEmptyGuid()
{
// Arrange
var s = new SecondClass { OtherProperty = 33 };
// Act
var f = Mapper.Map<FirstClass>(s);
// Assert
Assert.AreEqual(f.SomeGuidProperty, Guid.Empty);
}
[TestMethod]
public void DestinationMisssingGuidIsInitalizedAsNull()
{
// Arrange
var s = new SecondClass { OtherProperty = 33 };
// Act
var f = Mapper.Map<FirstClass>(s);
// Assert
Assert.AreEqual(null,f.SomeAloneProperty);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment