Example #1
0
        public void Login()
        {
            // Arrange
            var userLogin = new Contracts.UserLogin()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            var user = new Database.User()
            {
                Id        = Guid.NewGuid(),
                Email     = userLogin.Email,
                FirstName = "Unit",
                LastName  = "Test",
                Role      = Database.Role.Trader
            };

            user.UpdatePassword(userLogin.Password);
            _dbContext.Add(user);
            _dbContext.SaveChanges();
            _configurationMock.SetupGet(c => c[It.Is <string>(cv => cv == "JWT-IssuerSigningKey")]).Returns("aYPg2QjKQBY4Uqx8");

            // Act
            var loggedInUser = _userService.Login(userLogin);

            // Assert
            _configurationMock.VerifyGet(c => c["JWT-IssuerSigningKey"], Times.Once());
            Assert.Equal(loggedInUser.Email, userLogin.Email);
        }
Example #2
0
        public void Login_InvalidPassword()
        {
            // Arrange
            var userLogin = new Contracts.UserLogin()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            var user = new Database.User()
            {
                Id        = Guid.NewGuid(),
                Email     = userLogin.Email,
                FirstName = "Unit",
                LastName  = "Test",
                Role      = Database.Role.Trader
            };

            user.UpdatePassword("AndThisIsAsWellButDifferent");
            _dbContext.Add(user);
            _dbContext.SaveChanges();

            // Act
            // Assert
            var exception = Assert.Throws <ProblemDetailsException>(() => _userService.Login(userLogin));

            Assert.Equal(HttpStatusCode.NotFound, exception.Status);
            _configurationMock.VerifyGet(c => c["JWT-IssuerSigningKey"], Times.Never());
        }
Example #3
0
        public void Login_NotFound()
        {
            // Arrange
            var userLogin = new Contracts.UserLogin()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            // Act
            // Assert
            var exception = Assert.Throws <ProblemDetailsException>(() => _userService.Login(userLogin));

            Assert.Equal(HttpStatusCode.NotFound, exception.Status);
            _configurationMock.VerifyGet(c => c["JWT-IssuerSigningKey"], Times.Never());
        }