public void AutoMapperTypeAdapterAdaptEntityEnumerable() { var typeAdapter = new AutomapperTypeAdapter(); var blog = new Blog() { BlogId = 1, Name = "Name", Rating = 0, Url = "Url" }; //act var dto = typeAdapter.Adapt <IEnumerable <Blog>, List <BlogDTO> >(new Blog[] { blog }); //Assert Assert.NotNull(dto); Assert.True(dto.Count == 1); Assert.Equal(dto[0].BlogId, blog.BlogId); Assert.Equal(dto[0].Name, blog.Name); Assert.Equal(dto[0].Rating, blog.Rating); Assert.Equal(dto[0].Url, blog.Url); }
/// <summary> /// Project a type using a DTO /// </summary> /// <typeparam name="TProjection">The dto projection</typeparam> /// <param name="entity">The source entity to project</param> /// <returns>The projected type</returns> public static TProjection ProjectedAs <TProjection>(this Entity entity) where TProjection : class, new() { var adapter = new AutomapperTypeAdapter(); return(adapter.Adapt <TProjection>(entity)); }
/// <summary> /// projected a enumerable collection of items /// </summary> /// <typeparam name="TProjection">The dtop projection type</typeparam> /// <param name="items">the collection of entity items</param> /// <returns>Projected collection</returns> public static List <TProjection> ProjectedAsCollection <TProjection>(this IEnumerable <Entity> items) where TProjection : class, new() { var adapter = new AutomapperTypeAdapter(); return(adapter.Adapt <List <TProjection> >(items)); }
public void AdapterToDTOLista() { //Prepara Mapper.Initialize(cfg => cfg.AddProfile(new ClienteAdapterProfile())); var adapter = new AutomapperTypeAdapter(); Cliente cliente = new Cliente() { Id = 1, Nome = "Marcus Dorbação", Endereco = "Rua Campo Grande 2104", DataNascimento = new DateTime(1986, 06, 18) }; //Executa var clienteDTO = adapter.Adapt <IEnumerable <Cliente>, List <ClienteDTO> >(new Cliente[] { cliente }); //Valida Assert.IsNotNull(clienteDTO); Assert.IsTrue(clienteDTO.Count == 1); Assert.AreEqual(clienteDTO[0].Codigo, cliente.Id.ToString()); Assert.AreEqual(clienteDTO[0].NomeCliente, cliente.Nome); Assert.AreEqual(clienteDTO[0].DataNascimentoCliente, cliente.DataNascimento.ToShortDateString()); }
public void AutoMapperTypeAdapterAdaptEntityEnumerable() { //Arrange Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile())); var typeAdapter = new AutomapperTypeAdapter(); var customer = new Customer() { Id = 1, FirstName = "Jhon", LastName = "Bep" }; //act var dto = typeAdapter.Adapt<IEnumerable<Customer>, List<CustomerDto>>( new Customer[] { customer }); //Assert Assert.IsNotNull(dto); Assert.IsTrue(dto.Count == 1); Assert.AreEqual(dto[0].CustomerId, customer.Id); Assert.AreEqual(dto[0].FullName, string.Format("{0},{1}", customer.LastName, customer.FirstName)); }
public void AutoMapperTypeAdapterAdaptEntity() { //Arrange Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile())); var typeAdapter = new AutomapperTypeAdapter(); var blog = new Blog() { BlogId = 1, Name = "Name", Rating = 0, Url = "Url" }; //act var dto = typeAdapter.Adapt <Blog, BlogDTO>(blog); //Assert Assert.NotNull(dto); Assert.Equal(dto.BlogId, blog.BlogId); Assert.Equal(dto.Name, blog.Name); Assert.Equal(dto.Rating, blog.Rating); Assert.Equal(dto.Url, blog.Url); }
public void AutoMapperTypeAdapterAdaptEntityEnumerable() { //Arrange Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile())); var typeAdapter = new AutomapperTypeAdapter(); var customer = new Customer() { Id = 1, FirstName = "Jhon", LastName = "Bep" }; //act var dto = typeAdapter.Adapt <IEnumerable <Customer>, List <CustomerDto> >( new Customer[] { customer }); //Assert Assert.IsNotNull(dto); Assert.IsTrue(dto.Count == 1); Assert.AreEqual(dto[0].CustomerId, customer.Id); Assert.AreEqual(dto[0].FullName, string.Format("{0},{1}", customer.LastName, customer.FirstName)); }
public void AutoMapperTypeAdapterAdaptEntity() { var typeAdapter = new AutomapperTypeAdapter(fixture._mapper); var blog = new Blog() { BlogId = 1, Name = "Name", Rating = 0, Url = "Url" }; //act var dto = typeAdapter.Adapt <Blog, BlogDTO>(blog); //Assert Assert.NotNull(dto); Assert.Equal(dto.BlogId, blog.BlogId); Assert.Equal(dto.Name, blog.Name); Assert.Equal(dto.Rating, blog.Rating); Assert.Equal(dto.Url, blog.Url); }
public void AutoMapperTypeAdapterAdaptEntity() { //Arrange Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile())); var typeAdapter = new AutomapperTypeAdapter(); var customer = new Customer() { Id = 1, FirstName = "Jhon", LastName = "Bep" }; //act var dto = typeAdapter.Adapt<Customer, CustomerDto>(customer); //Assert Assert.IsNotNull(dto); Assert.AreEqual(dto.CustomerId, customer.Id); Assert.AreEqual(dto.FullName, string.Format("{0},{1}", customer.LastName, customer.FirstName)); }
public void AutoMapperTypeAdapterAdaptEntity() { //Arrange Mapper.Initialize(cfg => cfg.AddProfile(new TypeAdapterProfile())); var typeAdapter = new AutomapperTypeAdapter(); var customer = new Customer() { Id = 1, FirstName = "Jhon", LastName = "Bep" }; //act var dto = typeAdapter.Adapt <Customer, CustomerDTO>(customer); //Assert Assert.IsNotNull(dto); Assert.AreEqual(dto.CustomerId, customer.Id); Assert.AreEqual(dto.FullName, string.Format("{0},{1}", customer.LastName, customer.FirstName)); }