Пример #1
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IEmployeeRepository>();
            var model = new ApiEmployeeRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Employee>())).Returns(Task.FromResult(new Employee()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Employee()));
            var service = new EmployeeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.EmployeeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLEmployeeMapperMock,
                                              mock.DALMapperMockFactory.DALEmployeeMapperMock,
                                              mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock,
                                              mock.DALMapperMockFactory.DALClientCommunicationMapperMock,
                                              mock.BOLMapperMockFactory.BOLPipelineStepMapperMock,
                                              mock.DALMapperMockFactory.DALPipelineStepMapperMock,
                                              mock.BOLMapperMockFactory.BOLPipelineStepNoteMapperMock,
                                              mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock);

            UpdateResponse <ApiEmployeeResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.EmployeeModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiEmployeeRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Employee>()));
        }
Пример #2
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiEmployeeRequestModel();

            createModel.SetProperties("B", true, true, "B");
            CreateResponse <ApiEmployeeResponseModel> createResult = await client.EmployeeCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiEmployeeResponseModel getResponse = await client.EmployeeGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.EmployeeDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiEmployeeResponseModel verifyResponse = await client.EmployeeGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Пример #3
0
        public virtual BOEmployee MapModelToBO(
            int businessEntityID,
            ApiEmployeeRequestModel model
            )
        {
            BOEmployee boEmployee = new BOEmployee();

            boEmployee.SetProperties(
                businessEntityID,
                model.BirthDate,
                model.CurrentFlag,
                model.Gender,
                model.HireDate,
                model.JobTitle,
                model.LoginID,
                model.MaritalStatu,
                model.ModifiedDate,
                model.NationalIDNumber,
                model.OrganizationLevel,
                model.Rowguid,
                model.SalariedFlag,
                model.SickLeaveHour,
                model.VacationHour);
            return(boEmployee);
        }
        public void CreatePatch()
        {
            var mapper = new ApiEmployeeModelMapper();
            var model  = new ApiEmployeeRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), true, 1, 1);

            JsonPatchDocument <ApiEmployeeRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiEmployeeRequestModel();

            patch.ApplyTo(response);
            response.BirthDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.CurrentFlag.Should().Be(true);
            response.Gender.Should().Be("A");
            response.HireDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.JobTitle.Should().Be("A");
            response.LoginID.Should().Be("A");
            response.MaritalStatu.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NationalIDNumber.Should().Be("A");
            response.OrganizationLevel.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.SalariedFlag.Should().Be(true);
            response.SickLeaveHour.Should().Be(1);
            response.VacationHour.Should().Be(1);
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiEmployeeRequestModel model)
 {
     this.FirstNameRules();
     this.IsSalesPersonRules();
     this.IsShipperRules();
     this.LastNameRules();
     return(await this.ValidateAsync(model, id));
 }
