public async Task <ValidationResult> ValidateUpdateAsync(short id, ApiDepartmentRequestModel model)
 {
     this.GroupNameRules();
     this.ModifiedDateRules();
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiDepartmentResponseModel> CreateRecord()
        {
            var model = new ApiDepartmentRequestModel();

            model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B");
            CreateResponse <ApiDepartmentResponseModel> result = await this.Client.DepartmentCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiDepartmentModelMapper();
            var model  = new ApiDepartmentResponseModel();

            model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            ApiDepartmentRequestModel response = mapper.MapResponseToRequest(model);

            response.GroupName.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
        }
Example #4
0
        public void MapModelToBO()
        {
            var mapper = new BOLDepartmentMapper();
            ApiDepartmentRequestModel model = new ApiDepartmentRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            BODepartment response = mapper.MapModelToBO(1, model);

            response.GroupName.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiDepartmentRequestModel model)
        {
            CreateResponse <ApiDepartmentResponseModel> result = await this.DepartmentService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Departments/{result.Record.DepartmentID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Example #6
0
        public virtual BODepartment MapModelToBO(
            short departmentID,
            ApiDepartmentRequestModel model
            )
        {
            BODepartment boDepartment = new BODepartment();

            boDepartment.SetProperties(
                departmentID,
                model.GroupName,
                model.ModifiedDate,
                model.Name);
            return(boDepartment);
        }
        private async Task <ApiDepartmentRequestModel> PatchModel(short id, JsonPatchDocument <ApiDepartmentRequestModel> patch)
        {
            var record = await this.DepartmentService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiDepartmentRequestModel request = this.DepartmentModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiDepartmentResponseModel> > Create(
            ApiDepartmentRequestModel model)
        {
            CreateResponse <ApiDepartmentResponseModel> response = new CreateResponse <ApiDepartmentResponseModel>(await this.DepartmentModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolDepartmentMapper.MapModelToBO(default(short), model);
                var record = await this.DepartmentRepository.Create(this.DalDepartmentMapper.MapBOToEF(bo));

                response.SetRecord(this.BolDepartmentMapper.MapBOToModel(this.DalDepartmentMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public void CreatePatch()
        {
            var mapper = new ApiDepartmentModelMapper();
            var model  = new ApiDepartmentRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

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

            patch.ApplyTo(response);
            response.GroupName.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
        }
        public virtual async Task <UpdateResponse <ApiDepartmentResponseModel> > Update(
            short departmentID,
            ApiDepartmentRequestModel model)
        {
            var validationResult = await this.DepartmentModelValidator.ValidateUpdateAsync(departmentID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolDepartmentMapper.MapModelToBO(departmentID, model);
                await this.DepartmentRepository.Update(this.DalDepartmentMapper.MapBOToEF(bo));

                var record = await this.DepartmentRepository.Get(departmentID);

                return(new UpdateResponse <ApiDepartmentResponseModel>(this.BolDepartmentMapper.MapBOToModel(this.DalDepartmentMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiDepartmentResponseModel>(validationResult));
            }
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IDepartmentRepository>();
            var model = new ApiDepartmentRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Department>())).Returns(Task.FromResult(new Department()));
            var service = new DepartmentService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.DepartmentModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLDepartmentMapperMock,
                                                mock.DALMapperMockFactory.DALDepartmentMapperMock,
                                                mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                                mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.DepartmentModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDepartmentRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Department>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IDepartmentRepository>();
            var model = new ApiDepartmentRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <short>())).Returns(Task.CompletedTask);
            var service = new DepartmentService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.DepartmentModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLDepartmentMapperMock,
                                                mock.DALMapperMockFactory.DALDepartmentMapperMock,
                                                mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                                mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <short>()));
            mock.ModelValidatorMockFactory.DepartmentModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <short>()));
        }
        public virtual async Task <IActionResult> Update(short id, [FromBody] ApiDepartmentRequestModel model)
        {
            ApiDepartmentRequestModel request = await this.PatchModel(id, this.DepartmentModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(short id, [FromBody] JsonPatchDocument <ApiDepartmentRequestModel> patch)
        {
            ApiDepartmentResponseModel record = await this.DepartmentService.Get(id);

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

                UpdateResponse <ApiDepartmentResponseModel> result = await this.DepartmentService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }