public void GivenACustomDataOrigin_WhenUpdate_ThenContextSetsModified()
        {
            var expected = new CustomDataOrigin { Id = 1 };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
        public void GivenACustomDataOrigin_WhenRemove_ThenRemoveFromContext()
        {
            var item = new CustomDataOrigin { Id = 1 };

            Target.Remove(item);

            MockDbSet.AssertWasCalled(m => m.Remove(item));
        }
        public void GivenACustomDataOrigin_WhenAdd_ThenAddToContext()
        {
            var expected = new CustomDataOrigin { Id = 1 };

            Target.Add(expected);

            MockDbSet.AssertWasCalled(m => m.Add(expected));
        }
예제 #4
0
        public void WhenConstruct_ThenCreateTimeSet()
        {
            CustomDataOrigin actual = new CustomDataOrigin();

            Assert.IsTrue(actual.CreateTime.WithinTimeSpanOf(TimeSpan.FromMilliseconds(20), DateTime.Now));
        }
 private void ProcessRows(EducationSecurityPrincipal user, int studentIdColumn, DataTable dataTable, UploadWizardCompleteModel completeModel, CustomDataOrigin origin, Dictionary<int, CustomField> customFieldsDicitonary)
 {
     int numColumns = dataTable.Columns.Count;
     for (int i = 0; i < dataTable.Rows.Count; i++)
     {
         var row = dataTable.Rows[i];
         if (row.HasErrors)
         {
             ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Row {0} failed to process.  {1}", i + 2, row.RowError), completeModel);
         }
         else
         {
             var studentId = row[studentIdColumn].ToString();
             var student = StudentRepository.Items.Include("StudentAssignedOfferings.ServiceOffering.Provider").
                                                   SingleOrDefault(s => s.StudentSISId == studentId);
             if (student == null || !PermissionFactory.Current.Create("ProcessDataFile", student).TryGrantAccess(user))
             {
                 ProcessError(row, string.Format(CultureInfo.CurrentCulture, "You do not have permission to interact with the referenced student on row {0}", i + 2), completeModel);
             }
             else
             {
                 AttemptRowReadOfUploadWizardFile(studentIdColumn, completeModel, origin, customFieldsDicitonary, numColumns, i, row, student);
             }
         }
         completeModel.ProcessedRowCount++;
     }
 }
 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);
             }
         }
     }
 }
 private CustomDataOrigin CreateCustomDataOrigin(EducationSecurityPrincipal user, UploadWizardModel uploadModel)
 {
     var origin = new CustomDataOrigin
     {
         CreatingUser = user.Identity.User,
         FileName = uploadModel.BlobAddress,
         AzureBlobKey = uploadModel.BlobAddress,
         Source = uploadModel.Source,
         WasManualEntry = false
     };
     CustomDataOriginRepository.Add(origin);
     return origin;
 }
 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);
         }
     }
 }
 public void Update(CustomDataOrigin item)
 {
     Context.SetModified(item);
 }
 public void Remove(CustomDataOrigin item)
 {
     Context.CustomDataOrigins.Remove(item);
 }
 public void Add(CustomDataOrigin item)
 {
     Context.CustomDataOrigins.Add(item);
 }
        public void WhenConstruct_ThenCreateTimeSet()
        {
            CustomDataOrigin actual = new CustomDataOrigin();

            Assert.IsTrue(actual.CreateTime.WithinTimeSpanOf(TimeSpan.FromMilliseconds(20), DateTime.Now));
        }