Example #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 ApiVoteTypeRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiVoteTypeResponseModel> createResult = await client.VoteTypeCreateAsync(createModel);

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

            ApiVoteTypeResponseModel getResponse = await client.VoteTypeGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.VoteTypeDeleteAsync(2);

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

            ApiVoteTypeResponseModel verifyResponse = await client.VoteTypeGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Example #2
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiVoteTypeModelMapper();
            var model  = new ApiVoteTypeResponseModel();

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

            response.Name.Should().Be("A");
        }
Example #3
0
        private async Task <ApiVoteTypeResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiVoteTypeRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiVoteTypeResponseModel> result = await client.VoteTypeCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Example #4
0
        public void MapModelToBO()
        {
            var mapper = new BOLVoteTypeMapper();
            ApiVoteTypeRequestModel model = new ApiVoteTypeRequestModel();

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

            response.Name.Should().Be("A");
        }
        public virtual BOVoteType MapModelToBO(
            int id,
            ApiVoteTypeRequestModel model
            )
        {
            BOVoteType boVoteType = new BOVoteType();

            boVoteType.SetProperties(
                id,
                model.Name);
            return(boVoteType);
        }
Example #6
0
        public void CreatePatch()
        {
            var mapper = new ApiVoteTypeModelMapper();
            var model  = new ApiVoteTypeRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiVoteTypeRequestModel model)
        {
            CreateResponse <ApiVoteTypeResponseModel> result = await this.VoteTypeService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/VoteTypes/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Example #8
0
        public virtual async Task <CreateResponse <ApiVoteTypeResponseModel> > Create(
            ApiVoteTypeRequestModel model)
        {
            CreateResponse <ApiVoteTypeResponseModel> response = new CreateResponse <ApiVoteTypeResponseModel>(await this.VoteTypeModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolVoteTypeMapper.MapModelToBO(default(int), model);
                var record = await this.VoteTypeRepository.Create(this.DalVoteTypeMapper.MapBOToEF(bo));

                response.SetRecord(this.BolVoteTypeMapper.MapBOToModel(this.DalVoteTypeMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiVoteTypeRequestModel request = this.VoteTypeModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Example #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IVoteTypeRepository>();
            var model = new ApiVoteTypeRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <VoteType>())).Returns(Task.FromResult(new VoteType()));
            var service = new VoteTypeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLVoteTypeMapperMock,
                                              mock.DALMapperMockFactory.DALVoteTypeMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVoteTypeRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <VoteType>()));
        }
Example #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IVoteTypeRepository>();
            var model = new ApiVoteTypeRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VoteTypeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLVoteTypeMapperMock,
                                              mock.DALMapperMockFactory.DALVoteTypeMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Example #12
0
        public virtual async Task <UpdateResponse <ApiVoteTypeResponseModel> > Update(
            int id,
            ApiVoteTypeRequestModel model)
        {
            var validationResult = await this.VoteTypeModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolVoteTypeMapper.MapModelToBO(id, model);
                await this.VoteTypeRepository.Update(this.DalVoteTypeMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiVoteTypeResponseModel>(this.BolVoteTypeMapper.MapBOToModel(this.DalVoteTypeMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiVoteTypeResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiVoteTypeRequestModel model)
        {
            ApiVoteTypeRequestModel request = await this.PatchModel(id, this.VoteTypeModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiVoteTypeResponseModel> result = await this.VoteTypeService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #15
0
        public virtual async Task <UpdateResponse <ApiVoteTypeResponseModel> > VoteTypeUpdateAsync(int id, ApiVoteTypeRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/VoteTypes/{id}", item).ConfigureAwait(false);

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