Example #1
0
        public void GivenUserHasProviderAssociations_AndUserHasSchoolAssociations_WhenIExecuteDataSelector_ThenAssociationsIsSumOfSchoolAssociationCountAndProviderAssociationCount()
        {
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            var schools = new List <School> {
                new School(), new School()
            };
            var providers = new List <Provider> {
                new Provider(), new Provider(), new Provider()
            };
            User user = new User
            {
                UserRoles = new List <UserRole>
                {
                    new UserRole
                    {
                        Role      = new Role(),
                        Schools   = schools,
                        Providers = providers
                    }
                }
            };

            SecurityConfiguration.Expect(m => m.AdministratorEmailAddresses).Return(new string[] { "*****@*****.**" });

            dynamic actual = target.DataSelector.Compile().Invoke(user);

            Assert.AreEqual(schools.Count + providers.Count, actual.Associations);
        }
Example #2
0
        public void GivenStatusFilterCriteria_AndUserDoesntHaveStatus_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            User user = new User {
                Active = true
            };

            MockRequest.Expect(m => m["status"]).Return("Inactive");
            var target = new UserClientDataTable(MockRequest, SecurityConfiguration);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(user));
        }
Example #3
0
        public void GivenEmailSearchCriteria_AndUserEmailDoesntPartiallyMatch_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            User user = new User {
                EmailAddress = "*****@*****.**"
            };

            MockRequest.Expect(m => m["email"]).Return("xyz");
            var target = new UserClientDataTable(MockRequest, SecurityConfiguration);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(user));
        }
Example #4
0
        public void GivenLastNameSearchCriteria_AndUserNameDoesntPartiallyMatch_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            User user = new User {
                LastName = "Deitz"
            };

            MockRequest.Expect(m => m["lastName"]).Return("xyz");
            var target = new UserClientDataTable(MockRequest, SecurityConfiguration);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(user));
        }
Example #5
0
        public void GivenFirstNameSearchCriteria_AndUserNamePartiallyMatches_WhenInvokeFilterPredicate_ThenReturnTrue()
        {
            User user = new User {
                FirstName = "Alec"
            };

            MockRequest.Expect(m => m["firstName"]).Return("Ale");
            var target = new UserClientDataTable(MockRequest, SecurityConfiguration);

            Assert.IsTrue(target.FilterPredicate.Compile().Invoke(user));
        }
Example #6
0
        public void GivenUserIsNotConfiguredAsAdministrator_WhenIExecuteDataSelector_ThenDataRolesDoesNotContainAdministrator()
        {
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User {
                EmailAddress = "*****@*****.**"
            };

            SecurityConfiguration.Expect(m => m.AdministratorEmailAddresses).Return(new string[] { "*****@*****.**" });

            dynamic actual = target.DataSelector.Compile().Invoke(user);

            Assert.IsFalse(((IEnumerable <string>)actual.Roles).Contains(SecurityRoles.Administrator));
        }
Example #7
0
        public void GivenUserIsConfiguredAsAdministrator_WhenIExecuteDataSelector_ThenDataRolesIsAdministrator()
        {
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User {
                EmailAddress = "*****@*****.**"
            };

            SecurityConfiguration.Expect(m => m.AdministratorEmailAddresses).Return(new string[] { user.EmailAddress });

            dynamic actual = target.DataSelector.Compile().Invoke(user);

            Assert.AreEqual(SecurityRoles.Administrator, ((IEnumerable <string>)actual.Roles).Single());
        }
Example #8
0
        public void GivenSortDirectionOnFirstName_WhenExecuteSortSelector_ThenReturnFirstName()
        {
            MockRequest.Expect(m => m["iSortCol_0"]).Return("2");
            MockRequest.Expect(m => m["sSortDir_0"]).Return("asc");
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User {
                FirstName = "Alec"
            };

            var actual = target.SortSelector.Compile().Invoke(user);

            Assert.AreEqual("Alec", actual);
        }
