public void GivenStudentEntity_AndSomePrivateHealthFields_WhenCopyFrom_ThenCustomFieldsSet()
        {
            Student entity = new Student
            {
                Id = 1,
                StudentKey = "2",
                StudentSISId = "3",
                School = new School(),
                CustomFieldValues = new List<CustomFieldValue>
                {
                    new CustomFieldValue
                    {
                        CustomDataOrigin = new CustomDataOrigin { Source = "College Board" },
                        CustomField = new PublicField { Name = "ACT" },
                        Value = "27"
                    },
                    new CustomFieldValue
                    {
                        CustomDataOrigin = new CustomDataOrigin { Source = "HULK" },
                        CustomField = new PrivateHealthField { Name = "PHI" },
                        Value = "1234"
                    }
                }
            };

            Target.CopyFrom(entity);

            Assert.AreEqual(1, Target.CustomData.Count());
            Assert.AreEqual(1, Target.CustomPrivateData.Count());
        }
 private bool IsValidServiceOffering(EducationSecurityPrincipal user, int index, string studentSISId, Student student, DataTable dataTable, out DateTime? startDate, out DateTime? endDate, ServiceUploadModel model)
 {
     startDate = endDate = null;
     if (studentSISId == null || student == null)
     {
         ProcessError(dataTable.Rows[index], string.Format(CultureInfo.CurrentCulture, "Malformed Student Id on row {0}", index + 1), model);
         return false;
     }
     else if (!GrantUserAccessToSchedulingAnOffering(user, student))
     {
         ProcessError(dataTable.Rows[index], string.Format(CultureInfo.CurrentCulture, "You do not have permission to interact with the referenced student on row {0}", index + 1), model);
         return false;
     }
     else if (!ExcelUtility.TryGetOADate(dataTable.Rows[index][2].ToString(), out startDate))
     {
         ProcessError(dataTable.Rows[index], string.Format(CultureInfo.CurrentCulture, "Malformed Start Date on row {0}", index + 1), model);
         return false;
     }
     else if (!ExcelUtility.TryGetOADate(dataTable.Rows[index][3].ToString(), out endDate))
     {
         ProcessError(dataTable.Rows[index], string.Format(CultureInfo.CurrentCulture, "Malformed End Date on row {0}", index + 1), model);
         return false;
     }
     return true;
 }
        public void GivenStudentEntity_WhenCopyFrom_ThenIdIsSet()
        {
            Student entity = new Student { Id = 1, StudentKey = "2", StudentSISId = "3", School = new School() };

            Target.CopyFrom(entity);

            Assert.AreEqual(1, Target.Id);
        }
        public void GivenAStudent_WhenUpdate_ThenContextSetsModified()
        {
            var expected = new Student { Id = 1 };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
 public ManageCustomFieldPermission(Student student)
 {
     if (student == null)
     {
         throw new ArgumentNullException("student");
     }
     Student = student;
 }
 public ViewStudentDetailPermission(Student student)
 {
     if (student == null)
     {
         throw new ArgumentNullException("student");
     }
     Student = student;
 }
        public void GivenNoFilterParameters_AndUserIsNotDataAdmin_AndUserHasNoSchoolAssociationWithStudent_WhenIFilter_ThenStudentIsTaken()
        {
            Student student = new Student { SchoolId = 3 };
            PrepareDataTableRequestParameters("0", "asc", null, null, null, null, null, null, null, null, null);
            Target = new StudentClientDataTable(MockContext.Request, CreateUser(false), StudentProperties);

            Assert.IsTrue(Target.FilterPredicate.Compile().Invoke(student));
        }
        public void GivenFirstNameFilter_AndStudentDoesNotMatch_WhenExecuteFilterPredicate_ThenReturnFalse()
        {
            Student toFilter = new Student { FirstName = "abcd" };
            MockRequest.Expect(m => m["firstName"]).Return("de");
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(toFilter));
        }
        public void GivenFirstNameFilter_AndStudentMatches_WhenExecuteFilterPredicate_ThenReturnTrue()
        {
            Student toFilter = new Student { FirstName = "abcd", School = new School() };
            MockRequest.Expect(m => m["firstName"]).Return("bc");
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

            Assert.IsTrue(target.FilterPredicate.Compile().Invoke(toFilter));
        }
        public void GivenIDFilter_AndStudentDoesNotMatch_WhenExecuteFilterPredicate_ThenReturnFalse()
        {
            Student toFilter = new Student { StudentSISId = "1234" };
            MockRequest.Expect(m => m["ID"]).Return("45");
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(toFilter));
        }
        public void GivenIDFilter_AndStudentMatches_WhenExecuteFilterPredicate_ThenReturnTrue()
        {
            Student toFilter = new Student { StudentSISId = "1234", School = new School() };
            MockRequest.Expect(m => m["ID"]).Return("23");
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

            Assert.IsTrue(target.FilterPredicate.Compile().Invoke(toFilter));
        }
        public void GivenAnUnassociatedStudentAndProvider_WhenAddLink_ThenTheyAreAssociated()
        {
            Student student = new Student();
            Provider provider = new Provider();

            Target.AddLink(student, provider);

            CollectionAssert.Contains(student.ApprovedProviders.ToList(), provider);
            CollectionAssert.Contains(provider.ApprovingStudents.ToList(), student);
        }
        public void GivenAnAssociatedStudentAndProvider_WhenDeleteLink_ThenTheyAreNoLongerAssociated()
        {
            Student student = new Student();
            Provider provider = new Provider { ApprovingStudents = new List<Student> { student } };
            student.ApprovedProviders.Add(provider);

            Target.DeleteLink(student, provider);

            CollectionAssert.DoesNotContain(student.ApprovedProviders.ToList(), provider);
            CollectionAssert.DoesNotContain(provider.ApprovingStudents.ToList(), student);
        }
 public void DeleteLink(Student student, Provider provider)
 {
     if (student == null)
     {
         throw new ArgumentNullException("student");
     }
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     student.ApprovedProviders.Remove(provider);
     provider.ApprovingStudents.Remove(student);
 }
 private void CreateNewStudentAssignedOffering(Student student, ServiceUploadModel model, DateTime? startDate, DateTime? endDate, string notes, EducationSecurityPrincipal user)
 {
     var newOffering = new StudentAssignedOffering()
     {
         StudentId = student.Id,
         CreatingUser = user.Identity.User,
         ServiceOfferingId = model.ServiceOfferingId,
         StartDate = startDate,
         EndDate = endDate,
         Notes = notes,
         IsActive = true
     };
     StudentAssignedOfferingRepository.Add(newOffering);
 }
 public IEnumerable<object> MapData(StudentProfileExportFieldDescriptor fieldConfiguration, Student data, EducationSecurityPrincipal user, IUserAuditor auditor)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     if (auditor == null)
     {
         throw new ArgumentNullException("auditor");
     }
     List<object> dataList = new List<object> { data.School.Name, data.Grade, data.FullName };
     IViewStudentDetailPermission permission = (IViewStudentDetailPermission)PermissionFactory.Current.Create("StudentProfileExportMapData", data);
     if(permission.TryGrantAccess(user))
     {
         if (!permission.CustomFieldOnly)
         {
             dataList.Add(data.StudentSISId);
         }
         MapStandardData(fieldConfiguration, data, dataList, permission.CustomFieldOnly);
         dataList.AddRange(fieldConfiguration.SelectedCustomFields.Select(f => FindLatestValue(data, f)).Select(v => v == null ? string.Empty : v.Value));
         var fields = fieldConfiguration.SelectedCustomFields.Select(f => FindLatestValue(data, f));
         if (fields.Where(f => f != null).ToList().Count() > 0)
         {
             user.Identity.User.PrivateHealthDataViewEvents.Add(auditor.CreatePrivateHealthInfoViewEvent(user.Identity.User, fields.Where(f => f != null).ToList()));
         }
         if (!permission.CustomFieldOnly)
         {
             dataList.AddRange(fieldConfiguration.SelectedServiceTypes.Select(serviceType => FindServicesOfferingNames(data, serviceType)));
         }
     }
     return dataList;
 }
 private void AttemptRowReadOfUploadWizardFile(int studentIdColumn, UploadWizardCompleteModel model, CustomDataOrigin origin, Dictionary<int, CustomField> customFieldsDicitonary, int numColumns, int rowNum, DataRow row, Student student)
 {
     var successfulRow = true;
     int nonIdColumns = 0;
     List<CustomFieldValue> rowCustomFieldValues = new List<CustomFieldValue>();
     for (int i = 0; i < numColumns; i++)
     {
         if (i != studentIdColumn)
         {
             ProcessRowCell(model, origin, customFieldsDicitonary, rowNum, row, student, ref successfulRow, ref nonIdColumns, rowCustomFieldValues, i);
         }
     }
     if (nonIdColumns == 0)
     {
         successfulRow = false;
         ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Row {0} requires an additional field to Id", rowNum + 2), model);
     }
     if (successfulRow)
     {
         model.SuccessfulRowsCount++;
         foreach (var value in rowCustomFieldValues)
         {
             CustomFieldValueRepository.Add(value);
         }
     }
 }
 private static CustomFieldValue FindLatestValue(Student data, CustomField field)
 {
     return data.CustomFieldValues.Where(v => field == v.CustomField).OrderByDescending(v => v.CustomDataOrigin.CreateTime).FirstOrDefault();
 }
        public void GivenStudent_WhenExecuteDataSelctor_ThenDataContainsStudentProperties()
        {
            Student expectedState = new Student
            {
                Id = 1877,
                FirstName = "Bob",
                MiddleName = "Allan",
                LastName = "Smith",
                HasParentalOptOut = true,
                Grade = 7,
                School = new School { Name = "Random High School" },
                StudentSISId = "3823282"
            };
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

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

            Assert.AreEqual(expectedState.Id, actual.Id);
            Assert.AreEqual(expectedState.FullName, actual.Name);
            Assert.AreEqual(expectedState.HasParentalOptOut, actual.HasParentalOptOut);
            Assert.AreEqual(expectedState.Grade, actual.Grade);
            Assert.AreEqual(expectedState.School.Name, actual.School);
            Assert.AreEqual(expectedState.StudentSISId, actual.StudentSISId);
        }
 private static List<string> FindServicesOfferingNames(Student data, ServiceType serviceType)
 {
     return data.StudentAssignedOfferings.
         Where(s => s.ServiceOffering.ServiceType == serviceType && s.IsActive).
         Select(o => o.ServiceOffering.Name).ToList();
 }
        public void GivenStudent_AndStudentHasApprovedProviders_WhenExecuteDataSelctor_ThenDataContainsApprovedProviderDetail()
        {
            List<Provider> expectedState = new List<Provider> { new Provider { Id = 382, Name = "Blah1", IsActive = true }, new Provider { Id = 289, Name = "Grapejuice", IsActive = true } };
            Student student = new Student
            {
                School = new School(),
                ApprovedProviders = expectedState
            };
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

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

            int i = 0;
            foreach (dynamic actualProvider in actual.ApprovedProviders)
            {
                Assert.AreEqual(expectedState[i].Id, actualProvider.Id);
                Assert.AreEqual(expectedState[i].Name, actualProvider.Name);
                i++;
            }
            Assert.AreEqual(expectedState.Count, i);
        }
        public void GivenStudent_AndStudentHasApprovedProviders_AndSomeProvidersAreInactive_WhenExecuteDataSelctor_ThenDataContainsActiveApprovedProviderDetail()
        {
            Provider expectedState = new Provider { Id = 382, Name = "Blah1", IsActive = true };
            Student student = new Student
            {
                School = new School(),
                ApprovedProviders = new List<Provider> { expectedState, new Provider { Id = 289, Name = "Grapejuice" } }
            };
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

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

            dynamic actualApprovedProvider = ((IEnumerable<object>)actual.ApprovedProviders).Single();
            Assert.AreEqual(expectedState.Id, actualApprovedProvider.Id);
            Assert.AreEqual(expectedState.Name, actualApprovedProvider.Name);
        }
        public void GivenSchoolFilterList_AndStudentSchoolMatches_WhenExecuteFilterPredicate_ThenReturnTrue()
        {
            Student toFilter = new Student { School = new School { Name = "def" } };
            MockRequest.Expect(m => m["schools"]).Return("abc|def|ghi");
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

            Assert.IsTrue(target.FilterPredicate.Compile().Invoke(toFilter));
        }
        public void GivenProviderFilterList_AndStudentSchoolDoesNotMatch_WhenExecuteFilterPredicate_ThenReturnFalse()
        {
            Student toFilter = new Student { ApprovedProviders = new List<Provider> { new Provider { Name = "jkl" } }, School = new School() };
            MockRequest.Expect(m => m["providers"]).Return("abc|def|ghi");
            StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest);

            Assert.IsFalse(target.FilterPredicate.Compile().Invoke(toFilter));
        }
 private static void MapStandardData(StudentProfileExportFieldDescriptor fieldConfiguration, Student data, List<object> dataList, bool directoryLevelOnly)
 {
     if (fieldConfiguration.BirthDateIncluded)
     {
         dataList.Add(directoryLevelOnly ? null : data.DateOfBirth);
     }
     if (fieldConfiguration.ParentNameIncluded)
     {
         dataList.Add(directoryLevelOnly ? null : data.Parents);
     }
 }
 private static void AssertViewModel(Student expectedState, StudentDetailModel actual)
 {
     Assert.AreEqual(expectedState.Classes, actual.Classes);
     Assert.AreEqual(expectedState.DateOfBirth, actual.DateOfBirth);
     Assert.AreEqual(expectedState.Grade, actual.Grade);
     Assert.AreEqual(expectedState.Id, actual.Id);
     Assert.AreEqual(expectedState.FullName, actual.Name);
     Assert.AreEqual(expectedState.Parents, actual.Parents);
     Assert.AreEqual(expectedState.School.Name, actual.SchoolName);
     Assert.AreEqual(expectedState.ServiceRequests, actual.ServiceRequests);
     Assert.AreEqual(expectedState.StudentSISId, actual.SISId);
     CollectionAssert.AreEqual(expectedState.StudentAssignedOfferings.ToList(), actual.StudentAssignedOfferings.ToList());
 }
        public void GivenNullProvider_WhenDeleteLink_ThenThrowException()
        {
            Student student = new Student();

            Target.ExpectException<ArgumentNullException>(() => Target.DeleteLink(student, null));
        }
        public void GivenAStudent_WhenAdd_ThenThrowNotImplementedException()
        {
            var expected = new Student { Id = 1 };

            Target.ExpectException<NotImplementedException>(() => Target.Add(expected));
        }
 private void ProcessRowCell(UploadWizardCompleteModel model, CustomDataOrigin origin, Dictionary<int, CustomField> customFieldsDicitonary, int rowNum, DataRow row, Student student, ref bool successfulRow, ref int nonIdColumns, List<CustomFieldValue> rowCustomFieldValues, int i)
 {
     string fieldValue = row[i].ToString();
     if (!string.IsNullOrWhiteSpace(fieldValue))
     {
         nonIdColumns++;
         int integerTest;
         if (customFieldsDicitonary[i].CustomFieldType.Name.Equals("Integer") && !int.TryParse(fieldValue, out integerTest))
         {
             successfulRow = false;
             ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Custom field {0} on row {1} is malformed", i + 1, rowNum + 2), model);
         }
         else
         {
             DateTime dateTest;
             if (customFieldsDicitonary[i].CustomFieldType.Name.Equals("Date") && !DateTime.TryParse(fieldValue, out dateTest))
             {
                 successfulRow = false;
                 ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Custom field {0} on row {1} is malformed", i + 1, rowNum + 2), model);
             }
             else
             {
                 var value = new CustomFieldValue
                 {
                     CustomDataOriginId = origin.Id,
                     StudentId = student.Id,
                     CustomFieldId = customFieldsDicitonary[i].Id,
                     Value = fieldValue
                 };
                 rowCustomFieldValues.Add(value);
             }
         }
     }
 }
        public void GivenUserIsDataAdmin_AndSubjectListRequestParam_AndStudentHasServiceRequestWithSubject_WhenIFilter_ThenStudentIsTaken()
        {
            Student student = new Student
            {
                ServiceRequests = new List<ServiceRequest>
                {
                    new ServiceRequest { Subject = new Subject { Name = "Reading" } }
                }
            };
            PrepareDataTableRequestParameters("0", "asc", null, null, null, null, null, null, null, null, "Math|Reading");
            Target = new StudentClientDataTable(MockContext.Request, CreateUser(true), StudentProperties);

            Assert.IsTrue(Target.FilterPredicate.Compile().Invoke(student));
        }