コード例 #1
0
        public async Task <IHttpActionResult> AddAsync(AddEmployeeRequest request)
        {
            var employee = new Employee
            {
                Name       = request.Name,
                Department = request.Department
            };

            if (await _employeeService.AnyAsync(a => a.Name == request.Name && a.Department == request.Department))
            {
                return(Fail("存在重名"));
            }
            var result = await _employeeService.AddAsync(employee);

            if (result > 0)
            {
                return(Succeed(new AddEmployeeResponse
                {
                    Id = employee.Id
                }, "添加成功"));
            }
            else
            {
                return(Fail("修改失败"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create(Employee emp)
        {
            try
            {
                if (emp != null)
                {
                    emp.Adresse = new Address()
                    {
                        CodePostale = 2046
                    };

                    await _empservice.AddAsync(emp);
                }
                else
                {
                    return(View());
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public async Task ShouldAddEmployee()
        {
            // Arrage
            var service = new EmployeeService(_mockUow.Object, _mapper, _mockRepo.Object);

            // Act
            var b = new Employee
            {
                Name = "Petr",
            };
            await service.AddAsync(b);

            // Assert
            _mockUow.Verify(m => m.SaveAsync(), Times.Once());
        }
コード例 #4
0
        public void Add_NewEmployeeContract_inDB()
        {
            //Arrange
            EmployeeContract employeeContract = new EmployeeContract
            {
                FName   = "Test1",
                LName   = "User1",
                Gender  = "M",
                Address = new AddressContract {
                    Line1   = "Address11",
                    Line2   = "Address12",
                    POBox   = "POBox",
                    City    = "City",
                    Country = "Country",
                    Email   = "*****@*****.**",
                    Phone   = "+11-1111-111-111"
                }
            };
            Employee emp = new Employee
            {
                Id        = 1,
                FName     = "Test1",
                LName     = "User1",
                Gender    = "M",
                Addresses = new List <Address> {
                    new Address {
                        Id = 1, EmployeeId = 1, Line1 = "Address11", Line2 = "Address12", POBox = "POBox", City = "City", Country = "Country", Email = "*****@*****.**", Phone = "+11-1111-111-111"
                    }
                }
            };
            Mock <IEmployeeRepository> employeeRepository = new Mock <IEmployeeRepository>();

            employeeRepository.Setup(x => x.Add(It.IsAny <Employee>())).Returns(emp);
            EmployeeService service = new EmployeeService(employeeRepository.Object);
            ////ACT
            Task <EmployeeContract> result = service.AddAsync(employeeContract);

            result.Wait();
            //Assert
            Assert.NotNull(result.Result);
        }
コード例 #5
0
        public async Task ThrowException_IfLastNameLengthIsShort()
        {
            var employee = EmployeeGeneratorUtil.GenerateEmployee();

            var dto = new EmployeeDto
            {
                FirstName            = employee.FirstName,
                LastName             = "Ts",
                CompanyId            = employee.CompanyId,
                OfficeId             = employee.OfficeId,
                ExperienceEmployeeId = employee.ExperienceEmployeeId
            };

            var options = TestUtilities.GetOptions(nameof(ThrowException_IfLastNameLengthIsShort));

            using (var actContext = new EmployeeManagementSystemContext(options))
            {
                var sut = new EmployeeService(actContext);
                await sut.AddAsync(dto);
            }
        }
コード例 #6
0
        public async Task ThrowException_IfOfficeIsDeleted()
        {
            var employee = EmployeeGeneratorUtil.GenerateEmployee();
            var office   = OfficeGeneratorUtil.GenerateOffice();

            office.IsDeleted = true;
            var dto = new EmployeeDto
            {
                FirstName            = employee.FirstName,
                LastName             = employee.LastName,
                CompanyId            = 0,
                OfficeId             = office.Id,
                ExperienceEmployeeId = employee.ExperienceEmployeeId,
            };

            var options = TestUtilities.GetOptions(nameof(ThrowException_IfOfficeIsDeleted));

            using (var actContext = new EmployeeManagementSystemContext(options))
            {
                var sut = new EmployeeService(actContext);
                await sut.AddAsync(dto);
            }
        }