Esempio n. 1
0
        public void TestDetailsGetReturnsViewWhenDarCompleted()
        {
            #region Arrange
            var dars = new List <DepartmentalAdminRequest>();
            dars.Add(CreateValidEntities.DepartmentalAdminRequest(1));
            dars[0].Complete = true;
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, dars, false);
            new FakeUsers(2, UserRepository);
            new FakeOrganizations(3, OrganizationRepository);
            new FakeOrganizationDescendants(3, QueryRepositoryFactory.OrganizationDescendantRepository);
            #endregion Arrange

            #region Act
            var result = Controller.Details("1")
                         .AssertViewRendered()
                         .WithViewData <DepartmentalAdminRequestViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("1", result.DepartmentalAdminRequest.Id);
            Assert.IsTrue(result.UserExists);
            Assert.IsFalse(result.UserIsAlreadyDA);
            Assert.AreEqual(0, result.ExistingOrganizations.Count());
            Assert.AreEqual(2, result.Organizations.Count());
            Assert.AreEqual("1", result.Organizations[0].Id);
            Assert.AreEqual("2", result.Organizations[1].Id);
            #endregion Assert
        }
        public void TestIndexReturnsView()
        {
            #region Arrange
            var daRequest = new List <DepartmentalAdminRequest>();
            for (int i = 0; i < 4; i++)
            {
                daRequest.Add(CreateValidEntities.DepartmentalAdminRequest(i + 1));
                daRequest[i].Complete    = false;
                daRequest[i].DateCreated = DateTime.UtcNow.ToPacificTime().Date.AddDays(-i);
            }
            daRequest[1].Complete = true;
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, daRequest, false);
            #endregion Arrange

            #region Act
            var results = Controller.Index()
                          .AssertViewRendered()
                          .WithViewData <IList <DepartmentalAdminRequest> >();
            #endregion Act

            #region Assert
            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.Count());
            Assert.AreEqual("4", results[0].Id);
            Assert.AreEqual("3", results[1].Id);
            Assert.AreEqual("1", results[2].Id);
            #endregion Assert
        }
Esempio n. 3
0
        public void TestDenyPostRedirectsWhenAlreadyCompleted()
        {
            #region Arrange
            var dars = new List <DepartmentalAdminRequest>();
            dars.Add(CreateValidEntities.DepartmentalAdminRequest(3));
            dars[0].SetIdTo("3");
            dars[0].Complete = true;
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, dars, true);
            var dar = new DepartmentalAdminRequestViewModel
            {
                DepartmentalAdminRequest = new DepartmentalAdminRequest("3")
            };
            #endregion Arrange

            #region Act
            Controller.Deny(dar)
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("Request was already completed", Controller.Message);
            DepartmentalAdminRequestRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            DepartmentalAdminRequestRepository.AssertWasNotCalled(a => a.Remove(Arg <DepartmentalAdminRequest> .Is.Anything));
            #endregion Assert
        }
Esempio n. 4
0
        public void TestDenyPostRedirectsWhenValid()
        {
            #region Arrange
            var dars = new List <DepartmentalAdminRequest>();
            dars.Add(CreateValidEntities.DepartmentalAdminRequest(3));
            dars[0].SetIdTo("3");
            dars[0].Complete = false;
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, dars, true);
            var dar = new DepartmentalAdminRequestViewModel {
                DepartmentalAdminRequest = new DepartmentalAdminRequest("3")
            };
            #endregion Arrange

            #region Act
            Controller.Deny(dar)
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("Request Denied for FirstName3 LastName3 (3)", Controller.Message);
            DepartmentalAdminRequestRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            var args = (DepartmentalAdminRequest)DepartmentalAdminRequestRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything))[0][0];
            Assert.IsTrue(args.Complete);

            DepartmentalAdminRequestRepository.AssertWasNotCalled(a => a.Remove(Arg <DepartmentalAdminRequest> .Is.Anything));
            #endregion Assert
        }
Esempio n. 5
0
        public void TestApproveThrowsExceptionIfRequestNotFound()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                new FakeDepartmentalAdminRequests(3, DepartmentalAdminRequestRepository);
                var daRequest = new DepartmentalAdminRequestViewModel();
                daRequest.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(9);
                daRequest.DepartmentalAdminRequest.SetIdTo("9");
                thisFar = true;
                #endregion Arrange

                #region Act
                Controller.Approve(daRequest, null, null);
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("Sequence contains no matching element", ex.Message);
                throw;
            }
        }
