Last active
December 22, 2015 07:49
-
-
Save dhont/6441082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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