public async Task UpdateAsync_UsingNonexistentEntityKey_MustThrowException() { // Arrange var inMemoryDatabase = new DbContextOptionsBuilder <TodoDbContext>() .UseInMemoryDatabase($"db--{Guid.NewGuid():N}") .EnableDetailedErrors() .EnableSensitiveDataLogging(); var mockLogger = new Mock <ILogger <TodoItemService> >(); var owner = new Mock <IPrincipal>(); owner.SetupGet(x => x.Identity).Returns(new GenericIdentity("test")); var updateTodoItemInfo = new UpdateTodoItemInfo { Id = long.MaxValue, Name = "test", IsComplete = true, Owner = owner.Object }; var todoItemService = new TodoItemService(new TodoDbContext(inMemoryDatabase.Options), mockLogger.Object); // Act Func <Task> updateAsyncCall = async() => await todoItemService.UpdateAsync(updateTodoItemInfo); // Assert await updateAsyncCall.Should().ThrowExactlyAsync <EntityNotFoundException>( "service cannot update data using nonexistent entity key"); }
public async Task UpdateAsync_UsingNullAsUpdateTodoItemInfo_MustThrowException() { // Arrange var mockTodoDbContext = new DbContextMock <TodoDbContext>(DummyOptions); var mockLogger = new Mock <ILogger <TodoItemService> >(); var todoItemService = new TodoItemService(mockTodoDbContext.Object, mockLogger.Object); UpdateTodoItemInfo updateTodoItemInfo = null; // Act // ReSharper disable once ExpressionIsAlwaysNull Func <Task> updateAsyncCall = async() => await todoItemService.UpdateAsync(updateTodoItemInfo); // Assert await updateAsyncCall.Should().ThrowExactlyAsync <ArgumentNullException>( "service cannot update data using a null item"); }