Created
September 11, 2020 20:24
-
-
Save mxmissile/4ca97bcc62e60f8ec3f8e556f177f156 to your computer and use it in GitHub Desktop.
automapper test
This file contains hidden or 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
| public void mappingtest() | |
| { | |
| var config = new MapperConfiguration(cfg => | |
| { | |
| cfg.CreateMap<Asset, AssetDetailsDTO>() | |
| .ForMember(dto => dto.RequestId, conf => conf.MapFrom(x => x.Request.UUID)); | |
| }); | |
| var mapper = config.CreateMapper(); | |
| var guid = Guid.NewGuid(); | |
| var request = new Request {Id = 10, UUID = guid}; | |
| var asset = new Asset {Request = request}; | |
| var result = mapper.Map<AssetDetailsDTO>(asset); | |
| result.RequestId.Equal(guid); | |
| } | |
| public class Request | |
| { | |
| public int Id { get; set; } | |
| public Guid UUID { get; set; } | |
| public ICollection<Asset> Assets { get; set; } | |
| } | |
| public class Asset | |
| { | |
| public int RequestId { get; set; } | |
| public Request Request { get; set; } | |
| } | |
| public class AssetDetailsDTO | |
| { | |
| public Guid RequestId { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment