Created
March 17, 2024 05:33
-
-
Save Msirkovsky/fe518a751b0ec861f5a8f491807bdf6f to your computer and use it in GitHub Desktop.
Tabnine - DeleteUserCommandHandlerTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DeleteUserCommandHandlerTests | |
{ | |
private readonly AssistantsAIDbContext _context; | |
private readonly DeleteUserCommandHandler _handler; | |
public DeleteUserCommandHandlerTests() | |
{ | |
var options = new DbContextOptionsBuilder<AssistantsAIDbContext>() | |
.UseInMemoryDatabase(databaseName: "AssistantsAITest") | |
.Options; | |
_context = new AssistantsAIDbContext(options); | |
_handler = new DeleteUserCommandHandler(_context); | |
} | |
[Fact] | |
public async Task Handle_WhenUserExistsAndIsNotLocked_ShouldDeleteUser() | |
{ | |
// Arrange | |
var userId = 1; | |
var command = new DeleteUserCommandInput(userId); | |
var user = new User { User_Id = userId, Locked = false }; | |
_context.Users.Add(user); | |
await _context.SaveChangesAsync(); | |
// Act | |
await _handler.Handle(command, default); | |
// Assert | |
var deletedUser = await _context.Users.FirstOrDefaultAsync(u => u.User_Id == userId); | |
deletedUser.Should().BeNull(); | |
} | |
[Fact] | |
public async Task Handle_WhenUserExistsAndIsLocked_ShouldNotDeleteUser() | |
{ | |
// Arrange | |
var userId = 1; | |
var command = new DeleteUserCommandInput(userId); | |
var user = new User { User_Id = userId, Locked = true }; | |
_context.Users.Add(user); | |
await _context.SaveChangesAsync(); | |
// Act | |
await _handler.Handle(command, default); | |
// Assert | |
var deletedUser = await _context.Users.FirstOrDefaultAsync(u => u.User_Id == userId); | |
deletedUser.Should().NotBeNull(); | |
} | |
[Fact] | |
public async Task Handle_WhenUserDoesNotExist_ShouldNotDeleteUser() | |
{ | |
// Arrange | |
var userId = 1; | |
var command = new DeleteUserCommandInput(userId); | |
_context.Users.Add(new User { User_Id = 2, Locked = false }); | |
await _context.SaveChangesAsync(); | |
// Act | |
await _handler.Handle(command, default); | |
// Assert | |
var deletedUser = await _context.Users.FirstOrDefaultAsync(u => u.User_Id == userId); | |
deletedUser.Should().BeNull(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment