Пример #1
0
        public void TestModifyDepartmentalSetsExpectedValues4()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            var roles = new List <Role>();
            roles.Add(CreateValidEntities.Role(99));
            roles[0].SetIdTo(Role.Codes.DepartmentalAdmin);
            roles.Add(CreateValidEntities.Role(88));
            roles[1].SetIdTo(Role.Codes.Admin);
            roles.Add(CreateValidEntities.Role(77));
            roles[2].SetIdTo(Role.Codes.EmulationUser);
            new FakeRoles(0, RoleRepository, roles, true);

            var users = new List <User>();
            users.Add(CreateValidEntities.User(3));
            users[0].Roles.Add(RoleRepository.Queryable.Single(a => a.Id == Role.Codes.EmulationUser));
            users[0].SetIdTo("3");
            new FakeUsers(0, UserRepository, users, true);
            new FakeOrganizations(6, OrganizationRepository);



            var depUser = new DepartmentalAdminModel();
            depUser.User          = UserRepository.Queryable.Single(a => a.Id == "3");
            depUser.User.LastName = "Changed";
            depUser.User.Organizations.Add(OrganizationRepository.Queryable.Single(a => a.Id == "1"));

            var orgs = new List <string> {
                "2", "4"
            };
            #endregion Arrange

            #region Act
            Controller.ModifyDepartmental(depUser, orgs)
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var args = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(Role.Codes.EmulationUser, args.Roles[0].Id);
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, args.Roles[1].Id);

            Assert.AreEqual("FirstName3 Changed (3) was added as a departmental admin to the specified organization(s)", Controller.Message);
            #endregion Assert
        }
Пример #2
0
        public void TestModifyDepartmentalSetsExpectedValues1()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            new FakeUsers(3, UserRepository);
            new FakeOrganizations(6, OrganizationRepository);

            var roles = new List <Role>();
            roles.Add(CreateValidEntities.Role(99));
            roles[0].SetIdTo(Role.Codes.DepartmentalAdmin);
            new FakeRoles(0, RoleRepository, roles, true);

            var depUser = new DepartmentalAdminModel();
            depUser.User = CreateValidEntities.User(4);
            var orgs = new List <string> {
                "2", "4"
            };
            #endregion Arrange

            #region Act
            Controller.ModifyDepartmental(depUser, orgs)
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var args = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("4", args.Id);
            Assert.AreEqual("FirstName4 LastName4", args.FullName);
            Assert.AreEqual("*****@*****.**", args.Email);
            Assert.IsTrue(args.IsActive);
            Assert.AreEqual(1, args.Roles.Count());
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, args.Roles[0].Id);
            Assert.AreEqual(2, args.Organizations.Count());
            Assert.AreEqual("2", args.Organizations[0].Id);
            Assert.AreEqual("4", args.Organizations[1].Id);

            Assert.AreEqual("FirstName4 LastName4 (4) was added as a departmental admin to the specified organization(s)", Controller.Message);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "4"));
            #endregion Assert
        }
Пример #3
0
        public void TestModifyDepartmentalWhenOrgThanDoesNotExist()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                new FakeUsers(3, UserRepository);
                new FakeOrganizations(6, OrganizationRepository);

                var roles = new List <Role>();
                roles.Add(CreateValidEntities.Role(99));
                roles[0].SetIdTo(Role.Codes.DepartmentalAdmin);
                new FakeRoles(0, RoleRepository, roles, true);

                var depUser = new DepartmentalAdminModel();
                depUser.User          = UserRepository.Queryable.Single(a => a.Id == "3");
                depUser.User.LastName = "Changed";
                depUser.User.Organizations.Add(OrganizationRepository.Queryable.Single(a => a.Id == "1"));

                var orgs = new List <string> {
                    "2", "7"
                };
                thisFar = true;
                #endregion Arrange

                #region Act
                Controller.ModifyDepartmental(depUser, orgs);
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("Sequence contains no matching element", ex.Message);
                throw;
            }
        }