-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lbargaoanu-ReverseMap_ReplaceMemberName_bug_832' into d…
…evelop Fixes #832
- Loading branch information
Showing
6 changed files
with
130 additions
and
9 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,107 @@ | ||
using Xunit; | ||
using Should; | ||
using System; | ||
|
||
namespace AutoMapper.UnitTests.Bug | ||
{ | ||
public class ReverseMapAndReplaceMemberName : AutoMapperSpecBase | ||
{ | ||
const string SomeId = "someId"; | ||
const string SomeOtherId = "someOtherId"; | ||
private Source _source; | ||
private Destination _destination; | ||
|
||
class Source | ||
{ | ||
public string AccountId { get; set; } | ||
} | ||
class Destination | ||
{ | ||
public string UserId { get; set; } | ||
} | ||
|
||
protected override void Establish_context() | ||
{ | ||
Mapper.Initialize(cfg => | ||
{ | ||
cfg.ReplaceMemberName("Account", "User"); | ||
cfg.ReplaceMemberName("User", "Account"); | ||
cfg.CreateMap<Source, Destination>().ReverseMap(); | ||
}); | ||
} | ||
|
||
protected override void Because_of() | ||
{ | ||
_source = Mapper.Map<Destination, Source>(new Destination | ||
{ | ||
UserId = SomeId | ||
}); | ||
_destination = Mapper.Map<Source, Destination>(new Source | ||
{ | ||
AccountId = SomeOtherId | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Should_work_together() | ||
{ | ||
_source.AccountId.ShouldEqual(SomeId); | ||
_destination.UserId.ShouldEqual(SomeOtherId); | ||
} | ||
} | ||
|
||
public class ReverseMapAndReplaceMemberNameWithProfile : AutoMapperSpecBase | ||
{ | ||
const string SomeId = "someId"; | ||
const string SomeOtherId = "someOtherId"; | ||
private Source _source; | ||
private Destination _destination; | ||
|
||
class Source | ||
{ | ||
public string AccountId { get; set; } | ||
} | ||
|
||
class Destination | ||
{ | ||
public string UserId { get; set; } | ||
} | ||
|
||
class MyProfile : Profile | ||
{ | ||
protected override void Configure() | ||
{ | ||
ReplaceMemberName("Account", "User"); | ||
ReplaceMemberName("User", "Account"); | ||
CreateMap<Source, Destination>().ReverseMap(); | ||
} | ||
} | ||
|
||
protected override void Establish_context() | ||
{ | ||
Mapper.Initialize(cfg => | ||
{ | ||
cfg.AddProfile<MyProfile>(); | ||
}); | ||
} | ||
|
||
protected override void Because_of() | ||
{ | ||
_source = Mapper.Map<Destination, Source>(new Destination | ||
{ | ||
UserId = SomeId | ||
}); | ||
_destination = Mapper.Map<Source, Destination>(new Source | ||
{ | ||
AccountId = SomeOtherId | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Should_work_together() | ||
{ | ||
_source.AccountId.ShouldEqual(SomeId); | ||
_destination.UserId.ShouldEqual(SomeOtherId); | ||
} | ||
} | ||
} |
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