Beispiel #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 ApiLinkStatusRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiLinkStatusResponseModel> createResult = await client.LinkStatusCreateAsync(createModel);

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

            ApiLinkStatusResponseModel getResponse = await client.LinkStatusGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.LinkStatusDeleteAsync(2);

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

            ApiLinkStatusResponseModel verifyResponse = await client.LinkStatusGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Beispiel #2
0
        private async Task <ApiLinkStatusResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiLinkStatusRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiLinkStatusResponseModel> result = await client.LinkStatusCreateAsync(model);

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

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

            response.Name.Should().Be("A");
        }
        public void MapModelToBO()
        {
            var mapper = new BOLLinkStatusMapper();
            ApiLinkStatusRequestModel model = new ApiLinkStatusRequestModel();

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

            response.Name.Should().Be("A");
        }
Beispiel #5
0
        public virtual BOLinkStatus MapModelToBO(
            int id,
            ApiLinkStatusRequestModel model
            )
        {
            BOLinkStatus boLinkStatus = new BOLinkStatus();

            boLinkStatus.SetProperties(
                id,
                model.Name);
            return(boLinkStatus);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiLinkStatusRequestModel model)
        {
            CreateResponse <ApiLinkStatusResponseModel> result = await this.LinkStatusService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/LinkStatuses/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiLinkStatusModelMapper();
            var model  = new ApiLinkStatusRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
        public virtual async Task <CreateResponse <ApiLinkStatusResponseModel> > Create(
            ApiLinkStatusRequestModel model)
        {
            CreateResponse <ApiLinkStatusResponseModel> response = new CreateResponse <ApiLinkStatusResponseModel>(await this.linkStatusModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolLinkStatusMapper.MapModelToBO(default(int), model);
                var record = await this.linkStatusRepository.Create(this.dalLinkStatusMapper.MapBOToEF(bo));

                response.SetRecord(this.bolLinkStatusMapper.MapBOToModel(this.dalLinkStatusMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiLinkStatusRequestModel request = this.LinkStatusModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <UpdateResponse <ApiLinkStatusResponseModel> > Update(
            int id,
            ApiLinkStatusRequestModel model)
        {
            var validationResult = await this.linkStatusModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolLinkStatusMapper.MapModelToBO(id, model);
                await this.linkStatusRepository.Update(this.dalLinkStatusMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiLinkStatusResponseModel>(this.bolLinkStatusMapper.MapBOToModel(this.dalLinkStatusMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiLinkStatusResponseModel>(validationResult));
            }
        }
Beispiel #11
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ILinkStatusRepository>();
            var model = new ApiLinkStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <LinkStatus>())).Returns(Task.FromResult(new LinkStatus()));
            var service = new LinkStatusService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.LinkStatusModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLLinkStatusMapperMock,
                                                mock.DALMapperMockFactory.DALLinkStatusMapperMock,
                                                mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                                mock.DALMapperMockFactory.DALLinkMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LinkStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLinkStatusRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <LinkStatus>()));
        }
Beispiel #12
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ILinkStatusRepository>();
            var model = new ApiLinkStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new LinkStatusService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.LinkStatusModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLLinkStatusMapperMock,
                                                mock.DALMapperMockFactory.DALLinkStatusMapperMock,
                                                mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                                mock.DALMapperMockFactory.DALLinkMapperMock);

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

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

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

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

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

                UpdateResponse <ApiLinkStatusResponseModel> result = await this.LinkStatusService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #15
0
		public async Task<ValidationResult> ValidateCreateAsync(ApiLinkStatusRequestModel model)
		{
			this.NameRules();
			return await this.ValidateAsync(model);
		}
Beispiel #16
0
        public virtual async Task <UpdateResponse <ApiLinkStatusResponseModel> > LinkStatusUpdateAsync(int id, ApiLinkStatusRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/LinkStatuses/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiLinkStatusResponseModel> >(httpResponse.Content.ContentToString()));
        }
Beispiel #17
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiLinkStatusRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }