Exemplo n.º 1
0
        public void EditPostEmptyMembershipProviderIdReturnsViewOnException()
        {
            var adminRepository            = new LocalRepository <InsideUser>();
            var userManager                = new Mock <IIdentityMembershipProvider>();
            var accountManagerInRepository = ModelHelper.TestAccountManager;

            accountManagerInRepository.Id = null;
            adminRepository.Add(accountManagerInRepository);

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

            var accountManager1 = new AccountManagerViewModel()
            {
                Name     = accountManagerInRepository.Name,
                Id       = accountManagerInRepository.Id,
                Password = "******",
                Email    = "*****@*****.**"
            };

            userManager.Setup(u => u.GetUsers()).Returns(adminRepository.All);
            userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository);
            userManager.Setup(u => u.Create(It.IsAny <InsideUser>(), "Test Edited")).Returns(false).Verifiable();

            var result = controller.Edit(accountManager1) as ViewResult;

            Assert.IsTrue(controller.ModelState.Count > 0);
        }
Exemplo n.º 2
0
        public void EditPostSavesDataForOkDataWithEmptyMembershipProviderId()
        {
            var adminRepository            = new LocalRepository <InsideUser>();
            var userManager                = new Mock <IIdentityMembershipProvider>();
            var accountManagerInRepository = ModelHelper.TestAccountManager;

            accountManagerInRepository.Id           = null;
            accountManagerInRepository.PasswordHash = "HashedOldPassword";
            adminRepository.Add(accountManagerInRepository);

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

            var accountManager1 = new AccountManagerViewModel()
            {
                Name     = accountManagerInRepository.Name,
                Id       = accountManagerInRepository.Id,
                Password = "******",
                Email    = "*****@*****.**"
            };


            userManager.Setup(u => u.GetUsers()).Returns(adminRepository.All);
            userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository);
            userManager.Setup(u => u.UpdatePassword(accountManagerInRepository.Id, "Test Edited")).Returns(true).Verifiable();
            userManager.Setup(u => u.Create(accountManagerInRepository, "Test Edited")).Returns(true).Verifiable();

            var result = controller.Edit(accountManager1) as ViewResult;

            /* userManager.Verify(u => u.RemovePassword(accountManagerInRepository.Id), Times.Once);*/
            userManager.Verify(u => u.UpdatePassword(accountManagerInRepository.Id, "Test Edited"), Times.Never);
            userManager.Verify(u => u.Create(It.IsAny <InsideUser>(), "Test Edited"), Times.Once);
            Assert.AreEqual("*****@*****.**", adminRepository.All().First().Email);
        }
Exemplo n.º 3
0
        public void EditGetReturnsErrorIfAdminNotInRepository()
        {
            var adminRepository = new LocalRepository <InsideUser>();
            var userManager     = new Mock <IIdentityMembershipProvider>();

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

            var result = controller.Edit("Id1") as HttpNotFoundResult;

            Assert.AreEqual(404, result.StatusCode);
        }
Exemplo n.º 4
0
        public void EditGetReturnsErrorIfIdIsNull()
        {
            var adminRepository = new LocalRepository <InsideUser>();
            var userManager     = new Mock <IIdentityMembershipProvider>();

            adminRepository.Add(ModelHelper.TestAccountManager);
            var accountManagerInRepository = adminRepository.All().First();
            var controller = new AccountManagerController(adminRepository, userManager.Object);
            var result     = controller.Edit((string)null) as HttpStatusCodeResult;

            Assert.AreEqual(400, result.StatusCode);
        }
Exemplo n.º 5
0
        public void EditGetReturnsView()
        {
            var adminRepository            = new LocalRepository <InsideUser>();
            var userManager                = new Mock <IIdentityMembershipProvider>();
            var accountManagerInRepository = ModelHelper.TestAccountManager;

            adminRepository.Add(accountManagerInRepository);


            userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository);

            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 result = controller.Edit(accountManagerInRepository.Id) as ViewResult;

            Assert.IsTrue(controller.ModelState.Count == 0);
        }