Beispiel #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiRateRequestModel model)
 {
     this.AmountPerMinuteRules();
     this.TeacherIdRules();
     this.TeacherSkillIdRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #2
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 ApiRateRequestModel();

            createModel.SetProperties(2m, 1, 1);
            CreateResponse <ApiRateResponseModel> createResult = await client.RateCreateAsync(createModel);

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

            ApiRateResponseModel getResponse = await client.RateGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.RateDeleteAsync(2);

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

            ApiRateResponseModel verifyResponse = await client.RateGetAsync(2);

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

            model.SetProperties(2m, 1, 1);
            CreateResponse <ApiRateResponseModel> result = await client.RateCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiRateModelMapper();
            var model  = new ApiRateResponseModel();

            model.SetProperties(1, 1m, 1, 1);
            ApiRateRequestModel response = mapper.MapResponseToRequest(model);

            response.AmountPerMinute.Should().Be(1m);
            response.TeacherId.Should().Be(1);
            response.TeacherSkillId.Should().Be(1);
        }
Beispiel #5
0
        public void MapModelToBO()
        {
            var mapper = new BOLRateMapper();
            ApiRateRequestModel model = new ApiRateRequestModel();

            model.SetProperties(1m, 1, 1);
            BORate response = mapper.MapModelToBO(1, model);

            response.AmountPerMinute.Should().Be(1m);
            response.TeacherId.Should().Be(1);
            response.TeacherSkillId.Should().Be(1);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiRateRequestModel model)
        {
            CreateResponse <ApiRateResponseModel> result = await this.RateService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Rates/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Beispiel #7
0
        public virtual BORate MapModelToBO(
            int id,
            ApiRateRequestModel model
            )
        {
            BORate boRate = new BORate();

            boRate.SetProperties(
                id,
                model.AmountPerMinute,
                model.TeacherId,
                model.TeacherSkillId);
            return(boRate);
        }
Beispiel #8
0
        public void CreatePatch()
        {
            var mapper = new ApiRateModelMapper();
            var model  = new ApiRateRequestModel();

            model.SetProperties(1m, 1, 1);

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

            patch.ApplyTo(response);
            response.AmountPerMinute.Should().Be(1m);
            response.TeacherId.Should().Be(1);
            response.TeacherSkillId.Should().Be(1);
        }
Beispiel #9
0
        public virtual async Task <CreateResponse <ApiRateResponseModel> > Create(
            ApiRateRequestModel model)
        {
            CreateResponse <ApiRateResponseModel> response = new CreateResponse <ApiRateResponseModel>(await this.rateModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolRateMapper.MapModelToBO(default(int), model);
                var record = await this.rateRepository.Create(this.dalRateMapper.MapBOToEF(bo));

                response.SetRecord(this.bolRateMapper.MapBOToModel(this.dalRateMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiRateRequestModel request = this.RateModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #11
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IRateRepository>();
            var model = new ApiRateRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Rate>())).Returns(Task.FromResult(new Rate()));
            var service = new RateService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.RateModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLRateMapperMock,
                                          mock.DALMapperMockFactory.DALRateMapperMock);

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

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

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new RateService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.RateModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLRateMapperMock,
                                          mock.DALMapperMockFactory.DALRateMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.RateModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #13
0
        public virtual async Task <UpdateResponse <ApiRateResponseModel> > Update(
            int id,
            ApiRateRequestModel model)
        {
            var validationResult = await this.rateModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolRateMapper.MapModelToBO(id, model);
                await this.rateRepository.Update(this.dalRateMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiRateResponseModel>(this.bolRateMapper.MapBOToModel(this.dalRateMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiRateResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiRateRequestModel model)
        {
            ApiRateRequestModel request = await this.PatchModel(id, this.RateModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiRateResponseModel> result = await this.RateService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #16
0
        public virtual async Task <UpdateResponse <ApiRateResponseModel> > RateUpdateAsync(int id, ApiRateRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Rates/{id}", item).ConfigureAwait(false);

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