コード例 #1
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 ApiTimestampCheckRequestModel();

            createModel.SetProperties("B", BitConverter.GetBytes(2));
            CreateResponse <ApiTimestampCheckResponseModel> createResult = await client.TimestampCheckCreateAsync(createModel);

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

            ApiTimestampCheckResponseModel getResponse = await client.TimestampCheckGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TimestampCheckDeleteAsync(2);

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

            ApiTimestampCheckResponseModel verifyResponse = await client.TimestampCheckGetAsync(2);

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

            model.SetProperties("B", BitConverter.GetBytes(2));
            CreateResponse <ApiTimestampCheckResponseModel> result = await this.Client.TimestampCheckCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
コード例 #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTimestampCheckModelMapper();
            var model  = new ApiTimestampCheckResponseModel();

            model.SetProperties(1, "A", BitConverter.GetBytes(1));
            ApiTimestampCheckRequestModel response = mapper.MapResponseToRequest(model);

            response.Name.Should().Be("A");
            response.Timestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1));
        }
コード例 #4
0
        public void MapModelToBO()
        {
            var mapper = new BOLTimestampCheckMapper();
            ApiTimestampCheckRequestModel model = new ApiTimestampCheckRequestModel();

            model.SetProperties("A", BitConverter.GetBytes(1));
            BOTimestampCheck response = mapper.MapModelToBO(1, model);

            response.Name.Should().Be("A");
            response.Timestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1));
        }
コード例 #5
0
        public virtual BOTimestampCheck MapModelToBO(
            int id,
            ApiTimestampCheckRequestModel model
            )
        {
            BOTimestampCheck boTimestampCheck = new BOTimestampCheck();

            boTimestampCheck.SetProperties(
                id,
                model.Name,
                model.Timestamp);
            return(boTimestampCheck);
        }
コード例 #6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiTimestampCheckRequestModel model)
        {
            CreateResponse <ApiTimestampCheckResponseModel> result = await this.TimestampCheckService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TimestampChecks/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #7
0
        public void CreatePatch()
        {
            var mapper = new ApiTimestampCheckModelMapper();
            var model  = new ApiTimestampCheckRequestModel();

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

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
            response.Timestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1));
        }
コード例 #8
0
        public virtual async Task <CreateResponse <ApiTimestampCheckResponseModel> > Create(
            ApiTimestampCheckRequestModel model)
        {
            CreateResponse <ApiTimestampCheckResponseModel> response = new CreateResponse <ApiTimestampCheckResponseModel>(await this.timestampCheckModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolTimestampCheckMapper.MapModelToBO(default(int), model);
                var record = await this.timestampCheckRepository.Create(this.dalTimestampCheckMapper.MapBOToEF(bo));

                response.SetRecord(this.bolTimestampCheckMapper.MapBOToModel(this.dalTimestampCheckMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTimestampCheckRequestModel request = this.TimestampCheckModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITimestampCheckRepository>();
            var model = new ApiTimestampCheckRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TimestampCheck>())).Returns(Task.FromResult(new TimestampCheck()));
            var service = new TimestampCheckService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.TimestampCheckModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLTimestampCheckMapperMock,
                                                    mock.DALMapperMockFactory.DALTimestampCheckMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TimestampCheckModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTimestampCheckRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TimestampCheck>()));
        }
コード例 #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITimestampCheckRepository>();
            var model = new ApiTimestampCheckRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new TimestampCheckService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.TimestampCheckModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLTimestampCheckMapperMock,
                                                    mock.DALMapperMockFactory.DALTimestampCheckMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TimestampCheckModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
コード例 #12
0
        public virtual async Task <UpdateResponse <ApiTimestampCheckResponseModel> > Update(
            int id,
            ApiTimestampCheckRequestModel model)
        {
            var validationResult = await this.timestampCheckModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolTimestampCheckMapper.MapModelToBO(id, model);
                await this.timestampCheckRepository.Update(this.dalTimestampCheckMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiTimestampCheckResponseModel>(this.bolTimestampCheckMapper.MapBOToModel(this.dalTimestampCheckMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTimestampCheckResponseModel>(validationResult));
            }
        }
コード例 #13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTimestampCheckRequestModel model)
        {
            ApiTimestampCheckRequestModel request = await this.PatchModel(id, this.TimestampCheckModelMapper.CreatePatch(model));

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

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

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

                UpdateResponse <ApiTimestampCheckResponseModel> result = await this.TimestampCheckService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #15
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTimestampCheckRequestModel model)
 {
     this.NameRules();
     this.TimestampRules();
     return(await this.ValidateAsync(model, id));
 }
コード例 #16
0
        public virtual async Task <UpdateResponse <ApiTimestampCheckResponseModel> > TimestampCheckUpdateAsync(int id, ApiTimestampCheckRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/TimestampChecks/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiTimestampCheckResponseModel> >(httpResponse.Content.ContentToString()));
        }