public void Register(TypeAdapterConfig config)
            {
                config.NewConfig<Customer, CustomerDTO>();
                config.NewConfig<Product, ProductDTO>();

                config.ForType<Product, ProductDTO>()
                    .Map(dest => dest.Title, src => src.Title + "_AppendSomething!");
            }
示例#2
0
        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);
        }
示例#3
0
        public void should_mapping_home_dto_correctly_when_using_config()
        {
            TypeAdapterConfig <Address, AddressDto> .NewConfig()
            .MapWith(src => new AddressDto(src.Name));

            TypeAdapterConfig <Home, HomeDto> .ForType()
            .Map(desc => desc.AddressName, source => source.Address.Name)
            .Map(desc => desc.OwnerName, source => $"{source.Owner.FirstName}{source.Owner.LastName}");

            var homeDto = _home.Adapt <HomeDto>();

            homeDto.ShouldNotBeNull();
            homeDto.Id.ShouldBe(2);
            homeDto.Name.ShouldBe("zhangsan's home");
            homeDto.Address.Name.ShouldBe("Beijing");
            homeDto.AddressName.ShouldBe("Beijing");
            homeDto.OwnerName.ShouldBe("zhangsan");
        }
示例#4
0
        public void Alter_Config_After_Map_Should_Error()
        {
            TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig()
            .Map(dest => dest.Name, src => "a");

            var poco = new SimplePoco
            {
                Id   = Guid.NewGuid(),
                Name = "test",
            };
            var result = TypeAdapter.Adapt <SimpleDto>(poco);

            result.Name.ShouldBe("a");

            var ex = Should.Throw <InvalidOperationException>(() =>
                                                              TypeAdapterConfig <SimplePoco, SimpleDto> .ForType()
                                                              .Map(dest => dest.Name, src => "b"));

            ex.Message.ShouldContain("TypeAdapter.Adapt was already called");
        }
示例#5
0
        // We user Mapster to convert Database objects to API objects automatically using the .Adapt<T>() operator
        // This file is the sole location where we set up Mapster configurations for types.

        public static void UseMapster(this IApplicationBuilder app)
        {
            TypeAdapterConfig <RaidParticipation, McRaidDescription>
            .ForType()
            .Map(dest => dest.Raid, src => src.Raid.Raid)
            .Map(dest => dest.Gym, src => src.Raid.Gym)
            .Map(dest => dest.Location, src => src.Raid.Location.Adapt <McLocation>())
            .Map(dest => dest.RaidUnlockTime, src => src.Raid.RaidUnlockTime)
            .Map(dest => dest.RaidEndTime, src => src.Raid.RaidEndTime)
            .Map(dest => dest.Address, src => src.Raid.Address)
            .Map(dest => dest.Alignment, src => src.Raid.Alignment)
            .Map(dest => dest.Remarks, src => src.Raid.Remarks)
            .Map(dest => dest.UniqueID, src => src.UniqueID)
            .Map(dest => dest.PublicID, src => src.PublicID)
            .Map(dest => dest.UpdateCount, src => src.Raid.UpdateCount)
            .Map(dest => dest.User, src => src.Raid.User.Adapt <McTelegramUser>())
            .Map(dest => dest.Valor, src => src.Participants.Get(Team.Valor).Select(x => 1 + x.Extra).Sum())
            .Map(dest => dest.Mystic, src => src.Participants.Get(Team.Mystic).Select(x => 1 + x.Extra).Sum())
            .Map(dest => dest.Instinct, src => src.Participants.Get(Team.Instinct).Select(x => 1 + x.Extra).Sum())
            .Map(dest => dest.Unknown, src => src.Participants.Get(Team.Unknown).Select(x => 1 + x.Extra).Sum())
            .Map(dest => dest.Maybe, src => src.Maybe != null ? src.Maybe.Count : 0);
        }
        public void ForType_Enhances_Config()
        {
            var config = new TypeAdapterConfig();
            config.NewConfig<Customer, CustomerDTO>()
                .Map(dest => dest.Address_Country, src => "TestAddressCountry");

            config.ForType<Customer, CustomerDTO>()
                .Map(dest => dest.Name, src => src.Name + "_Enhanced");

            var customer = new Customer
            {
                Id = 12345,
                Name = "TestName",
                Surname = "TestSurname"
            };

            var customerDto = customer.Adapt<CustomerDTO>(config);

            customerDto.Id.ShouldEqual(12345);
            customerDto.Name.ShouldEqual("TestName_Enhanced");
            customerDto.Address_Country.ShouldEqual("TestAddressCountry");
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddDbContext <BugsterDbContext>(options =>
                                                     options.UseSqlServer(_configuration.GetConnectionString("DefaultConnection")));

            services.AddScoped <IProjectRepository, ProjectRepository>();
            services.AddScoped <IProjectApplicationService, ProjectApplicationService>();
            services.AddScoped <ITaskAssigner, BugAutoAssigner>();

            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserApplicationService, UserApplicationService>();

            services.AddScoped <ITagRepository, TagRepository>();
            services.AddScoped <ITagApplicationService, TagApplicationService>();

            TypeAdapterConfig <UserResponse, UpdateUserViewModel>
            .ForType()
            .Map(destination => destination.FirstName, source => source.FullName.Split(' ', System.StringSplitOptions.RemoveEmptyEntries)[0])
            .Map(destination => destination.LastName, source => source.FullName.Split(' ', System.StringSplitOptions.RemoveEmptyEntries)[1]);
        }
        public void ForType_Enhances_Config()
        {
            var config = new TypeAdapterConfig();

            config.NewConfig <Customer, CustomerDTO>()
            .Map(dest => dest.Address_Country, src => "TestAddressCountry");

            config.ForType <Customer, CustomerDTO>()
            .Map(dest => dest.Name, src => src.Name + "_Enhanced");

            var customer = new Customer
            {
                Id      = 12345,
                Name    = "TestName",
                Surname = "TestSurname"
            };

            var customerDto = customer.Adapt <CustomerDTO>(config);

            customerDto.Id.ShouldEqual(12345);
            customerDto.Name.ShouldEqual("TestName_Enhanced");
            customerDto.Address_Country.ShouldEqual("TestAddressCountry");
        }
