public async Task RemoveMessageFromUser() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "RemoveMessageFromUser_Database") .Options; var dbContext = new ApplicationDbContext(options); var messageService = new MessageService(dbContext); await messageService.AddMessageToUserAsync("Message1", "u1", null); await messageService.AddMessageToUserAsync("Message2", "u2", null); await messageService.MakeAllMessagesOld("u1"); await messageService.RemoveMessageFromUserAsync(1, "u1"); var messagesCount = await dbContext.Messages.CountAsync(); var message = await dbContext.Messages.FirstAsync(); Assert.Equal(2, message.Id); Assert.Equal("Message2", message.Content); Assert.Equal("u2", message.UserId); Assert.True(message.IsNew); Assert.Equal(1, messagesCount); }