コード例 #1
0
        public void GetUserByNameNotFoundTest()
        {
            const string Name = "user";
            string message;

            AccountService accountService = new AccountService(_dalContext);
            _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once();
            _usersRepository.Expect(x => x.GetUserByName(Name)).Return(null);
            _mockRepository.ReplayAll();

            User actual = accountService.GetUserByName(Name, out message);

            Assert.AreEqual(null, actual);
            Assert.AreEqual(AccountService.UserNotFoundMessage, message);
            _mockRepository.VerifyAll();
        }
コード例 #2
0
        public void GetUserByNameSuccessTest()
        {
            const string Name = "user";
            User user = new User();
            List<Role> roles = new List<Role>
                {
                    new Role
                        {
                            Key = 1,
                            Name = "Vassas",
                            Description = "Blah"
                        }
                };
            string message;

            AccountService accountService = new AccountService(_dalContext);
            _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once();
            _dalContext.Expect(x => x.RolesRepository).Return(_rolesRepository).Repeat.Once();
            _usersRepository.Expect(x => x.GetUserByName(Name)).Return(user);
            _rolesRepository.Expect(x => x.GetRolesForUser(Name)).Return(roles).Repeat.Once();

            _mockRepository.ReplayAll();
            User actual = accountService.GetUserByName(Name, out message);

            Assert.AreEqual(user, actual);
            Assert.IsNull(message);
            _mockRepository.VerifyAll();
        }
コード例 #3
0
        public void GetUserByNameDALErrorTest()
        {
            const string Name = "user";
            string message;

            AccountService accountService = new AccountService(_dalContext);
            _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once();
            _usersRepository.Expect(x => x.GetUserByName(Name)).Throw(new DbException("An error"));
            _mockRepository.ReplayAll();

            User actual = accountService.GetUserByName(Name, out message);

            Assert.AreEqual(null, actual);
            Assert.AreEqual(AccountService.ErrorDuringReadingUserMessage, message);
            _mockRepository.VerifyAll();
        }