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#18 from chaowlert/explicit-mapping
Explicit mapping
- Loading branch information
Showing
10 changed files
with
144 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using Mapster.Tests.Classes; | ||
using NUnit.Framework; | ||
using Should; | ||
|
||
namespace Mapster.Tests | ||
{ | ||
/// <summary> | ||
/// Not trying to test core testing here...just a few tests to make sure the extension method approach doesn't hose anything | ||
/// </summary> | ||
[TestFixture] | ||
public class WhenMappingWithExtensionMethods | ||
{ | ||
|
||
[Test] | ||
public void Adapt_With_Source_And_Destination_Type_Succeeds() | ||
{ | ||
TypeAdapterConfig<Product, ProductDTO>.NewConfig() | ||
.Compile(); | ||
|
||
var product = new Product { Id = Guid.NewGuid(), Title = "ProductA", CreatedUser = new User { Name = "UserA" } }; | ||
|
||
var dto = product.Adapt<Product, ProductDTO>(); | ||
|
||
dto.ShouldNotBeNull(); | ||
dto.Id.ShouldEqual(product.Id); | ||
} | ||
|
||
[Test] | ||
public void Adapt_With_Source_And_Destination_Types_And_Config_Succeeds() | ||
{ | ||
var config = new TypeAdapterConfig(); | ||
config.ForType<Product, ProductDTO>(); | ||
|
||
|
||
var product = new Product { Id = Guid.NewGuid(), Title = "ProductA", CreatedUser = new User { Name = "UserA" } }; | ||
|
||
var dto = product.Adapt<Product, ProductDTO>(config); | ||
|
||
dto.ShouldNotBeNull(); | ||
dto.Id.ShouldEqual(product.Id); | ||
} | ||
|
||
[Test] | ||
public void Adapt_With_Destination_Type_Succeeds() | ||
{ | ||
TypeAdapterConfig<Product, ProductDTO>.NewConfig() | ||
.Compile(); | ||
|
||
var product = new Product { Id = Guid.NewGuid(), Title = "ProductA", CreatedUser = new User { Name = "UserA" } }; | ||
|
||
var dto = product.Adapt<ProductDTO>(); | ||
|
||
dto.ShouldNotBeNull(); | ||
dto.Id.ShouldEqual(product.Id); | ||
} | ||
|
||
[Test] | ||
public void Adapt_With_Destination_Type_And_Config_Succeeds() | ||
{ | ||
var config = new TypeAdapterConfig(); | ||
config.ForType<Product, ProductDTO>(); | ||
|
||
|
||
var product = new Product { Id = Guid.NewGuid(), Title = "ProductA", CreatedUser = new User { Name = "UserA" } }; | ||
|
||
var dto = product.Adapt<ProductDTO>(config); | ||
|
||
dto.ShouldNotBeNull(); | ||
dto.Id.ShouldEqual(product.Id); | ||
} | ||
} | ||
} |
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