Пример #1
0
        public void GetMethodTest()
        {
            var b = ClassAdapter <A, B> .Adapt(new A { X = 100, Y = 50 });

            Assert.IsNotNull(b);
            Assert.IsTrue(b.Total == 150);
        }
Пример #2
0
        public void PropertyTest()
        {
            var d = ClassAdapter <C, D> .Adapt(new C { BClass = new B {
                                                           Total = 250
                                                       } });

            Assert.IsNotNull(d);
            Assert.IsTrue(d.BClassTotal == 250);
        }
Пример #3
0
        public void PropertyTest_NameWithUnderscore()
        {
            var e = ClassAdapter <C, E> .Adapt(new C { BClass = new B {
                                                           Total = 250
                                                       } });

            Assert.IsNotNull(e);
            Assert.IsTrue(e.BClass_Total == 250);
        }
        public void ConvertPrimitiveEntityToDTO()
        {
            var dto = ClassAdapter <Customer, CustomerDTO> .Adapt(GetCustomer());

            Assert.IsNotNull(dto);
            Assert.IsTrue(dto.Id == 1 &&
                          dto.Name == "Timuçin" &&
                          dto.Credit == 1542 &&
                          dto.IsActive &&
                          dto.DriverLicenceType == 'B' &&
                          dto.Debit == 100
                          );
        }
Пример #5
0
        public void String_Is_Mapped_To_Enum()
        {
            var employee = new EmployeeWithStringEnum {
                Id = Guid.NewGuid(), Name = "Timuçin", Department = Departments.IT.ToString()
            };

            var dto = ClassAdapter <EmployeeWithStringEnum, EmployeeDTO> .Adapt(employee);

            dto.ShouldNotBeNull();

            dto.Id.ShouldEqual(employee.Id);
            dto.Name.ShouldEqual(employee.Name);
            dto.Department.ShouldEqual(Departments.IT);
        }
Пример #6
0
        public void Int_Is_Mapped_To_Enum()
        {
            TypeAdapterConfig <Employee, EmployeeDTO>
            .NewConfig();

            var employee = new Employee {
                Id = Guid.NewGuid(), Name = "Timuçin", Surname = "KIVANÇ", Department = (int)Departments.IT
            };

            var dto = ClassAdapter <Employee, EmployeeDTO> .Adapt(employee);

            Assert.IsNotNull(dto);

            Assert.IsTrue(dto.Id == employee.Id &&
                          dto.Name == employee.Name &&
                          dto.Department == Departments.IT);
        }
Пример #7
0
        public void MapEnum()
        {
            TypeAdapterConfig <Employee, EmployeeDTO>
            .NewConfig()
            .MapFrom(dest => dest.Department, src => (Departments)src.Department);

            var employee = new Employee()
            {
                Id = Guid.NewGuid(), Name = "Timuçin", Surname = "KIVANÇ", Department = (int)Departments.IT
            };

            var dto = ClassAdapter <Employee, EmployeeDTO> .Adapt(employee);

            Assert.IsNotNull(dto);

            Assert.IsTrue(dto.Id == employee.Id &&
                          dto.Name == employee.Name &&
                          dto.Department == Departments.IT);
        }
Пример #8
0
        public void IgnoreMemberTest()
        {
            var currentDate = DateTime.Now;

            var objA = new ConfigA()
            {
                BirthDate = currentDate,
                Id        = 1,
                Name      = "Timuçin",
                Surname   = "KIVANÇ"
            };

            TypeAdapterConfig <ConfigA, ConfigB> .NewConfig()
            .IgnoreMember(dest => dest.Id);

            var objB = ClassAdapter <ConfigA, ConfigB> .Adapt(objA);

            Assert.IsNotNull(objB);

            Assert.IsTrue(objB.Id == 0 && objB.FullName == null && objB.BirthDate == currentDate);
        }
