public void GivenModelWithBirthDateIncluded_AndParentNameIncluded_AndSelectedCustomFields_AndSelectedServiceTypes_AndPermissionGrantsCustomFieldOnly_WhenMapData_ThenResultContainsOnlyDirectoryLevelData()
        {
            Student       student  = TestData.Students[0];
            List <object> expected = new List <object> {
                student.School.Name, student.Grade, student.FullName, null, null, student.CustomFieldValues.First().Value, student.CustomFieldValues.Last().Value
            };
            var model = new StudentProfileExportFieldDescriptor
            {
                BirthDateIncluded    = true,
                ParentNameIncluded   = true,
                SelectedCustomFields = new List <CustomField> {
                    TestData.CustomFields[0], TestData.CustomFields[2]
                },
                SelectedServiceTypes = new List <ServiceType> {
                    TestData.ServiceTypes[1]
                }
            };
            IViewStudentDetailPermission permission = MockRepository.GenerateMock <IViewStudentDetailPermission>();

            permission.Expect(p => p.CustomFieldOnly).Return(true);
            PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(permission);

            var actual = Target.MapData(model, student, User, MockUserAuditor);

            CollectionAssert.AreEqual(expected, actual.ToList());
        }
        public void GivenValidStudentId_AndPermissionCustomFieldOnlyTrue_WhenGenerateStudentDetailViewModel_ThenViewModelContainsOnlyCustomFieldValuesByUser_AndViewModelOnlyUploadedCustomFieldSetTrue()
        {
            IViewStudentDetailPermission permission = MockRepository.GenerateMock <IViewStudentDetailPermission>();

            permission.Expect(p => p.CustomFieldOnly).Return(true);
            PermissionFactory.Current.Expect(m => m.Create("ViewStudentDetail", Data.Students.Single(s => s.Id == 1))).Return(permission);
            User.Identity.User.Id = 1;
            var expected = Data.CustomFieldValues.Where(c => c.CustomDataOrigin.CreatingUserId == 1 && c.StudentId == 1);

            var actual = Target.GenerateStudentDetailViewModel(User, 1);

            Assert.IsTrue(actual.OnlyUploadedCustomField);
            Assert.IsTrue(actual.CustomData.Count() > 0);
            CollectionAssert.AreEquivalent(expected.Select(e => e.CustomField.Name).ToList(), actual.CustomData.Select(c => c.FieldName).ToList());
        }
        public void GivenValidStudentId_AndPermissionCustomFieldOnlyTrue_WhenGenerateStudentDetailViewModel_ThenViewModelDoesNotContainPrivateStudentData()
        {
            IViewStudentDetailPermission permission = MockRepository.GenerateMock <IViewStudentDetailPermission>();

            permission.Expect(p => p.CustomFieldOnly).Return(true);
            PermissionFactory.Current.Expect(m => m.Create("ViewStudentDetail", Data.Students.Single(s => s.Id == 1))).Return(permission);
            User.Identity.User.Id = 1;

            var actual = Target.GenerateStudentDetailViewModel(User, 1);

            Assert.IsFalse(actual.DateOfBirth.HasValue);
            Assert.IsNull(actual.Parents);
            Assert.IsTrue(actual.ServiceRequests.Count() == 0);
            Assert.IsTrue(actual.StudentAssignedOfferings.Count() == 0);
            Assert.IsTrue(actual.Classes.Count() == 0);
        }
        public void GivenPermissionDoesNotGrantAccess_WhenMapData_ThenOnlyDirectoryLevelInformationReturned()
        {
            Student       student  = TestData.Students[0];
            List <object> expected = new List <object> {
                student.School.Name, student.Grade, student.FullName
            };
            var model = new StudentProfileExportFieldDescriptor {
                SelectedServiceTypes = new List <ServiceType> {
                    TestData.ServiceTypes[1]
                }
            };
            IViewStudentDetailPermission permission = MockRepository.GenerateMock <IViewStudentDetailPermission>();

            permission.Expect(p => p.GrantAccess(User)).Throw(new EntityAccessUnauthorizedException());
            PermissionFactory.Current.Expect(m => m.Create("StudentProfileExportMapData", student)).Return(permission);

            var actual = Target.MapData(model, student, User, MockUserAuditor);

            CollectionAssert.AreEqual(expected, actual.ToList());
        }