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 ApiSaleRequestModel(); createModel.SetProperties(2m, "B", "B", 1, 1, "B"); CreateResponse <ApiSaleResponseModel> createResult = await client.SaleCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiSaleResponseModel getResponse = await client.SaleGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.SaleDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiSaleResponseModel verifyResponse = await client.SaleGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSaleRequestModel model) { this.IpAddressRules(); this.NotesRules(); this.SaleDateRules(); this.TransactionIdRules(); return(await this.ValidateAsync(model, id)); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSaleRequestModel model) { this.AmountRules(); this.ClientIdRules(); this.NoteRules(); this.PetIdRules(); this.SaleDateRules(); this.SalesPersonIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiSaleResponseModel> CreateRecord(ApiClient client) { var model = new ApiSaleRequestModel(); model.SetProperties(2m, "B", "B", 1, 1, "B"); CreateResponse <ApiSaleResponseModel> result = await client.SaleCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSaleRequestModel model) { this.AmountRules(); this.FirstNameRules(); this.LastNameRules(); this.PaymentTypeIdRules(); this.PetIdRules(); this.PhoneRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiSaleResponseModel> CreateRecord() { var model = new ApiSaleRequestModel(); model.SetProperties(2m, 1, "B", 1, DateTime.Parse("1/1/1988 12:00:00 AM"), 2); CreateResponse <ApiSaleResponseModel> result = await this.Client.SaleCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiSaleModelMapper(); var model = new ApiSaleResponseModel(); model.SetProperties(1, "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1); ApiSaleRequestModel response = mapper.MapResponseToRequest(model); response.IpAddress.Should().Be("A"); response.Note.Should().Be("A"); response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.TransactionId.Should().Be(1); }
public void MapModelToBO() { var mapper = new BOLSaleMapper(); ApiSaleRequestModel model = new ApiSaleRequestModel(); model.SetProperties("A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1); BOSale response = mapper.MapModelToBO(1, model); response.IpAddress.Should().Be("A"); response.Note.Should().Be("A"); response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.TransactionId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiSaleRequestModel model) { CreateResponse <ApiSaleResponseModel> result = await this.SaleService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Sales/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLSaleMapper(); ApiSaleRequestModel model = new ApiSaleRequestModel(); model.SetProperties(1m, "A", "A", 1, 1, "A"); BOSale response = mapper.MapModelToBO(1, model); response.Amount.Should().Be(1m); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.PaymentTypeId.Should().Be(1); response.PetId.Should().Be(1); response.Phone.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiSaleModelMapper(); var model = new ApiSaleResponseModel(); model.SetProperties(1, 1m, 1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1); ApiSaleRequestModel response = mapper.MapResponseToRequest(model); response.Amount.Should().Be(1m); response.ClientId.Should().Be(1); response.Note.Should().Be("A"); response.PetId.Should().Be(1); response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.SalesPersonId.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiSaleModelMapper(); var model = new ApiSaleResponseModel(); model.SetProperties(1, 1m, "A", "A", 1, 1, "A"); ApiSaleRequestModel response = mapper.MapResponseToRequest(model); response.Amount.Should().Be(1m); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.PaymentTypeId.Should().Be(1); response.PetId.Should().Be(1); response.Phone.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiSaleResponseModel> > Create( ApiSaleRequestModel model) { CreateResponse <ApiSaleResponseModel> response = new CreateResponse <ApiSaleResponseModel>(await this.SaleModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolSaleMapper.MapModelToBO(default(int), model); var record = await this.SaleRepository.Create(this.DalSaleMapper.MapBOToEF(bo)); response.SetRecord(this.BolSaleMapper.MapBOToModel(this.DalSaleMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiSaleRequestModel> PatchModel(int id, JsonPatchDocument <ApiSaleRequestModel> patch) { var record = await this.SaleService.Get(id); if (record == null) { return(null); } else { ApiSaleRequestModel request = this.SaleModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOSale MapModelToBO( int id, ApiSaleRequestModel model ) { BOSale boSale = new BOSale(); boSale.SetProperties( id, model.IpAddress, model.Note, model.SaleDate, model.TransactionId); return(boSale); }
public void CreatePatch() { var mapper = new ApiSaleModelMapper(); var model = new ApiSaleRequestModel(); model.SetProperties("A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1); JsonPatchDocument <ApiSaleRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSaleRequestModel(); patch.ApplyTo(response); response.IpAddress.Should().Be("A"); response.Note.Should().Be("A"); response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.TransactionId.Should().Be(1); }
public virtual BOSale MapModelToBO( int id, ApiSaleRequestModel model ) { BOSale boSale = new BOSale(); boSale.SetProperties( id, model.Amount, model.FirstName, model.LastName, model.PaymentTypeId, model.PetId, model.Phone); return(boSale); }
public virtual BOSale MapModelToBO( int id, ApiSaleRequestModel model ) { BOSale boSale = new BOSale(); boSale.SetProperties( id, model.Amount, model.ClientId, model.Note, model.PetId, model.SaleDate, model.SalesPersonId); return(boSale); }
public async void Create() { var mock = new ServiceMockFacade <ISaleRepository>(); var model = new ApiSaleRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Sale>())).Returns(Task.FromResult(new Sale())); var service = new SaleService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SaleModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSaleMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); CreateResponse <ApiSaleResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.SaleModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSaleRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Sale>())); }
public async void Delete() { var mock = new ServiceMockFacade <ISaleRepository>(); var model = new ApiSaleRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new SaleService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SaleModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSaleMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.SaleModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public void CreatePatch() { var mapper = new ApiSaleModelMapper(); var model = new ApiSaleRequestModel(); model.SetProperties(1m, "A", "A", 1, 1, "A"); JsonPatchDocument <ApiSaleRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSaleRequestModel(); patch.ApplyTo(response); response.Amount.Should().Be(1m); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.PaymentTypeId.Should().Be(1); response.PetId.Should().Be(1); response.Phone.Should().Be("A"); }
public void CreatePatch() { var mapper = new ApiSaleModelMapper(); var model = new ApiSaleRequestModel(); model.SetProperties(1m, 1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1); JsonPatchDocument <ApiSaleRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSaleRequestModel(); patch.ApplyTo(response); response.Amount.Should().Be(1m); response.ClientId.Should().Be(1); response.Note.Should().Be("A"); response.PetId.Should().Be(1); response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.SalesPersonId.Should().Be(1); }
public virtual async Task <UpdateResponse <ApiSaleResponseModel> > Update( int id, ApiSaleRequestModel model) { var validationResult = await this.SaleModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolSaleMapper.MapModelToBO(id, model); await this.SaleRepository.Update(this.DalSaleMapper.MapBOToEF(bo)); var record = await this.SaleRepository.Get(id); return(new UpdateResponse <ApiSaleResponseModel>(this.BolSaleMapper.MapBOToModel(this.DalSaleMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiSaleResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSaleRequestModel model) { ApiSaleRequestModel request = await this.PatchModel(id, this.SaleModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiSaleResponseModel> result = await this.SaleService.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 <ApiSaleRequestModel> patch) { ApiSaleResponseModel record = await this.SaleService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSaleRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSaleResponseModel> result = await this.SaleService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiSaleResponseModel> > SaleUpdateAsync(int id, ApiSaleRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Sales/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiSaleResponseModel> >(httpResponse.Content.ContentToString())); }