コード例 #1
0
        public void FromEmployeeEntityToDTO()
        {
            //Given a Full EmployeeEntity
            EmployeeEntity employeeEntity = new EmployeeEntity
            {
                Sn         = 2,
                IsActive   = true,
                FirstName  = "TestNameF",
                MiddleName = "TestNameM",
                LastName   = "TestNameL",
                ID         = "ID200533",
                Gender     = EmployeeEntity.GenderTypes.Female,
                Birthday   = new DateTime(1992, 6, 16),
                JobTitle   = "Job Title",
                Department = new Department
                {
                    Code        = 0,
                    Name        = "DeptName",
                    Description = "Dept description"
                },
                Position = new JobPosition
                {
                    Code        = 0,
                    Name        = "PosName",
                    Description = "Position description"
                },
                ManagerSN   = 54,
                SalesmanSN  = -1,
                HomeAddress = new Address
                {
                    ID          = "Addr H",
                    Country     = "IL",
                    City        = " H city",
                    Block       = " H block",
                    Street      = " H street",
                    NumAtStreet = " H numAtSteet",
                    Apartment   = " H Apartment",
                    ZipCode     = " H ZipCode"
                },
                WorkAddress = new Address
                {
                    ID          = "Addr W",
                    Country     = "IL",
                    City        = " W city",
                    Block       = " W block",
                    Street      = " W street",
                    NumAtStreet = " W numAtSteet",
                    Apartment   = " W Apartment",
                    ZipCode     = " W ZipCode"
                },
                HomePhone    = "054-8998989",
                OfficePhone  = "09-89895142",
                WorkCellular = "058-74454151",
                Fax          = "8-45642120",
                Email        = "*****@*****.**",
                PicPath      = "picture URL here",
            };

            //When converting the entity to DTO and than back to an entity
            EmployeeEntity employeeEntityAfterConvert = _mapper.Map <EmployeeEntity>(_mapper.Map <EmployeeDto>(employeeEntity));

            //Than the entity after the convert should match the entity before
            employeeEntityAfterConvert.Should().BeEquivalentTo(employeeEntity, options => options.IncludingNestedObjects());
            //and the entity after the convert should not be the  entity before
            employeeEntityAfterConvert.Should().NotBeSameAs(employeeEntity);
        }