Beispiel #1
0
        public void Login_NullPassword_ShouldThrow()
        {
            var videoRepositoryMock       = new Mock <IRepository <Video> >();
            var unitOfWorkMock            = new Mock <IUnitOfWork>();
            var commentRepositoryMock     = new Mock <IRepository <Comment> >();
            var userRepositoryMock        = new Mock <IRepository <VidconfileUser> >();
            var passwordHasherMock        = new Mock <IPasswordHasher>();
            var subscribeToSubscriberMock = new Mock <IRepository <SubscribeToSubscribers> >();

            VidconfileUserServices userService =
                new VidconfileUserServices(userRepositoryMock.Object, unitOfWorkMock.Object, passwordHasherMock.Object,
                                           videoRepositoryMock.Object, subscribeToSubscriberMock.Object);

            string username = "******";
            string password = "******";

            string message = Assert.Throws <NullReferenceException>(() => userService.Login(username, null)).Message;

            Assert.Equal("password cannot be null or empty", message);
        }
Beispiel #2
0
        public void Login_NotExistingUser_ShouldReturnNull()
        {
            var videoRepositoryMock       = new Mock <IRepository <Video> >();
            var unitOfWorkMock            = new Mock <IUnitOfWork>();
            var commentRepositoryMock     = new Mock <IRepository <Comment> >();
            var userRepositoryMock        = new Mock <IRepository <VidconfileUser> >();
            var passwordHasherMock        = new Mock <IPasswordHasher>();
            var subscribeToSubscriberMock = new Mock <IRepository <SubscribeToSubscribers> >();

            VidconfileUserServices userService =
                new VidconfileUserServices(userRepositoryMock.Object, unitOfWorkMock.Object, passwordHasherMock.Object,
                                           videoRepositoryMock.Object, subscribeToSubscriberMock.Object);

            string username = "******";
            string password = "******";

            var user = userService.Login(username, password);

            passwordHasherMock.Verify(x => x.VerifyPasswordHash(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <byte[]>()), Times.Never);

            Assert.Null(user);
        }
Beispiel #3
0
        public void Login_NotWrongPassword_ShouldReturnUser()
        {
            var videoRepositoryMock       = new Mock <IRepository <Video> >();
            var unitOfWorkMock            = new Mock <IUnitOfWork>();
            var commentRepositoryMock     = new Mock <IRepository <Comment> >();
            var userRepositoryMock        = new Mock <IRepository <VidconfileUser> >();
            var passwordHasherMock        = new Mock <IPasswordHasher>();
            var subscribeToSubscriberMock = new Mock <IRepository <SubscribeToSubscribers> >();


            VidconfileUser user = new VidconfileUser();

            string username = "******";
            string password = "******";

            user.Username = username;

            userRepositoryMock.Setup(x => x.All())
            .Returns(new List <VidconfileUser>()
            {
                user
            }.AsQueryable());

            passwordHasherMock.Setup(x => x.VerifyPasswordHash(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <byte[]>()))
            .Returns(true);

            VidconfileUserServices userService =
                new VidconfileUserServices(userRepositoryMock.Object, unitOfWorkMock.Object, passwordHasherMock.Object,
                                           videoRepositoryMock.Object, subscribeToSubscriberMock.Object);

            var userRet = userService.Login(username, password);

            passwordHasherMock.Verify(x => x.VerifyPasswordHash(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <byte[]>()), Times.Once);

            Assert.Same(user, userRet);
        }