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

            createModel.SetProperties("B");
            CreateResponse <ApiBreedResponseModel> createResult = await client.BreedCreateAsync(createModel);

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

            ApiBreedResponseModel getResponse = await client.BreedGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.BreedDeleteAsync(2);

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

            ApiBreedResponseModel verifyResponse = await client.BreedGetAsync(2);

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

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

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

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

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

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

            response.Name.Should().Be("A");
        }
        public void MapRequestToResponse()
        {
            var mapper = new ApiBreedModelMapper();
            var model  = new ApiBreedRequestModel();

            model.SetProperties("A", 1);
            ApiBreedResponseModel response = mapper.MapRequestToResponse(1, model);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
            response.SpeciesId.Should().Be(1);
        }
        public virtual BOBreed MapModelToBO(
            int id,
            ApiBreedRequestModel model
            )
        {
            BOBreed boBreed = new BOBreed();

            boBreed.SetProperties(
                id,
                model.Name);
            return(boBreed);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiBreedRequestModel model)
        {
            CreateResponse <ApiBreedResponseModel> result = await this.BreedService.Create(model);

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

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
Beispiel #9
0
        public virtual async Task <CreateResponse <ApiBreedResponseModel> > Create(
            ApiBreedRequestModel model)
        {
            CreateResponse <ApiBreedResponseModel> response = new CreateResponse <ApiBreedResponseModel>(await this.BreedModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolBreedMapper.MapModelToBO(default(int), model);
                var record = await this.BreedRepository.Create(this.DalBreedMapper.MapBOToEF(bo));

                response.SetRecord(this.BolBreedMapper.MapBOToModel(this.DalBreedMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiBreedRequestModel request = this.BreedModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #11
0
        public virtual async Task <UpdateResponse <ApiBreedResponseModel> > Update(
            int id,
            ApiBreedRequestModel model)
        {
            var validationResult = await this.BreedModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolBreedMapper.MapModelToBO(id, model);
                await this.BreedRepository.Update(this.DalBreedMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiBreedResponseModel>(this.BolBreedMapper.MapBOToModel(this.DalBreedMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiBreedResponseModel>(validationResult));
            }
        }
Beispiel #12
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IBreedRepository>();
            var model = new ApiBreedRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Breed>())).Returns(Task.FromResult(new Breed()));
            var service = new BreedService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.BreedModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLBreedMapperMock,
                                           mock.DALMapperMockFactory.DALBreedMapperMock,
                                           mock.BOLMapperMockFactory.BOLPetMapperMock,
                                           mock.DALMapperMockFactory.DALPetMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.BreedModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBreedRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Breed>()));
        }
Beispiel #13
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IBreedRepository>();
            var model = new ApiBreedRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new BreedService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.BreedModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLBreedMapperMock,
                                           mock.DALMapperMockFactory.DALBreedMapperMock,
                                           mock.BOLMapperMockFactory.BOLPetMapperMock,
                                           mock.DALMapperMockFactory.DALPetMapperMock);

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

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

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiBreedResponseModel> result = await this.BreedService.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 <ApiBreedRequestModel> patch)
        {
            ApiBreedResponseModel record = await this.BreedService.Get(id);

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

                UpdateResponse <ApiBreedResponseModel> result = await this.BreedService.Update(id, model);

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

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiBreedResponseModel> >(httpResponse.Content.ContentToString()));
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiBreedRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }