Exemplo n.º 1
0
        public async Task When_logging_in_user_with_incorrect_password()
        {
            var mockUserRepository = new Mock <IUserRepository>();
            var guid = Guid.NewGuid();

            mockUserRepository.Setup(x => x.GetUserByEmailAsync(It.IsAny <string>())).ReturnsAsync(new UserInfo
            {
                FirstName = "First Name",
                LastName  = "Last Name",
                Email     = "*****@*****.**",
                Guid      = guid,
                Password  = "******"
            });
            mockUserRepository.Setup(x => x.VerifyPasswordAsync(It.IsAny <UserInfo>())).ReturnsAsync(false);

            var mockSessionsRepository = new Mock <SessionsRepository>();

            mockSessionsRepository.Setup(x => x.AuthorizeSessionAsync(It.IsAny <UserInfo>()));

            var loginUserHelper = new LoginUserHelper(mockUserRepository.Object, mockSessionsRepository.Object);

            var result = await loginUserHelper.LoginUserAsync(new LoginUserHelper.LoginData());

            Assert.That(result.FirstName, Is.EqualTo(null));
            Assert.That(result.LastName, Is.EqualTo(null));
            Assert.That(result.Email, Is.EqualTo(null));
            Assert.That(result.Guid, Is.EqualTo(new Guid()));
            Assert.That(result.Password, Is.EqualTo(null));
        }
Exemplo n.º 2
0
        public void When_logging_in_with_null_login_data()
        {
            var mockAuthorizationData = new Mock <IUserRepository>();
            var guid      = Guid.NewGuid();
            var loginData = new LoginUserHelper.LoginData
            {
                Email = "*****@*****.**",
                Guid  = guid
            };
            var userInfo = new UserInfo
            {
                FirstName = "First Name",
                LastName  = "Last Name",
                Email     = loginData.Email,
                Guid      = loginData.Guid,
                Password  = "******"
            };

            mockAuthorizationData.Setup(x => x.GetUserByEmailAsync(It.IsAny <string>())).ReturnsAsync(userInfo);
            mockAuthorizationData.Setup(x => x.VerifyPasswordAsync(It.IsAny <UserInfo>())).ReturnsAsync(true);

            var mockSessionsRepository = new Mock <SessionsRepository>();

            mockSessionsRepository.Setup(x => x.AuthorizeSessionAsync(It.IsAny <UserInfo>())).ReturnsAsync(false);

            var loginUserHelper = new LoginUserHelper(mockAuthorizationData.Object, mockSessionsRepository.Object);

            Assert.ThrowsAsync <NotAuthorizedException>(() => loginUserHelper.LoginUserAsync(new LoginUserHelper.LoginData {
                Email = "*****@*****.**", Guid = Guid.NewGuid()
            }));
        }
Exemplo n.º 3
0
        public async Task When_logging_in_user_with_correct_password()
        {
            var mockAuthorizationData = new Mock <IUserRepository>();
            var guid      = Guid.NewGuid();
            var loginData = new LoginUserHelper.LoginData
            {
                Email = "*****@*****.**",
                Guid  = guid
            };
            var userInfo = new UserInfo
            {
                FirstName = "First Name",
                LastName  = "Last Name",
                Email     = loginData.Email,
                Guid      = loginData.Guid,
                Password  = "******"
            };

            mockAuthorizationData.Setup(x => x.GetUserByEmailAsync(It.IsAny <string>())).ReturnsAsync(userInfo);
            mockAuthorizationData.Setup(x => x.VerifyPasswordAsync(It.IsAny <UserInfo>())).ReturnsAsync(true);

            var mockSessionsRepository = new Mock <SessionsRepository>();

            mockSessionsRepository.Setup(x => x.AuthorizeSessionAsync(It.IsAny <UserInfo>())).ReturnsAsync(true);

            var loginUserController = new LoginUserHelper(mockAuthorizationData.Object, mockSessionsRepository.Object);

            var result = await loginUserController.LoginUserAsync(loginData);

            Assert.That(result.FirstName, Is.EqualTo(userInfo.FirstName));
            Assert.That(result.LastName, Is.EqualTo(userInfo.LastName));
            Assert.That(result.Email, Is.EqualTo(userInfo.Email));
            Assert.That(result.Guid, Is.EqualTo(userInfo.Guid));
            Assert.That(result.Password, Is.EqualTo(userInfo.Password));
        }
        public async Task <UserInfo> Post(LoginUserHelper.LoginData data)
        {
            var loginUserHelper = new LoginUserHelper();

            return(await loginUserHelper.LoginUserAsync(data));
        }