コード例 #1
0
 public void TearDownObjects()
 {
     _userList = null;
     _dbContextMock = null;
     _userObj = null;
     _dbContextMock = null;
 }
コード例 #2
0
        public void InitializeUnitTests()
        {
            // create some mock products to play with
            _userObj = new User
                                {
                                    Name = "Chris Smith",
                                    id = 2,
                                    Password = "******",
                                    Role = "Developer",
                                    IsEnabled = true
                                };

            _userList = new List<User>
                                 {
                                     _userObj,
                                     new User
                                         {
                                             Name = "Awin George",
                                             Password = "******",
                                             Role = "Developer",
                                             IsEnabled = false,
                                             id = 3
                                         },
                                     new User
                                         {
                                             Name = "Richard Child",
                                             Password = "******",
                                             Role = "Developer",
                                             IsEnabled = true,
                                             id = 4
                                         }
                                 };

            _mockUserRepository = new Mock<IUserRepository>();
        }
コード例 #3
0
        public void InitializeUnitTests()
        {
            // create some mock products to play with
            _isValid = true;

            _userObj = new User
                           {
                               Name = "Chris Smith",
                               Password = "******",
                               Role = "Developer",
                               IsEnabled = true,
                               id = 2
                           };

            _userList =
                new List<User>
                    {
                        _userObj,
                        new User
                            {
                                Name = "Awin George",
                                Password = "******",
                                Role = "Developer",
                                IsEnabled = false,
                                id = 3
                            },
                        new User
                            {
                                Name = "Richard Child",
                                Password = "******",
                                Role = "Developer",
                                IsEnabled = true,
                                id = 4
                            }
                    }.AsQueryable();

            _dbContextMock = new Mock<dbContext>();

            _dbSetMock = new Mock<IDbSet<User>>();

            _dbSetMock.Setup(m => m.Provider).Returns(_userList.Provider);
            _dbSetMock.Setup(m => m.Expression).Returns(_userList.Expression);
            _dbSetMock.Setup(m => m.ElementType).Returns(_userList.ElementType);
            _dbSetMock.Setup(m => m.GetEnumerator()).Returns(_userList.GetEnumerator());
        }
コード例 #4
0
        /// <summary>
        ///     Get user By Name
        /// </summary>
        /// <param name="name">user Name</param>
        /// <param name="userObj">Object to be retrieved</param>
        /// <returns>Returns true if success, else false</returns>
        public bool GetUserBy(string name, out User userObj)
        {
            var succeed = false;
            userObj = null;

            if (this._userRepository.GetUserBy(name, out userObj))
            {
                succeed = true;
            }

            return succeed;
        }
コード例 #5
0
        /// <summary>
        ///     Get user By Id
        /// </summary>
        /// <param name="id">user Id</param>
        /// <param name="userObj">Object to be retrieved</param>
        /// <returns>Returns true if success, else false</returns>
        public bool GetUserBy(int id, out User userObj)
        {
            var succeed = false;
            userObj = null;

            if (this._userRepository.GetUserBy(id, out userObj)) succeed = true;

            return succeed;
        }
コード例 #6
0
        /// <summary>
        ///     Get user By Id.
        /// </summary>
        /// <param name="id">user Id.</param>
        /// <param name="userObj">Object to be retrieved.</param>
        /// <returns>Returns true if success, else false.</returns>
        public bool GetUserBy(int id, out User userObj)
        {
            var succeed = false;

            userObj = this._context.User.First(p => p.id == id);
            succeed = true;

            return succeed;
        }
コード例 #7
0
        /// <summary>
        ///     Get user By Name
        /// </summary>
        /// <param name="name">user Name</param>
        /// <param name="userObj">Object to be retrieved</param>
        /// <returns>Returns true if success, else false</returns>
        public bool GetUserBy(string name, out User userObj)
        {
            var succeed = false;

            userObj = this._context.User.First(p => p.Name == name);
            succeed = true;

            return succeed;
        }
コード例 #8
0
 public void TearDownObjects()
 {
     _userList = null;
     _userObj = null;
     _mockUserRepository = null;
 }
コード例 #9
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);
        }
コード例 #10
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);
        }