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 ApiOrganizationRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiOrganizationResponseModel> createResult = await client.OrganizationCreateAsync(createModel);

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

            ApiOrganizationResponseModel getResponse = await client.OrganizationGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.OrganizationDeleteAsync(2);

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

            ApiOrganizationResponseModel verifyResponse = await client.OrganizationGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Beispiel #2
0
        public void MapModelToBO()
        {
            var mapper = new BOLOrganizationMapper();
            ApiOrganizationRequestModel model = new ApiOrganizationRequestModel();

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

            response.Name.Should().Be("A");
        }
Beispiel #3
0
        private async Task <ApiOrganizationResponseModel> CreateRecord()
        {
            var model = new ApiOrganizationRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiOrganizationResponseModel> result = await this.Client.OrganizationCreateAsync(model);

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

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

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

            boOrganization.SetProperties(
                id,
                model.Name);
            return(boOrganization);
        }
Beispiel #6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiOrganizationRequestModel model)
        {
            CreateResponse <ApiOrganizationResponseModel> result = await this.OrganizationService.Create(model);

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

            model.SetProperties("A");

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

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

            if (response.Success)
            {
                var bo     = this.bolOrganizationMapper.MapModelToBO(default(int), model);
                var record = await this.organizationRepository.Create(this.dalOrganizationMapper.MapBOToEF(bo));

                response.SetRecord(this.bolOrganizationMapper.MapBOToModel(this.dalOrganizationMapper.MapEFToBO(record)));
            }

            return(response);
        }
Beispiel #9
0
        private async Task <ApiOrganizationRequestModel> PatchModel(int id, JsonPatchDocument <ApiOrganizationRequestModel> patch)
        {
            var record = await this.OrganizationService.Get(id);

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

            if (validationResult.IsValid)
            {
                var bo = this.bolOrganizationMapper.MapModelToBO(id, model);
                await this.organizationRepository.Update(this.dalOrganizationMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiOrganizationResponseModel>(this.bolOrganizationMapper.MapBOToModel(this.dalOrganizationMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiOrganizationResponseModel>(validationResult));
            }
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IOrganizationRepository>();
            var model = new ApiOrganizationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Organization>())).Returns(Task.FromResult(new Organization()));
            var service = new OrganizationService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.OrganizationModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLOrganizationMapperMock,
                                                  mock.DALMapperMockFactory.DALOrganizationMapperMock,
                                                  mock.BOLMapperMockFactory.BOLTeamMapperMock,
                                                  mock.DALMapperMockFactory.DALTeamMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.OrganizationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOrganizationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Organization>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IOrganizationRepository>();
            var model = new ApiOrganizationRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new OrganizationService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.OrganizationModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLOrganizationMapperMock,
                                                  mock.DALMapperMockFactory.DALOrganizationMapperMock,
                                                  mock.BOLMapperMockFactory.BOLTeamMapperMock,
                                                  mock.DALMapperMockFactory.DALTeamMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.OrganizationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiOrganizationRequestModel model)
        {
            ApiOrganizationRequestModel request = await this.PatchModel(id, this.OrganizationModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiOrganizationRequestModel> patch)
        {
            ApiOrganizationResponseModel record = await this.OrganizationService.Get(id);

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

                UpdateResponse <ApiOrganizationResponseModel> result = await this.OrganizationService.Update(id, model);

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

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