示例#9
0
 public void Register(TypeAdapterConfig config)
 {
     config.ForType <IEnumerable <PieChartItem>, PieChartDto>()
     .Map(dst => dst.Name, src => src.Select(i => i.ChunkName))
     .Map(dst => dst.Quantity, src => src.Select(i => i.Quantity));
 }
 public void ToEntities(TypeAdapterConfig config)
 {
     config.ForType <AuthorDto, Author>();
     config.ForType <BookDto, Book>();
     config.ForType <SerieDto, Serie>();
 }
 public void FromEntities(TypeAdapterConfig config)
 {
     config.ForType <Author, AuthorDto>();
     config.ForType <Book, BookDto>();
     config.ForType <Serie, SerieDto>();
 }
示例#12
0
 public void Register(TypeAdapterConfig config)
 {
     config.ForType <Person, Person>()
     .GenerateMapper(MapType.Map | MapType.MapToTarget);
 }
示例#13
0
 public void Register(TypeAdapterConfig config)
 {
     config.ForType<Person, PersonDTO>();
 }
 public void Register(TypeAdapterConfig config)
 {
     config.ForType <Person, PersonDTO>();
 }
        public static void Mapping()
        {
            var config = new TypeAdapterConfig();

            config.ForType <BillInput, Bill>();
            config.ForType <CustomerInput, Customer>();
            config.ForType <VendorInput, Vendor>();
            config.ForType <VendorQuotationInput, VendorQuotation>();
            config.ForType <VendorQuotationPriceInput, VendorQuotationPrice>();
            config.ForType <ZoneInput, Zone>();
            config.ForType <ParamsInput, Params>();
            config.ForType <ParcelServiceInput, ParcelService>();
            config.ForType <ParcelServiceZoneInput, ParcelServiceZone>();

            config.ForType <BillInput, LicenseBillInput>().TwoWays();
            config.ForType <LicenseBillInput, Bill>();
            config.ForType <BillQuotationInput, BillQuotation>();

            config.ForType <ParcelServiceVendorInput, ParcelServiceVendor>();
        }
示例#16
0
 public void Register(TypeAdapterConfig config)
 {
     config.ForType <IEnumerable <ColumnChartItem>, ColumnChartDto>()
     .Map(dst => dst.Label, src => src.Select(i => i.Label))
     .Map(dst => dst.Value, src => src.Select(i => i.Value));
 }
        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.ShouldBe(product.Id);
        }