Пример #6
0
        private async Task <ApiEmployeeResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiEmployeeRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), true, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), true, 2, 2);
            CreateResponse <ApiEmployeeResponseModel> result = await client.EmployeeCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        private async Task <ApiEmployeeResponseModel> CreateRecord()
        {
            var model = new ApiEmployeeRequestModel();

            model.SetProperties("B", true, true, "B");
            CreateResponse <ApiEmployeeResponseModel> result = await this.Client.EmployeeCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiEmployeeRequestModel model)
        {
            CreateResponse <ApiEmployeeResponseModel> result = await this.EmployeeService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Employees/{result.Record.BusinessEntityID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiEmployeeModelMapper();
            var model  = new ApiEmployeeResponseModel();

            model.SetProperties(1, "A", true, true, "A");
            ApiEmployeeRequestModel response = mapper.MapResponseToRequest(model);

            response.FirstName.Should().Be("A");
            response.IsSalesPerson.Should().Be(true);
            response.IsShipper.Should().Be(true);
            response.LastName.Should().Be("A");
        }
Пример #10
0
        public void MapModelToBO()
        {
            var mapper = new BOLEmployeeMapper();
            ApiEmployeeRequestModel model = new ApiEmployeeRequestModel();

            model.SetProperties("A", true, true, "A");
            BOEmployee response = mapper.MapModelToBO(1, model);

            response.FirstName.Should().Be("A");
            response.IsSalesPerson.Should().Be(true);
            response.IsShipper.Should().Be(true);
            response.LastName.Should().Be("A");
        }
Пример #11
0
        public virtual BOEmployee MapModelToBO(
            int id,
            ApiEmployeeRequestModel model
            )
        {
            BOEmployee boEmployee = new BOEmployee();

            boEmployee.SetProperties(
                id,
                model.FirstName,
                model.IsSalesPerson,
                model.IsShipper,
                model.LastName);
            return(boEmployee);
        }
Пример #12
0
        public virtual async Task <CreateResponse <ApiEmployeeResponseModel> > Create(
            ApiEmployeeRequestModel model)
        {
            CreateResponse <ApiEmployeeResponseModel> response = new CreateResponse <ApiEmployeeResponseModel>(await this.employeeModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolEmployeeMapper.MapModelToBO(default(int), model);
                var record = await this.employeeRepository.Create(this.dalEmployeeMapper.MapBOToEF(bo));

                response.SetRecord(this.bolEmployeeMapper.MapBOToModel(this.dalEmployeeMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiEmployeeRequestModel> PatchModel(int id, JsonPatchDocument <ApiEmployeeRequestModel> patch)
        {
            var record = await this.EmployeeService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiEmployeeRequestModel request = this.EmployeeModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Пример #14
0
        public void CreatePatch()
        {
            var mapper = new ApiEmployeeModelMapper();
            var model  = new ApiEmployeeRequestModel();

            model.SetProperties("A", true, true, "A");

            JsonPatchDocument <ApiEmployeeRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiEmployeeRequestModel();

            patch.ApplyTo(response);
            response.FirstName.Should().Be("A");
            response.IsSalesPerson.Should().Be(true);
            response.IsShipper.Should().Be(true);
            response.LastName.Should().Be("A");
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiEmployeeRequestModel model)
 {
     this.BirthDateRules();
     this.CurrentFlagRules();
     this.GenderRules();
     this.HireDateRules();
     this.JobTitleRules();
     this.LoginIDRules();
     this.MaritalStatuRules();
     this.ModifiedDateRules();
     this.NationalIDNumberRules();
     this.OrganizationLevelRules();
     this.RowguidRules();
     this.SalariedFlagRules();
     this.SickLeaveHourRules();
     this.VacationHourRules();
     return(await this.ValidateAsync(model, id));
 }
Пример #16
0
        public virtual async Task <UpdateResponse <ApiEmployeeResponseModel> > Update(
            int id,
            ApiEmployeeRequestModel model)
        {
            var validationResult = await this.employeeModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolEmployeeMapper.MapModelToBO(id, model);
                await this.employeeRepository.Update(this.dalEmployeeMapper.MapBOToEF(bo));

                var record = await this.employeeRepository.Get(id);

                return(new UpdateResponse <ApiEmployeeResponseModel>(this.bolEmployeeMapper.MapBOToModel(this.dalEmployeeMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiEmployeeResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiEmployeeRequestModel model)
        {
            ApiEmployeeRequestModel request = await this.PatchModel(id, this.EmployeeModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiEmployeeResponseModel> result = await this.EmployeeService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #18
0
        public void MapModelToBO()
        {
            var mapper = new BOLEmployeeMapper();
            ApiEmployeeRequestModel model = new ApiEmployeeRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), true, 1, 1);
            BOEmployee response = mapper.MapModelToBO(1, model);

            response.BirthDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.CurrentFlag.Should().Be(true);
            response.Gender.Should().Be("A");
            response.HireDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.JobTitle.Should().Be("A");
            response.LoginID.Should().Be("A");
            response.MaritalStatu.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NationalIDNumber.Should().Be("A");
            response.OrganizationLevel.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.SalariedFlag.Should().Be(true);
            response.SickLeaveHour.Should().Be(1);
            response.VacationHour.Should().Be(1);
        }
Пример #19
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IEmployeeRepository>();
            var model = new ApiEmployeeRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new EmployeeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.EmployeeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLEmployeeMapperMock,
                                              mock.DALMapperMockFactory.DALEmployeeMapperMock,
                                              mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock,
                                              mock.DALMapperMockFactory.DALClientCommunicationMapperMock,
                                              mock.BOLMapperMockFactory.BOLPipelineStepMapperMock,
                                              mock.DALMapperMockFactory.DALPipelineStepMapperMock,
                                              mock.BOLMapperMockFactory.BOLPipelineStepNoteMapperMock,
                                              mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.EmployeeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiEmployeeRequestModel> patch)
        {
            ApiEmployeeResponseModel record = await this.EmployeeService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiEmployeeRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiEmployeeResponseModel> result = await this.EmployeeService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #21
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IEmployeeRepository>();
            var model = new ApiEmployeeRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Employee>())).Returns(Task.FromResult(new Employee()));
            var service = new EmployeeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.EmployeeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLEmployeeMapperMock,
                                              mock.DALMapperMockFactory.DALEmployeeMapperMock,
                                              mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                              mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock,
                                              mock.BOLMapperMockFactory.BOLEmployeePayHistoryMapperMock,
                                              mock.DALMapperMockFactory.DALEmployeePayHistoryMapperMock,
                                              mock.BOLMapperMockFactory.BOLJobCandidateMapperMock,
                                              mock.DALMapperMockFactory.DALJobCandidateMapperMock);

            CreateResponse <ApiEmployeeResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.EmployeeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiEmployeeRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Employee>()));
        }