コード例 #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPipelineStepNoteRequestModel model)
 {
     this.EmployeeIdRules();
     this.NoteRules();
     this.PipelineStepIdRules();
     return(await this.ValidateAsync(model, id));
 }
コード例 #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 ApiPipelineStepNoteRequestModel();

            createModel.SetProperties(1, "B", 1);
            CreateResponse <ApiPipelineStepNoteResponseModel> createResult = await client.PipelineStepNoteCreateAsync(createModel);

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

            ApiPipelineStepNoteResponseModel getResponse = await client.PipelineStepNoteGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.PipelineStepNoteDeleteAsync(2);

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

            ApiPipelineStepNoteResponseModel verifyResponse = await client.PipelineStepNoteGetAsync(2);

            verifyResponse.Should().BeNull();
        }
コード例 #3
0
        private async Task <ApiPipelineStepNoteResponseModel> CreateRecord()
        {
            var model = new ApiPipelineStepNoteRequestModel();

            model.SetProperties(1, "B", 1);
            CreateResponse <ApiPipelineStepNoteResponseModel> result = await this.Client.PipelineStepNoteCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
コード例 #4
0
        public void MapModelToBO()
        {
            var mapper = new BOLPipelineStepNoteMapper();
            ApiPipelineStepNoteRequestModel model = new ApiPipelineStepNoteRequestModel();

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

            response.EmployeeId.Should().Be(1);
            response.Note.Should().Be("A");
            response.PipelineStepId.Should().Be(1);
        }
コード例 #5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiPipelineStepNoteModelMapper();
            var model  = new ApiPipelineStepNoteResponseModel();

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

            response.EmployeeId.Should().Be(1);
            response.Note.Should().Be("A");
            response.PipelineStepId.Should().Be(1);
        }
コード例 #6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiPipelineStepNoteRequestModel model)
        {
            CreateResponse <ApiPipelineStepNoteResponseModel> result = await this.PipelineStepNoteService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PipelineStepNotes/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #7
0
        public virtual BOPipelineStepNote MapModelToBO(
            int id,
            ApiPipelineStepNoteRequestModel model
            )
        {
            BOPipelineStepNote boPipelineStepNote = new BOPipelineStepNote();

            boPipelineStepNote.SetProperties(
                id,
                model.EmployeeId,
                model.Note,
                model.PipelineStepId);
            return(boPipelineStepNote);
        }
コード例 #8
0
        public virtual async Task <CreateResponse <ApiPipelineStepNoteResponseModel> > Create(
            ApiPipelineStepNoteRequestModel model)
        {
            CreateResponse <ApiPipelineStepNoteResponseModel> response = new CreateResponse <ApiPipelineStepNoteResponseModel>(await this.PipelineStepNoteModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolPipelineStepNoteMapper.MapModelToBO(default(int), model);
                var record = await this.PipelineStepNoteRepository.Create(this.DalPipelineStepNoteMapper.MapBOToEF(bo));

                response.SetRecord(this.BolPipelineStepNoteMapper.MapBOToModel(this.DalPipelineStepNoteMapper.MapEFToBO(record)));
            }

            return(response);
        }
コード例 #9
0
        private async Task <ApiPipelineStepNoteRequestModel> PatchModel(int id, JsonPatchDocument <ApiPipelineStepNoteRequestModel> patch)
        {
            var record = await this.PipelineStepNoteService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiPipelineStepNoteRequestModel request = this.PipelineStepNoteModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #10
0
        public void CreatePatch()
        {
            var mapper = new ApiPipelineStepNoteModelMapper();
            var model  = new ApiPipelineStepNoteRequestModel();

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

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

            patch.ApplyTo(response);
            response.EmployeeId.Should().Be(1);
            response.Note.Should().Be("A");
            response.PipelineStepId.Should().Be(1);
        }
コード例 #11
0
		public async void Create()
		{
			var mock = new ServiceMockFacade<IPipelineStepNoteRepository>();
			var model = new ApiPipelineStepNoteRequestModel();
			mock.RepositoryMock.Setup(x => x.Create(It.IsAny<PipelineStepNote>())).Returns(Task.FromResult(new PipelineStepNote()));
			var service = new PipelineStepNoteService(mock.LoggerMock.Object,
			                                          mock.RepositoryMock.Object,
			                                          mock.ModelValidatorMockFactory.PipelineStepNoteModelValidatorMock.Object,
			                                          mock.BOLMapperMockFactory.BOLPipelineStepNoteMapperMock,
			                                          mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock);

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

			response.Should().NotBeNull();
			mock.ModelValidatorMockFactory.PipelineStepNoteModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny<ApiPipelineStepNoteRequestModel>()));
			mock.RepositoryMock.Verify(x => x.Create(It.IsAny<PipelineStepNote>()));
		}
コード例 #12
0
		public async void Delete()
		{
			var mock = new ServiceMockFacade<IPipelineStepNoteRepository>();
			var model = new ApiPipelineStepNoteRequestModel();
			mock.RepositoryMock.Setup(x => x.Delete(It.IsAny<int>())).Returns(Task.CompletedTask);
			var service = new PipelineStepNoteService(mock.LoggerMock.Object,
			                                          mock.RepositoryMock.Object,
			                                          mock.ModelValidatorMockFactory.PipelineStepNoteModelValidatorMock.Object,
			                                          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.PipelineStepNoteModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny<int>()));
		}
コード例 #13
0
        public virtual async Task <UpdateResponse <ApiPipelineStepNoteResponseModel> > Update(
            int id,
            ApiPipelineStepNoteRequestModel model)
        {
            var validationResult = await this.PipelineStepNoteModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolPipelineStepNoteMapper.MapModelToBO(id, model);
                await this.PipelineStepNoteRepository.Update(this.DalPipelineStepNoteMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiPipelineStepNoteResponseModel>(this.BolPipelineStepNoteMapper.MapBOToModel(this.DalPipelineStepNoteMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiPipelineStepNoteResponseModel>(validationResult));
            }
        }
コード例 #14
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPipelineStepNoteRequestModel model)
        {
            ApiPipelineStepNoteRequestModel request = await this.PatchModel(id, this.PipelineStepNoteModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #15
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPipelineStepNoteRequestModel> patch)
        {
            ApiPipelineStepNoteResponseModel record = await this.PipelineStepNoteService.Get(id);

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

                UpdateResponse <ApiPipelineStepNoteResponseModel> result = await this.PipelineStepNoteService.Update(id, model);

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