Exemple #1
0
        public void IndexReturnsmultipleItems()
        {
            var adminRepository = new LocalRepository <InsideUser>();
            var userManager     = new Mock <IIdentityMembershipProvider>();

            var claim = new Claim("test", "AnyId");

            userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> {
                "mockRole"
            });


            var controller = new AccountManagerController(adminRepository, userManager.Object);

            ModelHelper.SetClaimAsCurrentUserForController(claim, controller);
            var adminInRepository1 = new InsideUser()
            {
                Role = new Collection <InsideRole> {
                    ModelHelper.TestSalesRole
                },
                Id   = "Id1",
                Name = "Test Admin 1"
            };

            var adminInRepository2 = new InsideUser()
            {
                Role = new Collection <InsideRole> {
                    ModelHelper.TestSalesRole
                },
                Id   = "Id2",
                Name = "Test Admin 2"
            };

            adminRepository.Add(adminInRepository1);
            adminRepository.Add(adminInRepository2);

            userManager.Setup(um => um.GetUsers()).Returns(adminRepository.All());
            var result = controller.Index() as ViewResult;

            var model = result.Model as AccountManagerListViewModel;

            Assert.AreEqual(2, model.Collection.Count);
            Assert.AreEqual("Test Admin 1", model.Collection.Single(a => a.Id == "Id1").Name);
            Assert.AreEqual("Test Admin 2", model.Collection.Single(a => a.Id == "Id2").Name);
        }
Exemple #2
0
        public void IndexReturnsZeroItems()
        {
            var adminRepository = new Mock <IRepository <InsideUser> >();
            var userManager     = new Mock <IIdentityMembershipProvider>();
            var claim           = new Claim("test", "AnyId");

            userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> {
                "mockRole"
            });

            var controller = new AccountManagerController(adminRepository.Object, userManager.Object);

            ModelHelper.SetClaimAsCurrentUserForController(claim, controller);

            var result = controller.Index() as ViewResult;

            var model = result.Model as AccountManagerListViewModel;

            Assert.AreEqual(0, model.Collection.Count);
        }