コード例 #1
0
        public void WhenUserNameAndPasswordIsProvidedValidateUserTest(
            [Values("Richard Child", "Chris Smith", "Awin George", "", null)] string userName,
            [Values("pass", "Test Password", "", null)] string password)
        {
            // return valid user
            var Valid = true;
            _userObj = _userList.FirstOrDefault(p => p.Name == userName && p.Password == password);
            _mockUserRepository.Setup(
                mr =>
                mr.ValidateUser(
                    It.IsIn(_userObj != null ? _userObj.Name : string.Empty),
                    It.IsIn(_userObj != null ? _userObj.Password : string.Empty),
                    out Valid)).Returns(true);

            // setup of Mock User Repository
            var target = new UserService(_mockUserRepository.Object);

            var success = target.ValidateUser(userName, password, out Valid);

            // assert
            if (success)
            {
                Assert.IsTrue(Valid);
            }
            else Assert.IsFalse(success);
        }
コード例 #2
0
        public void WhenUserNameAndPasswordIsNullOrEmptyValidateUserTest(
            [Values("", null)] string userName,
            [Values("pass", "Test Password", "", null)] string password)
        {
            // return valid user
            var isValid = true;
            _userObj = _userList.FirstOrDefault(p => p.Name == userName && p.Password == password);
            _mockUserRepository.Setup(
                mr =>
                mr.ValidateUser(
                    It.IsIn(_userObj != null ? _userObj.Name : string.Empty),
                    It.IsIn(_userObj != null ? _userObj.Password : string.Empty),
                    out isValid)).Returns(false);

            // setup of Mock User Repository
            var target = new UserService(_mockUserRepository.Object);

            var success = target.ValidateUser(userName, password, out isValid);

            // assert
            Assert.IsFalse(success);
        }