コード例 #1
0
        private async Task <ApiCountryRegionCurrencyResponseModel> CreateRecord()
        {
            var model = new ApiCountryRegionCurrencyRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1988 12:00:00 AM"));
            CreateResponse <ApiCountryRegionCurrencyResponseModel> result = await this.Client.CountryRegionCurrencyCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
コード例 #2
0
        public void MapModelToBO()
        {
            var mapper = new BOLCountryRegionCurrencyMapper();
            ApiCountryRegionCurrencyRequestModel model = new ApiCountryRegionCurrencyRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"));
            BOCountryRegionCurrency response = mapper.MapModelToBO("A", model);

            response.CurrencyCode.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
コード例 #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiCountryRegionCurrencyModelMapper();
            var model  = new ApiCountryRegionCurrencyResponseModel();

            model.SetProperties("A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"));
            ApiCountryRegionCurrencyRequestModel response = mapper.MapResponseToRequest(model);

            response.CurrencyCode.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
コード例 #4
0
        public virtual BOCountryRegionCurrency MapModelToBO(
            string countryRegionCode,
            ApiCountryRegionCurrencyRequestModel model
            )
        {
            BOCountryRegionCurrency boCountryRegionCurrency = new BOCountryRegionCurrency();

            boCountryRegionCurrency.SetProperties(
                countryRegionCode,
                model.CurrencyCode,
                model.ModifiedDate);
            return(boCountryRegionCurrency);
        }
コード例 #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiCountryRegionCurrencyRequestModel model)
        {
            CreateResponse <ApiCountryRegionCurrencyResponseModel> result = await this.CountryRegionCurrencyService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/CountryRegionCurrencies/{result.Record.CountryRegionCode}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #6
0
        public void CreatePatch()
        {
            var mapper = new ApiCountryRegionCurrencyModelMapper();
            var model  = new ApiCountryRegionCurrencyRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"));

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

            patch.ApplyTo(response);
            response.CurrencyCode.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
コード例 #7
0
        private async Task <ApiCountryRegionCurrencyRequestModel> PatchModel(string id, JsonPatchDocument <ApiCountryRegionCurrencyRequestModel> patch)
        {
            var record = await this.CountryRegionCurrencyService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiCountryRegionCurrencyRequestModel request = this.CountryRegionCurrencyModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #8
0
        public virtual async Task <CreateResponse <ApiCountryRegionCurrencyResponseModel> > Create(
            ApiCountryRegionCurrencyRequestModel model)
        {
            CreateResponse <ApiCountryRegionCurrencyResponseModel> response = new CreateResponse <ApiCountryRegionCurrencyResponseModel>(await this.countryRegionCurrencyModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolCountryRegionCurrencyMapper.MapModelToBO(default(string), model);
                var record = await this.countryRegionCurrencyRepository.Create(this.dalCountryRegionCurrencyMapper.MapBOToEF(bo));

                response.SetRecord(this.bolCountryRegionCurrencyMapper.MapBOToModel(this.dalCountryRegionCurrencyMapper.MapEFToBO(record)));
            }

            return(response);
        }
コード例 #9
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ICountryRegionCurrencyRepository>();
            var model = new ApiCountryRegionCurrencyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <CountryRegionCurrency>())).Returns(Task.FromResult(new CountryRegionCurrency()));
            var service = new CountryRegionCurrencyService(mock.LoggerMock.Object,
                                                           mock.RepositoryMock.Object,
                                                           mock.ModelValidatorMockFactory.CountryRegionCurrencyModelValidatorMock.Object,
                                                           mock.BOLMapperMockFactory.BOLCountryRegionCurrencyMapperMock,
                                                           mock.DALMapperMockFactory.DALCountryRegionCurrencyMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.CountryRegionCurrencyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCountryRegionCurrencyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <CountryRegionCurrency>()));
        }
コード例 #10
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ICountryRegionCurrencyRepository>();
            var model = new ApiCountryRegionCurrencyRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new CountryRegionCurrencyService(mock.LoggerMock.Object,
                                                           mock.RepositoryMock.Object,
                                                           mock.ModelValidatorMockFactory.CountryRegionCurrencyModelValidatorMock.Object,
                                                           mock.BOLMapperMockFactory.BOLCountryRegionCurrencyMapperMock,
                                                           mock.DALMapperMockFactory.DALCountryRegionCurrencyMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.CountryRegionCurrencyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
コード例 #11
0
        public virtual async Task <UpdateResponse <ApiCountryRegionCurrencyResponseModel> > Update(
            string countryRegionCode,
            ApiCountryRegionCurrencyRequestModel model)
        {
            var validationResult = await this.countryRegionCurrencyModelValidator.ValidateUpdateAsync(countryRegionCode, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolCountryRegionCurrencyMapper.MapModelToBO(countryRegionCode, model);
                await this.countryRegionCurrencyRepository.Update(this.dalCountryRegionCurrencyMapper.MapBOToEF(bo));

                var record = await this.countryRegionCurrencyRepository.Get(countryRegionCode);

                return(new UpdateResponse <ApiCountryRegionCurrencyResponseModel>(this.bolCountryRegionCurrencyMapper.MapBOToModel(this.dalCountryRegionCurrencyMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiCountryRegionCurrencyResponseModel>(validationResult));
            }
        }
コード例 #12
0
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiCountryRegionCurrencyRequestModel model)
        {
            ApiCountryRegionCurrencyRequestModel request = await this.PatchModel(id, this.CountryRegionCurrencyModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #13
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiCountryRegionCurrencyRequestModel> patch)
        {
            ApiCountryRegionCurrencyResponseModel record = await this.CountryRegionCurrencyService.Get(id);

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

                UpdateResponse <ApiCountryRegionCurrencyResponseModel> result = await this.CountryRegionCurrencyService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #14
0
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiCountryRegionCurrencyRequestModel model)
 {
     this.CurrencyCodeRules();
     this.ModifiedDateRules();
     return(await this.ValidateAsync(model, id));
 }