forked from MapsterMapper/Mapster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MapsterMapper#6 from chaowlert/unit-test
Unit tests for primitive types & complex type support
- Loading branch information
Showing
11 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Should; | ||
|
||
namespace Mapster.Tests | ||
{ | ||
[TestFixture] | ||
public class WhenAddingPrimitiveTypes | ||
{ | ||
[TearDown] | ||
public void TearDown() | ||
{ | ||
TypeAdapterConfig.GlobalSettings.PrimitiveTypes.Clear(); | ||
} | ||
|
||
[Test] | ||
public void No_Primitive_Uri_Should_Throw() | ||
{ | ||
TypeAdapter.ClearCache(); | ||
var sourceUri = new Uri("http:https://example.com"); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(() => TypeAdapter.Adapt<Uri, Uri>(sourceUri)); | ||
Console.WriteLine(exception.Message); | ||
|
||
exception.ParamName.ShouldEqual("con"); | ||
} | ||
|
||
[Test] | ||
public void Set_Primitive_Uri_Success() | ||
{ | ||
TypeAdapter.ClearCache(); | ||
TypeAdapterConfig.GlobalSettings.PrimitiveTypes.Add(typeof(Uri)); | ||
|
||
var sourceUri = new Uri("http:https://example.com"); | ||
var targetUri = TypeAdapter.Adapt<Uri, Uri>(sourceUri); | ||
|
||
targetUri.ShouldEqual(sourceUri); | ||
} | ||
|
||
[Test] | ||
public void No_Primitive_Uri_Property_Should_Throw() | ||
{ | ||
TypeAdapterConfig<SimplePoco, SimplePoco>.Clear(); | ||
var sourceDto = new SimplePoco | ||
{ | ||
Id = 1, | ||
Website = new Uri("http:https://example.com"), | ||
}; | ||
|
||
var exception = Assert.Throws<InvalidOperationException>(() => TypeAdapter.Adapt<SimplePoco, SimplePoco>(sourceDto)); | ||
Console.WriteLine(exception.Message); | ||
|
||
var innerException = exception.InnerException; | ||
innerException.ShouldBeType<ArgumentNullException>(); | ||
((ArgumentNullException)innerException).ParamName.ShouldEqual("con"); | ||
} | ||
|
||
[Test] | ||
public void Set_Primitive_Uri_Property_Success() | ||
{ | ||
TypeAdapterConfig<SimplePoco, SimplePoco>.Clear(); | ||
TypeAdapterConfig.GlobalSettings.PrimitiveTypes.Add(typeof(Uri)); | ||
|
||
var sourceDto = new SimplePoco | ||
{ | ||
Id = 1, | ||
Website = new Uri("http:https://example.com"), | ||
}; | ||
var targetDto = TypeAdapter.Adapt<SimplePoco, SimplePoco>(sourceDto); | ||
|
||
targetDto.Website.ShouldEqual(sourceDto.Website); | ||
} | ||
#region TestClasses | ||
|
||
public class SimplePoco | ||
{ | ||
public int Id { get; set; } | ||
public Uri Website { get; set; } | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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
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
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
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
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
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