public void GetUser_ThrowsInvalidUserNameException_WhenRepositoryThrowsInvalidUserNameException()
        {
            // arrange
            var exMessage      = "Invalid username";
            var repositoryMock = new Mock <IUserRepository>();

            repositoryMock.Setup(m => m.GetUser(It.IsAny <string>())).Throws(new InvalidUserNameException(exMessage, null));

            var sut = new UserAuthManager(repositoryMock.Object, null);

            // act
            var ex = Assert.ThrowsException <InvalidUserNameException>(() => sut.GetUser("someUserName"));

            // assert
            Assert.AreEqual(exMessage, ex.Message);
        }
        public UserAuthManager AuthMock(string[] roles)
        {
            var user = Mock.Of <IPrincipal>(u => u.Identity.Name == CurrentUserUsername);

            Mock.Get(user)
            .Setup(u => u.IsInRole(It.Is <string>(s => roles.Contains(s))))
            .Returns(true);
            Mock.Get(user)
            .Setup(u => u.IsInRole(It.Is <string>(s => !roles.Contains(s))))
            .Returns(false);
            var AuthM = new UserAuthManager(
                user: user,
                logger: Mock.Of <ILogger>()
                );

            return(AuthM);
        }
Beispiel #3
0
        public void CreateNewUser_UserNameValidationFails_2()
        {
            //	custom validation checks for UserName: should be a valid active directory account (domain\username)

            // arrange
            var sutWithADValidation = new UserAuthManager(new SqlUserRepository(_connectionString), new List <IValidation <User> > {
                new UserNameIsValidActiveDirectoryAccountValidation()
            });

            try
            {
                // act
                sutWithADValidation.CreateUser(new User("notAValidADAccount", "somePwd"));
                Assert.Fail("Expected exception on the previous line.");
            }
            catch (Exception ex)
            {
                // assert
                Assert.IsInstanceOfType(ex, typeof(ValidationException));
                Assert.AreEqual(new UserNameIsValidActiveDirectoryAccountValidation().Message, ex.Message);
            }
        }
 public LogInController()
 {
     UserAuthManager    = new UserAuthManager();
     ProjectListManager = new ProjectListManager();
 }