Esempio n. 6
0
        public void TestApproveWhenExistingUser3()
        {
            #region Arrange
            new FakeDepartmentalAdminRequests(9, DepartmentalAdminRequestRepository);
            var daRequest = new DepartmentalAdminRequestViewModel();
            daRequest.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(9);
            daRequest.DepartmentalAdminRequest.SetIdTo("3");
            daRequest.MergeExistingOrgs = true; //Merge Them
            new FakeOrganizations(10, OrganizationRepository);
            var users = new List <User>();
            users.Add(CreateValidEntities.User(3));
            users[0].SetIdTo("3");
            users[0].Roles.Add(RoleRepository.GetById(Role.Codes.DepartmentalAdmin));
            users[0].Organizations.Add(OrganizationRepository.Queryable.Single(a => a.Id == "1"));
            users[0].Organizations.Add(OrganizationRepository.Queryable.Single(a => a.Id == "2"));
            new FakeUsers(0, UserRepository, users, true);
            #endregion Arrange

            #region Act
            Controller.Approve(daRequest, new List <string> {
                "1", "5"
            }, new List <string> {
                "1", "2"
            })
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("FirstName3 LastName3 (3) Updated Departmental Admin Access", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(userArgs);
            Assert.AreEqual("3", userArgs.Id);
            Assert.AreEqual("FirstName3", userArgs.FirstName);
            Assert.AreEqual("LastName3", userArgs.LastName);
            Assert.AreEqual("*****@*****.**", userArgs.Email);
            Assert.AreEqual(1, userArgs.Roles.Count);
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, userArgs.Roles[0].Id);

            Assert.AreEqual(3, userArgs.Organizations.Count());
            Assert.AreEqual("1", userArgs.Organizations[0].Id);
            Assert.AreEqual("5", userArgs.Organizations[1].Id);
            Assert.AreEqual("2", userArgs.Organizations[2].Id);

            DepartmentalAdminRequestRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            var darArgs = (DepartmentalAdminRequest)DepartmentalAdminRequestRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything))[0][0];
            Assert.IsNotNull(darArgs);
            Assert.IsTrue(darArgs.Complete);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "3"));
            #endregion Assert
        }
        public void TestCreatePostRedirectsWhenValid()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            var ldap = new DirectoryUser
            {
                LoginId      = "Me",
                FirstName    = "FirstName",
                LastName     = "LastNasme",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "999 999-9999"
            };
            DirectorySearchService.Expect(a => a.FindUser("Me")).Return(ldap);
            new FakeDepartmentalAdminRequests(3, DepartmentalAdminRequestRepository);
            var departmentalAdminRequestViewModel = new DepartmentalAdminRequestViewModel();
            departmentalAdminRequestViewModel.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(1);
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.SetIdTo("Me");
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.PhoneNumber     = "333 321-1234";
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.DepartmentSize  = 1;
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.SharedOrCluster = true;
            #endregion Arrange

            #region Act
            Controller.Create(departmentalAdminRequestViewModel, new List <string> {
                "1", "3"
            })
            .AssertActionRedirect()
            .ToAction <HomeController>(a => a.Index());
            #endregion Act

            #region Assert
            Assert.AreEqual("Request created.", Controller.Message);
            DepartmentalAdminRequestRepository.AssertWasCalled(
                a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            var args =
                (DepartmentalAdminRequest)
                DepartmentalAdminRequestRepository.GetArgumentsForCallsMadeOn(
                    a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("me", args.Id);
            Assert.AreEqual("FirstName", args.FirstName);
            Assert.AreEqual("LastNasme", args.LastName);
            Assert.AreEqual("*****@*****.**", args.Email);
            Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date, args.DateCreated.Date);
            Assert.AreEqual("1,3", args.Organizations);
            Assert.AreEqual("333 321-1234", args.PhoneNumber);
            Assert.AreEqual(true, args.SharedOrCluster);
            Assert.AreEqual(1, args.DepartmentSize);
            #endregion Assert
        }
        public void TestCreatePostRetursViewWhenInvalid2()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "1");
            var ldap = new DirectoryUser
            {
                LoginId      = "Me",
                FirstName    = "FirstName",
                LastName     = "LastNasme",
                EmailAddress = null,
                //"*****@*****.**",
                PhoneNumber = "999 999-9999"
            };
            DirectorySearchService.Expect(a => a.FindUser("1")).Return(ldap);
            var dars = new List <DepartmentalAdminRequest>();
            dars.Add(CreateValidEntities.DepartmentalAdminRequest(1));
            dars[0].Organizations = "This Will Be Replaced";
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, dars, false);
            var departmentalAdminRequestViewModel = new DepartmentalAdminRequestViewModel();
            departmentalAdminRequestViewModel.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(1);
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.SetIdTo("Me");
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.PhoneNumber     = "333 321-1234";
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.DepartmentSize  = 1;
            departmentalAdminRequestViewModel.DepartmentalAdminRequest.SharedOrCluster = true;
            #endregion Arrange

            #region Act
            var results = Controller.Create(departmentalAdminRequestViewModel, new List <string> {
                "1", "3"
            })
                          .AssertViewRendered()
                          .WithViewData <DepartmentalAdminRequestViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(results);
            Controller.ModelState.AssertErrorsAre("The Email field is required.");
            Assert.AreEqual("There were Errors, please correct and try again.", Controller.ErrorMessage);
            Assert.AreEqual("1", results.DepartmentalAdminRequest.Id);
            Assert.AreEqual("FirstName", results.DepartmentalAdminRequest.FirstName);
            Assert.AreEqual("LastNasme", results.DepartmentalAdminRequest.LastName);
            Assert.AreEqual(null, results.DepartmentalAdminRequest.Email);
            Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date, results.DepartmentalAdminRequest.DateCreated.Date);
            Assert.AreEqual("1,3", results.DepartmentalAdminRequest.Organizations);
            Assert.AreEqual("333 321-1234", results.DepartmentalAdminRequest.PhoneNumber);
            Assert.AreEqual(true, results.DepartmentalAdminRequest.SharedOrCluster);
            Assert.AreEqual(1, results.DepartmentalAdminRequest.DepartmentSize);
            DepartmentalAdminRequestRepository.AssertWasCalled(a => a.GetNullableById("1"));
            #endregion Assert
        }
