예제 #1
0
        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.");
        }
예제 #2
0
        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.");
        }
예제 #3
0
        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.");
        }
예제 #4
0
        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.");
        }
예제 #5
0
        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>();
        }