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); }
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")); }
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")); }
public virtual BOCountryRegionCurrency MapModelToBO( string countryRegionCode, ApiCountryRegionCurrencyRequestModel model ) { BOCountryRegionCurrency boCountryRegionCurrency = new BOCountryRegionCurrency(); boCountryRegionCurrency.SetProperties( countryRegionCode, model.CurrencyCode, model.ModifiedDate); return(boCountryRegionCurrency); }
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)); } }
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")); }
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); } }
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); }
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>())); }
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>())); }
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)); } }
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)); } } }
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)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiCountryRegionCurrencyRequestModel model) { this.CurrencyCodeRules(); this.ModifiedDateRules(); return(await this.ValidateAsync(model, id)); }