public async Task GetUserByUsernameAsync_GivenANullUsername_ShouldThrowArgumentException() { var unitOfWorkMock = new Mock <IUnitOfWork <IBoltDbContext> >(); var service = new UsersService(unitOfWorkMock.Object); service .Awaiting(async sut => await sut.GetUserByUsernameAsync(null)) .Should() .ThrowExactly <ArgumentException>() .WithMessage("The ussername cannot be null or empty."); }
public async Task EditUserAsync_WhenTheuserDTOIsNull_ShouldThrowArgumentException() { var unitOfWorkMock = new Mock <IUnitOfWork <IBoltDbContext> >(); var service = new UsersService(unitOfWorkMock.Object); service .Awaiting(async sut => await sut.EditUserAsync("username", null)) .Should() .ThrowExactly <ArgumentNullException>() .WithMessage("Value cannot be null.\r\nParameter name: The User DTO model cannot be null or empty."); }
public async Task EditUserAsync_WhenTheUsernameIsNull_ShouldThrowArgumentException() { var unitOfWorkMock = new Mock <IUnitOfWork <IBoltDbContext> >(); var userDto = new UserDTO(); var service = new UsersService(unitOfWorkMock.Object); service .Awaiting(async sut => await sut.EditUserAsync(null, userDto)) .Should() .ThrowExactly <ArgumentException>() .WithMessage("The username cannot be null or empty."); }
public async Task EditUserAsync_WhenTheRepositoryThrowsAnException_ShouldThrowArgumentException() { var exceptionToThrow = new ArgumentException(); var unitOfWorkMock = new Mock <IUnitOfWork <IBoltDbContext> >(); unitOfWorkMock.Setup(x => x.GetRepository <IUsersRepository>()).Callback(() => throw exceptionToThrow); var service = new UsersService(unitOfWorkMock.Object); service .Awaiting(async sut => await sut.EditUserAsync(null, null)) .Should() .ThrowExactly <ArgumentException>() .WithMessage("The username cannot be null or empty."); }
public async Task GetUserByUsernameAsync_WhenTheRepositoryThrowsAnException_ShouldThrowArgumentException() { var exceptionToThrow = new ArgumentException(); var unitOfWorkMock = new Mock <IUnitOfWork <IBoltDbContext> >(); unitOfWorkMock.Setup(x => x.GetRepository <IUsersRepository>()).Callback(() => throw exceptionToThrow); var service = new UsersService(unitOfWorkMock.Object); service .Awaiting(async sut => await sut.GetUserByUsernameAsync("someUserName")) .Should() .ThrowExactly <ArgumentException>() .WithMessage("Failed to get the user by username. Please try again.") .WithInnerException <Exception>(); }