public void TestCreateGetReturnsView1()
        {
            #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);
            #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.IsNull(result.DepartmentalAdminRequest.Organizations);
            #endregion Assert
        }
        public void TestCreatePostRequiresLdapLookup()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
                DirectorySearchService.Expect(a => a.FindUser("Me")).Return(null);
                thisFar = true;
                #endregion Arrange

                #region Act
                Controller.Create(new DepartmentalAdminRequestViewModel(), new List <string> {
                    "1", "2"
                });
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("Person requesting Departmental Access ID not found. ID = Me", ex.Message);
                throw;
            }
        }
コード例 #3
0
        public void TestWhenAlreadyExists()
        {
            #region Arrange
            var idValue       = "2";
            var directoryUser = new DirectoryUser();
            directoryUser.FirstName    = "Jimmy";
            directoryUser.LastName     = "James";
            directoryUser.EmailAddress = "*****@*****.**";
            DirectorySearchService.Expect(a => a.FindUser("2")).Return(directoryUser);
            new FakeDepartmentalAdminRequests(3, DepartmentalAdminRequestRepository);

            #endregion Arrange

            #region Act
            Controller.TookTraining(idValue);
            #endregion Act

            #region Assert
            Assert.AreEqual("Request created/Updated.", 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.AreEqual("2", args.Id);
            Assert.IsTrue(args.AttendedTraining);
            Assert.AreEqual("*****@*****.**", args.Email);
            Assert.AreEqual("Jimmy", args.FirstName);
            Assert.AreEqual("James", args.LastName);
            #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
        }
コード例 #6
0
        public void TestFindUser1()
        {
            #region Arrange
            const string searchTerm = "TestValue";
            DirectorySearchService.Expect(a => a.FindUser(searchTerm)).Return(null).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = Controller.FindUser(searchTerm)
                         .AssertResultIs <JsonResult>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsNull(result.Data);
            Assert.AreEqual(JsonRequestBehavior.AllowGet, result.JsonRequestBehavior);
            DirectorySearchService.AssertWasCalled(a => a.FindUser(searchTerm));
            #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
        }
コード例 #8
0
        public void TestFindUser2()
        {
            #region Arrange
            const string searchTerm = "TestValue";
            AutomapperConfig.Configure();
            var directoryUser = new DirectoryUser();
            directoryUser.EmailAddress = "*****@*****.**";
            directoryUser.EmployeeId   = "EmployeeId";
            directoryUser.FirstName    = "FirstName";
            directoryUser.LastName     = "LastName";
            directoryUser.FullName     = "FullName";
            directoryUser.LoginId      = "LoginId";
            directoryUser.PhoneNumber  = "1 555 555 5555";

            DirectorySearchService.Expect(a => a.FindUser(searchTerm)).Return(directoryUser).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = Controller.FindUser(searchTerm)
                         .AssertResultIs <JsonResult>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            var result2 = (ServiceUser)result.Data;
            Assert.IsNotNull(result2);
            Assert.AreEqual("*****@*****.**", result2.Email);
            Assert.AreEqual("FirstName", result2.FirstName);
            Assert.IsNull(result2.FullNameAndLogin);
            Assert.AreEqual("LastName", result2.LastName);
            Assert.AreEqual("LoginId", result2.Login);
            Assert.AreEqual("1 555 555 5555", result2.Phone);
            Assert.IsNull(result2.Roles);
            Assert.IsNull(result2.Units);

            Assert.AreEqual(JsonRequestBehavior.AllowGet, result.JsonRequestBehavior);
            DirectorySearchService.AssertWasCalled(a => a.FindUser(searchTerm));
            #endregion Assert
        }