Пример #9
0
        public void MapFromTest()
        {
            var currentDate = DateTime.Now;

            var objC = new ConfigC()
            {
                BirthDate = currentDate,
                Id        = 1,
                Name      = "Timuçin",
                Surname   = "KIVANÇ"
            };

            TypeAdapterConfig <ConfigC, ConfigD> .NewConfig()
            //.MapFrom(dest => dest.FullName, (src) => string.Concat(src.Name, " ", src.Surname));
            .MapFrom(dest => dest.FullName, src => string.Concat(src.Name, " ", src.Surname));

            var objD = ClassAdapter <ConfigC, ConfigD> .Adapt(objC);

            Assert.IsNotNull(objD);

            Assert.IsTrue(objD.Id == 1 && objD.FullName == "Timuçin KIVANÇ" && objD.BirthDate == currentDate);
        }
Пример #10
0
        public void MapCollectionProperty()
        {
            var person = new Person()
            {
                Id      = Guid.NewGuid(),
                Name    = "Timuçin",
                Surname = "KIVANÇ",
                Project = Projects.A,
                X       = new int[] { 1, 2, 3, 4 },
                Y       = new List <int>()
                {
                    5, 6, 7
                },
                Z   = new ArrayList((ICollection)(new List <Guid>()
                {
                    Guid.NewGuid(), Guid.NewGuid()
                })),
                Ids = new List <Guid>()
                {
                    Guid.Empty, Guid.NewGuid()
                },
                CityId    = Guid.NewGuid(),
                Picture   = new byte[] { 0, 1, 2 },
                Countries = new List <string> {
                    "Turkey", "Germany"
                },
                XX = new List <string> {
                    "Nederland", "USA"
                },
                YY = new List <int> {
                    22, 33
                },
                ZZ = new List <int> {
                    44, 55
                },
                RelatedDepartments = new Departments[] { Departments.IT, Departments.Finance }
            };

            var dto = ClassAdapter <Person, PersonDTO> .Adapt(person);

            Assert.IsNotNull(dto);
            Assert.IsTrue(dto.Id == person.Id &&
                          dto.Name == person.Name &&
                          dto.Project == person.Project);

            Assert.IsNotNull(dto.X);
            Assert.IsTrue(dto.X.Count == 4 && dto.X[0] == 1 && dto.X[1] == 2 && dto.X[2] == 3 && dto.X[3] == 4);

            Assert.IsNotNull(dto.Y);
            Assert.IsTrue(dto.Y.Length == 3 && dto.Y[0] == 5 && dto.Y[1] == 6 && dto.Y[2] == 7);

            Assert.IsNotNull(dto.Z);
            Assert.IsTrue(dto.Z.Count == 2 && dto.Z.Contains((Guid)person.Z[0]) && dto.Z.Contains((Guid)person.Z[1]));

            Assert.IsNotNull(dto.Ids);
            Assert.IsTrue(dto.Ids.Count == 2);

            Assert.IsTrue(dto.CityId == person.CityId);

            Assert.IsNotNull(dto.Picture);
            Assert.IsTrue(dto.Picture.Length == 3 && dto.Picture[0] == 0 && dto.Picture[1] == 1 && dto.Picture[2] == 2);

            Assert.IsNotNull(dto.Countries);
            Assert.IsTrue(dto.Countries.Count == 2 && dto.Countries.First() == "Turkey" && dto.Countries.Last() == "Germany");

            Assert.IsNotNull(dto.XX);
            Assert.IsTrue(dto.XX.Count() == 2 && dto.XX.First() == "Nederland" && dto.XX.Last() == "USA");

            Assert.IsNotNull(dto.YY);
            Assert.IsTrue(dto.YY.Count == 2 && dto.YY.First() == 22 && dto.YY.Last() == 33);

            Assert.IsNotNull(dto.ZZ);
            Assert.IsTrue(dto.ZZ.Count == 2 && dto.ZZ.First() == 44 && dto.ZZ.Last() == 55);

            Assert.IsNotNull(dto.RelatedDepartments);
            Assert.IsTrue(dto.RelatedDepartments.Length == 2 && dto.RelatedDepartments[0] == Departments.IT && dto.RelatedDepartments[1] == Departments.Finance);
        }