Exemplo n.º 1
0
        public void Test_EditUser_View()
        {
            var user = CreateUserWithCompany();
            var companies = CreateCompanies();

            userService.Stub(x => x.GetById(1)).Return(user);
            companyService.Stub(x => x.GetAll()).Return(companies);

            var adminController = new AdminController(userService, companyService, orderService);
            var viewResult = adminController.EditUser(user.Id) as ViewResult;
            var dataModel = (EditUserViewModel)viewResult.ViewData.Model;

            Assert.AreEqual("*****@*****.**", dataModel.Email);
            Assert.AreEqual(2, dataModel.Companies.Count);
        }
Exemplo n.º 2
0
        public void Test_UserList_View()
        {
            var user = CreateUserWithCompany();
            userService.Stub(x => x.GetAllUsersWithCompanies()).Return(new List<User> { user });

            var adminController = new AdminController(userService, companyService, orderService);

            var viewResult = adminController.UserList(null) as ViewResult;
            var dataModel = ((IEnumerable<UserListViewModel>)viewResult.ViewData.Model).ToList();

            Assert.AreEqual(dataModel.Count, 1);
            Assert.IsTrue(dataModel.Any(d=>d.Email.Contains("*****@*****.**")));
        }
Exemplo n.º 3
0
        public void Test_DisableOrEnableUser_View()
        {
            var user = CreateUserWithCompany();

            userService.Stub(x => x.GetById(1)).Return(user);
            userService.Expect(x => x.DisableOrEnable(user)).WhenCalled(c=> user.Disabled = true);

            var adminController = new AdminController(userService, companyService, orderService);
            var viewResult = adminController.DisableOrEnableUser(user.Id) as PartialViewResult;
            var dataModel = (User)viewResult.ViewData.Model;

            Assert.AreEqual("UserListRow", viewResult.ViewName);
            Assert.IsTrue(dataModel.Disabled);
        }
Exemplo n.º 4
0
        public void Test_EditUser_View_Post()
        {
            var updatedUser = new User();
            var user = CreateUserWithCompany();

            userService.Stub(x => x.GetById(1)).Return(user);
            userService.Expect(x => x.Update(user)).WhenCalled(c => updatedUser = user);

            companyService.Stub(x => x.GetById(2)).Return(new Company() { Id = 2, Name = "TestCompany2" });

            var editUserViewModel = new EditUserViewModel()
            {
                Id = 1,
                CompanyId = 2,
                Disabled = true,
                Email = "*****@*****.**",
                FirstName = "testUser2",
                LastName = "testUser2"
            };

            var adminController = new AdminController(userService, companyService, orderService);

            var result = (RedirectToRouteResult)adminController.EditUser(editUserViewModel);

            Assert.AreEqual(updatedUser.Email, "*****@*****.**");
            Assert.AreEqual(updatedUser.FirstName, "testUser2");
            Assert.AreEqual(updatedUser.LastName, "testUser2");
            Assert.AreEqual(updatedUser.Company.Name, "TestCompany2");
            Assert.IsTrue(updatedUser.Disabled);
            Assert.AreEqual("UserList", result.RouteValues["Action"]);
        }