public async Task ForAnAnimalThatDoesNotExistItShouldThrow() { // Arrange var context = LivestockDbContextFactory.Create(_loggerFactory); var service = new WeightTransactionCrudService(_logger, context); // Act var transaction = new WeightTransaction { AnimalId = TestConstants.AnimalId1, TransactionDate = TestConstants.DefaultDate, Weight = 100 }; var exception = await Assert.ThrowsAsync <TransactionRequiresAnimalException>(async() => await service.AddAsync(transaction, CancellationToken.None)); // Assert Assert.NotNull(exception); Assert.Equal(TestConstants.AnimalId1, exception.AnimalId); Assert.Equal("The animal for this transaction could not be found.", exception.Message); }
public async Task ThatDoesNotExistItShouldAddItToTheDatabase() { // Arrange var context = LivestockDbContextFactory.Create(_loggerFactory); context.SeedTestAnimal(TestConstants.AnimalId1); context.SaveChanges(); var service = new WeightTransactionCrudService(_logger, context); // Act var transaction = new WeightTransaction { AnimalId = TestConstants.AnimalId1, TransactionDate = TestConstants.DefaultDate, Weight = 100 }; await service.AddAsync(transaction, CancellationToken.None); // Assert Assert.Equal(1, context.WeightTransactions.Count()); }