Esempio n. 9
0
        public void TestDenyGetRedirectsWhenDarCompleted()
        {
            #region Arrange
            var dars = new List <DepartmentalAdminRequest>();
            dars.Add(CreateValidEntities.DepartmentalAdminRequest(1));
            dars[0].Complete = true;
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, dars, false);
            #endregion Arrange

            #region Act
            Controller.Deny("1")
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("Request was already completed", Controller.Message);
            #endregion Assert
        }
        public void TestCreateGetReturnsView2()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            var ldap = new DirectoryUser
            {
                LoginId      = "Me",
                FirstName    = "FirstName",
                LastName     = "LastNasme",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "999 999-9999"
            };
            DirectorySearchService.Expect(a => a.FindUser("Me")).Return(ldap);

            var daRequests = new List <DepartmentalAdminRequest>();
            daRequests.Add(CreateValidEntities.DepartmentalAdminRequest(1));
            daRequests[0].SetIdTo("Me");
            daRequests[0].Organizations = "1,2";
            new FakeDepartmentalAdminRequests(0, DepartmentalAdminRequestRepository, daRequests, true);
            new FakeOrganizations(2, OrganizationRepository);
            #endregion Arrange

            #region Act
            var result = Controller.Create()
                         .AssertViewRendered()
                         .WithViewData <DepartmentalAdminRequestViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.DepartmentalAdminRequest);
            Assert.IsNull(result.ExistingOrganizations);
            Assert.AreEqual("Me", result.DepartmentalAdminRequest.Id);
            Assert.AreEqual("FirstName", result.DepartmentalAdminRequest.FirstName);
            Assert.AreEqual("LastNasme", result.DepartmentalAdminRequest.LastName);
            Assert.AreEqual("*****@*****.**", result.DepartmentalAdminRequest.Email);
            Assert.AreEqual("999 999-9999", result.DepartmentalAdminRequest.PhoneNumber);
            Assert.AreEqual("1,2", result.DepartmentalAdminRequest.Organizations);
            #endregion Assert
        }
Esempio n. 11
0
        public void TestApproveWhenNewUser()
        {
            #region Arrange
            new FakeDepartmentalAdminRequests(9, DepartmentalAdminRequestRepository);
            var daRequest = new DepartmentalAdminRequestViewModel();
            daRequest.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(9);
            daRequest.DepartmentalAdminRequest.SetIdTo("9");
            new FakeUsers(3, UserRepository);
            new FakeOrganizations(10, OrganizationRepository);
            #endregion Arrange

            #region Act
            Controller.Approve(daRequest, new List <string> {
                "1", "5"
            }, null)
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("FirstName9 LastName9 (9) Granted Departmental Admin Access", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(userArgs);
            Assert.AreEqual("9", userArgs.Id);
            Assert.AreEqual("FirstName9", userArgs.FirstName);
            Assert.AreEqual("LastName9", userArgs.LastName);
            Assert.AreEqual("*****@*****.**", userArgs.Email);
            Assert.AreEqual(1, userArgs.Roles.Count);
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, userArgs.Roles[0].Id);

            DepartmentalAdminRequestRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            var darArgs = (DepartmentalAdminRequest)DepartmentalAdminRequestRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything))[0][0];
            Assert.IsNotNull(darArgs);
            Assert.IsTrue(darArgs.Complete);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "9"));
            #endregion Assert
        }
Esempio n. 12
0
        public void TestApprovePostRedirectsIfNoOrgsSelected2()
        {
            #region Arrange
            new FakeDepartmentalAdminRequests(3, DepartmentalAdminRequestRepository);
            var daRequest = new DepartmentalAdminRequestViewModel();
            daRequest.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(9);
            daRequest.DepartmentalAdminRequest.SetIdTo("3");
            #endregion Arrange

            #region Act
            var result = Controller.Approve(daRequest, new List <string>(), new List <string> {
                "1", "2"
            })
                         .AssertActionRedirect()
                         .ToAction <DepartmentalAdminRequestController>(a => a.Approve("3"));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("3", result.RouteValues["id"]);
            Assert.AreEqual("Must select at least one organization", Controller.ErrorMessage);
            #endregion Assert
        }
 /// <summary>
 /// Gets the valid entity of type T
 /// </summary>
 /// <param name="counter">The counter.</param>
 /// <returns>A valid entity of type T</returns>
 protected override DepartmentalAdminRequest GetValid(int?counter)
 {
     return(CreateValidEntities.DepartmentalAdminRequest(counter));
 }