Example #9
0
        public void GivenSortDirectionOnStatus_WhenExecuteSortSelector_ThenReturnStatus()
        {
            MockRequest.Expect(m => m["iSortCol_0"]).Return("0");
            MockRequest.Expect(m => m["sSortDir_0"]).Return("asc");
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User {
                Active = false
            };

            var actual = target.SortSelector.Compile().Invoke(user);

            Assert.AreEqual("Inactive", actual);
        }
Example #10
0
        public void GivenSchoolsFilterCriteria_AndUserIsNotAssociatedToSchool_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            User user = new User {
                UserRoles = new List <UserRole> {
                    new UserRole {
                        Schools = new List <School> {
                            TestData.Schools[1]
                        }
                    }
                }
            };

            MockRequest.Expect(m => m["schools"]).Return(TestData.Schools[0].Name);
            var target = new UserClientDataTable(MockRequest, SecurityConfiguration);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(user));
        }
Example #11
0
        public void GivenRoleFilterCriteria_AndUserDoesntHaveRole_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            User user = new User {
                UserRoles = new List <UserRole> {
                    new UserRole {
                        Role = new Role {
                            Name = SecurityRoles.SiteCoordinator
                        }
                    }
                }
            };

            MockRequest.Expect(m => m["roles"]).Return("Data Admin");
            var target = new UserClientDataTable(MockRequest, SecurityConfiguration);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(user));
        }
Example #12
0
        public void GivenUserHasLoginEvents_WhenIExecuteDataSelector_ThenDataHasLastLoginTime()
        {
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User
            {
                LoginEvents = new List <LoginEvent>
                {
                    new LoginEvent {
                        CreateTime = DateTime.Now
                    }
                }
            };

            SecurityConfiguration.Expect(m => m.AdministratorEmailAddresses).Return(new string[] { user.EmailAddress });

            dynamic actual = target.DataSelector.Compile().Invoke(user);

            Assert.AreEqual(user.LastLoginTime, actual.LastLoginTime);
        }
Example #13
0
        public void GivenSortDirectionOnLastLoginTime_WhenExecuteSortSelector_ThenReturnLastLoginTimeInMinutes()
        {
            MockRequest.Expect(m => m["iSortCol_0"]).Return("3");
            MockRequest.Expect(m => m["sSortDir_0"]).Return("asc");
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User
            {
                LoginEvents = new List <LoginEvent>
                {
                    new LoginEvent {
                        CreateTime = DateTime.Now
                    }
                }
            };
            string expected = ((int)new TimeSpan(user.LastLoginTime.Value.Ticks).TotalMinutes).ToString();

            var actual = target.SortSelector.Compile().Invoke(user);

            Assert.AreEqual(expected, actual);
        }
Example #14
0
        public void GivenUserHasProviderAssociations_AndSortOnAssociationCount_WhenExecuteSortSelector_ThenReturnProviderAssociationCount()
        {
            MockRequest.Expect(m => m["iSortCol_0"]).Return("4");
            MockRequest.Expect(m => m["sSortDir_0"]).Return("asc");
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User
            {
                UserRoles = new List <UserRole>
                {
                    new UserRole {
                        Providers = new List <Provider> {
                            new Provider(), new Provider(), new Provider()
                        }
                    }
                }
            };

            var actual = target.SortSelector.Compile().Invoke(user);

            Assert.AreEqual("3", actual);
        }
Example #15
0
        public void GivenUserIsConfiguredAsAdministrator_AndHasDataAdminRole_WhenIExecuteDataSelector_ThenDataRolesContainsAdministratorAndDataAdmin()
        {
            UserClientDataTable target = new UserClientDataTable(MockRequest, SecurityConfiguration);
            User user = new User
            {
                EmailAddress = "*****@*****.**",
                UserRoles    = new List <UserRole>
                {
                    new UserRole {
                        Role = new Role {
                            Name = SecurityRoles.DataAdmin
                        }
                    }
                }
            };

            string[] expected = new[] { "Administrator", SecurityRoles.DataAdmin };
            SecurityConfiguration.Expect(m => m.AdministratorEmailAddresses).Return(new string[] { user.EmailAddress });

            dynamic actual = target.DataSelector.Compile().Invoke(user);

            CollectionAssert.AreEqual(expected, ((IEnumerable <string>)actual.Roles).ToList());
        }