public async Task CreateAsync_SupplierValidationFailed_ThrowsError() { // Arrange var fixture = new Fixture(); var tights = new TightsUpdateModel(); var expected = fixture.Create <string>(); var supplierGetService = new Mock <ISupplierGetService>(); supplierGetService .Setup(x => x.ValidateAsync(tights)) .Throws(new InvalidOperationException(expected)); var buyerGetService = new Mock <IBuyerGetService>(); buyerGetService.Setup(x => x.ValidateAsync(tights)).Throws(new InvalidOperationException(expected)); var tightsDataAccess = new Mock <ITightsDataAccess>(); var tightsGetService = new TightsCreateService(tightsDataAccess.Object, supplierGetService.Object, buyerGetService.Object); // Act var action = new Func <Task>(() => tightsGetService.CreateAsync(tights)); // Assert await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected); tightsDataAccess.Verify(x => x.InsertAsync(tights), Times.Never); }
public async Task CreateAsync_DepartmentValidationSucceed_CreatesTights() { // Arrange var tights = new TightsUpdateModel(); var expected = new Tights(); var supplierGetService = new Mock <ISupplierGetService>(); supplierGetService.Setup(x => x.ValidateAsync(tights)); var buyerGetService = new Mock <IBuyerGetService>(); buyerGetService.Setup(x => x.ValidateAsync(tights)); var tightsDataAccess = new Mock <ITightsDataAccess>(); tightsDataAccess.Setup(x => x.InsertAsync(tights)).ReturnsAsync(expected); var tightsGetService = new TightsCreateService(tightsDataAccess.Object, supplierGetService.Object, buyerGetService.Object); // Act var result = await tightsGetService.CreateAsync(tights); // Assert result.Should().Be(expected); }
public async Task <Tights> CreateAsync(TightsUpdateModel tights) { await BuyerGetService.ValidateAsync(tights); await SupplierGetService.ValidateAsync(tights); return(await TightsDataAccess.InsertAsync(tights)); }
public async Task <Tights> InsertAsync(TightsUpdateModel tights) { var result = await this.Context.AddAsync(this.Mapper.Map <DataLayer.Entities.Tights>(tights)); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Tights>(result.Entity)); }
public async Task <Tights> UpdateAsync(TightsUpdateModel tights) { var existing = await this.Get(tights); var result = this.Mapper.Map(tights, existing); this.Context.Update(result); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Tights>(result)); }