public void Should_ThrowException_When_CommandIsNull()
        {
            var userRepositoryMock = new Mock <IUserRepository>();
            var roleLookupMock     = new Mock <IRoleLookup>();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(m => m.Map <RegisterUserCommand, User>(It.IsAny <RegisterUserCommand>())).Returns((User)null);

            var target = new RegisterUserCommandHandler(userRepositoryMock.Object, roleLookupMock.Object, mapperMock.Object);

            var command = new RegisterUserCommand();

            Func <Task> func = async() => await target.HandleAsync(command);

            func.ShouldThrow <NullReferenceException>();
        }
        public void Should_ThrowException_When_PasswordIsNullOrEmpty()
        {
            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(u => u.RegisterAsync(It.IsAny <User>(), It.IsAny <string>())).ThrowsAsync(new ArgumentException("password is empty."));

            var roleLookupMock = new Mock <IRoleLookup>();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(m => m.Map <RegisterUserCommand, User>(It.IsAny <RegisterUserCommand>())).Returns((User)null);

            var target = new RegisterUserCommandHandler(userRepositoryMock.Object, roleLookupMock.Object, mapperMock.Object);

            var command = new RegisterUserCommand();

            Func <Task> func = async() => await target.HandleAsync(command);

            func.ShouldThrow <Exception>();
        }
        public void Should_RegisterUser_When_CommandIsValid()
        {
            var userRepositoryMock = new Mock <IUserRepository>();

            var roleLookupMock = new Mock <IRoleLookup>();

            roleLookupMock.Setup(r => r.GetUserRoleAsync()).ReturnsAsync(new Role());

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(m => m.Map <RegisterUserCommand, User>(It.IsAny <RegisterUserCommand>())).Returns(new User());

            var target = new RegisterUserCommandHandler(userRepositoryMock.Object, roleLookupMock.Object, mapperMock.Object);

            var command = new RegisterUserCommand();

            Func <Task> func = async() => await target.HandleAsync(command);

            func.ShouldNotThrow(); //Should not throw any kind of exception
        }