public async Task ThatDoesNotExistItShouldAddItToTheDatabase() { // Arrange var context = LivestockDbContextFactory.Create(_loggerFactory); var service = new AnimalCrudService(_logger, context, _mockMapper.Object); // Act var animal = new Animal(); await service.AddAsync(animal, CancellationToken.None); // Assert Assert.Equal(1, context.Animals.Count()); }
public async Task ThatAlreadyExistItShouldAddItToTheDatabase() { // Arrange var context = LivestockDbContextFactory.Create(_loggerFactory); var service = new AnimalCrudService(_logger, context, _mockMapper.Object); var animal = new Animal { Id = 1 }; // Act await service.AddAsync(animal, CancellationToken.None); var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddAsync(animal, CancellationToken.None)); // Assert Assert.NotNull(exception); Assert.Equal(1, context.Animals.Count()); }