public async Task UpdateQuestionAsync_UpdatesImportedClasses()
        {
            var database = GetDatabase().Build();
            var question = database.Context.ClassQuestions
                           .Include(q => q.ImportedClasses)
                           .Include(q => q.Tests)
                           .First();

            database.Reload();

            question.ImportedClasses.Clear();
            question.ImportedClasses.Add(new ImportedClass()
            {
                ClassName = "NewImported"
            });

            var errors  = new MockErrorCollection();
            var updater = GetCodeQuestionUpdater(database, question, errors);
            await updater.UpdateQuestionAsync();

            database.Context.Questions.Update(question);
            database.Context.SaveChanges();

            database.Reload();
            question = database.Context.ClassQuestions
                       .Include(q => q.ImportedClasses)
                       .Include(q => q.Tests)
                       .First();

            Assert.False(errors.HasErrors);
            Assert.Single(question.ImportedClasses);
            Assert.Equal("NewImported", question.ImportedClasses[0].ClassName);
        }
        public async Task UpdateQuestionAsync_BrokenTemplate_ReturnsError()
        {
            var database = GetDatabase().Build();
            var question = database.Context.GeneratedQuestions.First();

            database.Reload();
            question.GeneratorContents = "NewGeneratedContents";

            var questionGenerator = GetMockQuestionGenerator
                                    (
                question,
                new QuestionGenerationResult("QuestionGenerationError")
                                    );

            var errors       = new MockErrorCollection();
            var timeProvider = new Mock <ITimeProvider>();
            var updater      = new GeneratedQuestionUpdater
                               (
                database.Context,
                question,
                errors,
                questionGenerator.Object,
                timeProvider.Object
                               );

            await updater.UpdateQuestionAsync();

            Assert.True(errors.HasErrors);
            Assert.True(errors.VerifyErrors("GeneratorContents"));
        }
Exemple #3
0
        public async Task ValidateAssignmentAsync_ChangedExistingQuestionId_ReturnsFalseWithCorrectError()
        {
            var database    = GetDatabase().Build();
            var modelErrors = new MockErrorCollection();
            var assignment  = database.Context
                              .Assignments
                              .Include(a => a.DueDates)
                              .Include(a => a.Questions)
                              .First();

            int newQuestionId = database.Context
                                .Questions
                                .First(q => q.Id != assignment.Questions[0].QuestionId)
                                .Id;

            assignment.Questions[0].QuestionId = newQuestionId;

            database.Reload();

            var assignmentValidator = new AssignmentValidator(database.Context);
            var result = await assignmentValidator.ValidateAssignmentAsync
                         (
                assignment,
                modelErrors
                         );

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Questions"));
        }
Exemple #4
0
        public async Task ValidateAssignmentAsync_DuplicateDueDates_ReturnsFalseWithCorrectError()
        {
            var database    = GetDatabase().Build();
            var modelErrors = new MockErrorCollection();
            var sectionId   = database.Context.Sections.First().Id;
            var assignment  = database.Context
                              .Assignments
                              .Include(a => a.DueDates)
                              .Include(a => a.Questions)
                              .First();

            assignment.DueDates.Add
            (
                new AssignmentDueDate()
            {
                SectionId = sectionId,
                DueDate   = DateTime.MaxValue
            }
            );

            database.Reload();

            var assignmentValidator = new AssignmentValidator(database.Context);
            var result = await assignmentValidator.ValidateAssignmentAsync
                         (
                assignment,
                modelErrors
                         );

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("DueDates"));
        }
Exemple #5
0
        public async Task UpdateQuestionAsync_UpdatesBlanks()
        {
            var database = GetDatabase().Build();
            var question = database.Context.ShortAnswerQuestions
                           .Include(q => q.Blanks)
                           .First();

            database.Reload();

            question.Blanks.Clear();
            question.Blanks.Add(new ShortAnswerQuestionBlank()
            {
                Name = "NewBlank1\r\nLine2"
            });
            question.Blanks.Add(new ShortAnswerQuestionBlank()
            {
                Name = "NewBlank2\r\nLine2"
            });

            var errors  = new MockErrorCollection();
            var updater = new ShortAnswerQuestionUpdater(database.Context, question, errors);
            await updater.UpdateQuestionAsync();

            Assert.False(errors.HasErrors);
            Assert.Equal(2, question.Blanks.Count);
            Assert.Equal("NewBlank1\nLine2", question.Blanks[0].Name);
            Assert.Equal(0, question.Blanks[0].Order);
            Assert.Equal("NewBlank2\nLine2", question.Blanks[1].Name);
            Assert.Equal(1, question.Blanks[1].Order);
        }
        public async Task PostAnnouncementAsync_ValidationFailed_ReturnsFalseWithError()
        {
            var database    = GetDatabase().Build();
            var classroomId = database.Context.Classrooms.First().Id;
            var userId      = database.Context
                              .Users
                              .Single(u => u.UserName == "Admin1")
                              .Id;

            var announcement = new Announcement()
            {
                Sections = new List <AnnouncementSection>()
            };

            var validator           = GetMockValidator(classroomId, announcement, result: false);
            var modelErrors         = new MockErrorCollection();
            var announcementService = GetAnnouncementService(database.Context, validator);
            var result = await announcementService.PostAnnouncementAsync
                         (
                "Class1",
                userId,
                announcement,
                dt => string.Empty,
                modelErrors
                         );

            database.Reload();

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Error"));
            Assert.False(database.Context.Announcements.Any());
        }
Exemple #7
0
        public async Task ValidateSectionAsync_DuplicateSectionRecipients_Error()
        {
            var database = GetDatabase().Build();
            var adminId  = database.Context
                           .ClassroomMemberships
                           .Single(cm => cm.User.UserName == "Admin1")
                           .Id;

            var errors    = new MockErrorCollection();
            var validator = new SectionValidator(database.Context);

            var section = new Section()
            {
                SectionRecipients = Collections.CreateList
                                    (
                    new SectionRecipient()
                {
                    ClassroomMembershipId = adminId,
                },
                    new SectionRecipient()
                {
                    ClassroomMembershipId = adminId,
                }
                                    )
            };

            var result = await validator.ValidateSectionAsync(section, errors);

            Assert.False(result);
            Assert.True(errors.VerifyErrors("SectionRecipients"));
        }
        public async Task UpdateQuestionAsync_ExistingQuestion_NoNewCategoryCreated()
        {
            var database = GetDatabase()
                           .AddQuestion("Class1", "Category1", new RandomlySelectedQuestion())
                           .Build();

            var existingQuestion = database.Context
                                   .Questions
                                   .OfType <RandomlySelectedQuestion>()
                                   .First();

            database.Reload();

            var errors  = new MockErrorCollection();
            var updater = new RandomlySelectedQuestionUpdater
                          (
                database.Context,
                existingQuestion,
                errors
                          );

            await updater.UpdateQuestionAsync();

            Assert.False(errors.HasErrors);
            Assert.Null(existingQuestion.ChoicesCategory);
            Assert.Equal(1, database.Context.QuestionCategories.Count());
        }
Exemple #9
0
        public async Task ValidateQuestionAsync_NewValidQuestion_ReturnsTrueNoErrors()
        {
            var database = GetDatabase().Build();

            var question = new MultipleChoiceQuestion()
            {
                Name = "NewQuestion",
                QuestionCategoryId = database.Context
                                     .QuestionCategories
                                     .Single(qc => qc.Name == "Category1")
                                     .Id
            };

            database.Reload();

            var modelErrors = new MockErrorCollection();
            var validator   = new QuestionValidator(database.Context);

            var result = await validator.ValidateQuestionAsync
                         (
                question,
                modelErrors,
                "Class1"
                         );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);
        }
Exemple #10
0
        public async Task ValidateQuestionAsync_ModifiedValidQuestion_ReturnsTrueNoErrors()
        {
            var database = GetDatabase().Build();

            var question = database.Context
                           .Questions
                           .Include(q => q.QuestionCategory.Classroom)
                           .Single(q => q.Name == "Question1");

            database.Reload();

            question.Name = "ModifiedQuestion";

            var modelErrors = new MockErrorCollection();
            var validator   = new QuestionValidator(database.Context);

            var result = await validator.ValidateQuestionAsync
                         (
                question,
                modelErrors,
                "Class1"
                         );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);
        }
Exemple #11
0
        public async Task CreateSectionAsync_InvalidSection_SectionNotCreated()
        {
            var database = new TestDatabaseBuilder()
                           .AddClassroom("Class1")
                           .Build();

            var section = new Section()
            {
                Name = "Section1"
            };
            var errors         = new MockErrorCollection();
            var validator      = CreateMockSectionValidator(section, errors, valid: false);
            var sectionService = CreateSectionService(database.Context, validator);

            var result = await sectionService.CreateSectionAsync("Class1", section, errors);

            database.Reload();

            section = database.Context.Sections
                      .Include(qc => qc.Classroom)
                      .SingleOrDefault();

            Assert.False(result);
            Assert.True(errors.HasErrors);
            Assert.Null(section);
        }
        public void ValidateAnnouncement_InvalidSection_ReturnsFalseWithError()
        {
            var validator   = new AnnouncementValidator();
            var modelErrors = new MockErrorCollection();
            var result      = validator.ValidateAnnouncement
                              (
                new Classroom()
            {
                Sections = new List <Section>()
            },
                new Announcement()
            {
                Sections = Collections.CreateList
                           (
                    new AnnouncementSection()
                {
                    SectionId = 1
                }
                           )
            },
                modelErrors
                              );

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Sections"));
        }
Exemple #13
0
        public async Task UpdateSectionAsync_ValidSection_SectionUpdated()
        {
            var database = new TestDatabaseBuilder()
                           .AddClassroom("Class1")
                           .AddSection("Class1", "Section1")
                           .Build();

            var section = database.Context.Sections
                          .Include(qc => qc.Classroom)
                          .First();

            // Update the section
            database.Context.Entry(section).State = EntityState.Detached;
            section.DisplayName = "New Display Name";

            // Apply the update
            var errors         = new MockErrorCollection();
            var validator      = CreateMockSectionValidator(section, errors, valid: true);
            var sectionService = CreateSectionService(database.Context, validator);
            var result         = await sectionService.UpdateSectionAsync("Class1", section, errors);

            database.Reload();

            section = database.Context.Sections
                      .Include(qc => qc.Classroom)
                      .Single();

            Assert.True(result);
            Assert.False(errors.HasErrors);
            Assert.Equal("Class1", section.Classroom.Name);
            Assert.Equal("Section1", section.Name);
            Assert.Equal("New Display Name", section.DisplayName);
        }
Exemple #14
0
        public async Task ValidateQuestionAsync_CategoryChangedForRandomQuestionChoice_Throws()
        {
            var database = GetDatabase().Build();

            var question = database.Context
                           .Questions
                           .Include(q => q.QuestionCategory.Classroom)
                           .Single(q => q.Name == "Choice1");

            var newCategoryId = database.Context
                                .QuestionCategories
                                .Single(qc => qc.Name == "Category1")
                                .Id;

            database.Reload();

            question.QuestionCategoryId = newCategoryId;
            question.QuestionCategory   = null;

            var modelErrors = new MockErrorCollection();
            var validator   = new QuestionValidator(database.Context);

            await Assert.ThrowsAsync <InvalidOperationException>
            (
                async() => await validator.ValidateQuestionAsync
                (
                    question,
                    modelErrors,
                    "Class1"
                )
            );
        }
        public void ValidateAnnouncement_ValidSections_ReturnsTrueWithNoError()
        {
            var validator   = new AnnouncementValidator();
            var modelErrors = new MockErrorCollection();
            var result      = validator.ValidateAnnouncement
                              (
                new Classroom()
            {
                Sections = Collections.CreateList
                           (
                    new Section()
                {
                    Id = 1
                }
                           )
            },
                new Announcement()
            {
                Sections = Collections.CreateList
                           (
                    new AnnouncementSection()
                {
                    SectionId = 1
                }
                           )
            },
                modelErrors
                              );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);
        }
Exemple #16
0
        public async Task ValidateSectionAsync_DuplicateSectionGradebooks_Error()
        {
            var database             = GetDatabase().Build();
            var classroomGradebookId = database.Context
                                       .ClassroomGradebooks
                                       .First()
                                       .Id;

            var errors    = new MockErrorCollection();
            var validator = new SectionValidator(database.Context);

            var section = new Section()
            {
                SectionGradebooks = Collections.CreateList
                                    (
                    new SectionGradebook()
                {
                    ClassroomGradebookId = classroomGradebookId,
                },
                    new SectionGradebook()
                {
                    ClassroomGradebookId = classroomGradebookId,
                }
                                    )
            };

            var result = await validator.ValidateSectionAsync(section, errors);

            Assert.False(result);
            Assert.True(errors.VerifyErrors("SectionGradebooks"));
        }
Exemple #17
0
        public async Task ValidateAssignmentAsync_OnlyShowCombinedScore_ReturnsFalseIfSeparateSubmissions(
            bool combinedSubmissions)
        {
            var database    = GetDatabase().Build();
            var modelErrors = new MockErrorCollection();
            var assignment  = database.Context
                              .Assignments
                              .Include(a => a.DueDates)
                              .Include(a => a.Questions)
                              .First();

            assignment.OnlyShowCombinedScore = true;
            assignment.CombinedSubmissions   = combinedSubmissions;

            database.Reload();

            var assignmentValidator = new AssignmentValidator(database.Context);
            var result = await assignmentValidator.ValidateAssignmentAsync
                         (
                assignment,
                modelErrors
                         );

            Assert.Equal(combinedSubmissions, result);
            if (!combinedSubmissions)
            {
                Assert.True(modelErrors.VerifyErrors("OnlyShowCombinedScore"));
            }
        }
        public async Task EditAnnouncementAsync_ValidationFailed_ReturnsFalseWithError()
        {
            var database     = GetDatabaseWithAnnouncements().Build();
            var classroomId  = database.Context.Classrooms.First().Id;
            var announcement = database.Context
                               .Announcements
                               .Single(a => a.DatePosted == PostDate2);

            var validator           = GetMockValidator(classroomId, announcement, result: false);
            var modelErrors         = new MockErrorCollection();
            var announcementService = GetAnnouncementService(database.Context, validator);

            announcement.Title = "UpdatedTitle";
            var result = await announcementService.EditAnnouncementAsync
                         (
                "Class1",
                announcement,
                dt => string.Empty,
                modelErrors
                         );

            database.Reload();

            announcement = database.Context
                           .Announcements
                           .Single(a => a.DatePosted == PostDate2);

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Error"));
            Assert.Equal("Title2", announcement.Title);
        }
Exemple #19
0
        public async Task UpdateQuestionAsync_RemovesAllTests_Error()
        {
            var database = GetDatabase().Build();
            var question = database.Context.ClassQuestions
                           .Include(q => q.Tests)
                           .First();

            database.Reload();

            question.Tests.Clear();

            var errors = new MockErrorCollection();
            var loader = new ClassQuestionUpdater(database.Context, question, errors);
            await loader.UpdateQuestionAsync();

            Assert.True(errors.HasErrors);
            Assert.True(errors.VerifyErrors("Tests"));

            database.Reload();
            question = database.Context.ClassQuestions
                       .Include(q => q.Tests)
                       .First();

            Assert.Equal(1, question.Tests.Count);
            Assert.Equal("Test", question.Tests[0].Name);
        }
Exemple #20
0
        public async Task UpdateQuestionAsync_UpdatesTests_NoError()
        {
            var database = GetDatabase().Build();
            var question = database.Context.ClassQuestions
                           .Include(q => q.Tests)
                           .First();

            database.Reload();

            question.Tests.Clear();
            question.Tests.Add(new ClassQuestionTest()
            {
                Name = "NewTest1", ExpectedOutput = "Line1\r\nLine2"
            });
            question.Tests.Add(new ClassQuestionTest()
            {
                Name = "NewTest2", ExpectedOutput = "Line1\r\nLine2"
            });

            var errors = new MockErrorCollection();
            var loader = new ClassQuestionUpdater(database.Context, question, errors);
            await loader.UpdateQuestionAsync();

            Assert.False(errors.HasErrors);
            Assert.Equal(2, question.Tests.Count);
            Assert.Equal("NewTest1", question.Tests[0].Name);
            Assert.Equal(0, question.Tests[0].Order);
            Assert.Equal("Line1\nLine2", question.Tests[0].ExpectedOutput);
            Assert.Equal("NewTest2", question.Tests[1].Name);
            Assert.Equal(1, question.Tests[1].Order);
            Assert.Equal("Line1\nLine2", question.Tests[1].ExpectedOutput);
        }
Exemple #21
0
        public async Task UpdateQuestionAsync_UpdatesChoices()
        {
            var database = GetDatabase().Build();
            var question = database.Context.MultipleChoiceQuestions
                           .Include(q => q.Choices)
                           .First();

            database.Reload();

            question.Choices.Clear();
            question.Choices.Add(new MultipleChoiceQuestionChoice()
            {
                Value = "NewChoice1\r\nLine2"
            });
            question.Choices.Add(new MultipleChoiceQuestionChoice()
            {
                Value = "NewChoice2\r\nLine2"
            });

            var errors  = new MockErrorCollection();
            var updater = new MultipleChoiceQuestionUpdater(database.Context, question, errors);
            await updater.UpdateQuestionAsync();

            Assert.False(errors.HasErrors);
            Assert.Equal(2, question.Choices.Count);
            Assert.Equal("NewChoice1\nLine2", question.Choices[0].Value);
            Assert.Equal(0, question.Choices[0].Order);
            Assert.Equal("NewChoice2\nLine2", question.Choices[1].Value);
            Assert.Equal(1, question.Choices[1].Order);
        }
        public async Task UpdateQuestionAsync_NewQuestion_CreatesChoicesCategory()
        {
            var database           = GetDatabase().Build();
            var classroom          = database.Context.Classrooms.First();
            var questionCategoryId = database.Context
                                     .QuestionCategories
                                     .First()
                                     .Id;

            var errors      = new MockErrorCollection();
            var newQuestion = new RandomlySelectedQuestion()
            {
                Name = "Random Question",
                QuestionCategoryId = questionCategoryId
            };

            var updater = new RandomlySelectedQuestionUpdater
                          (
                database.Context,
                newQuestion,
                errors
                          );

            await updater.UpdateQuestionAsync();

            Assert.False(errors.HasErrors);
            Assert.NotNull(newQuestion.ChoicesCategory);
            Assert.Equal(classroom.Id, newQuestion.ChoicesCategory.ClassroomId);
            Assert.Equal("Category1: Random Question", newQuestion.ChoicesCategory.Name);
        }
Exemple #23
0
        public async Task UpdateCheckpointAsync_DuplicateTestClasses_CheckpointNotUpdated()
        {
            var database = GetDatabaseBuilderWithCheckpoint().Build();

            var checkpoint = database.Context.Checkpoints
                             .Include(c => c.Project)
                             .Include(c => c.Project.Classroom)
                             .Include(c => c.TestClasses)
                             .Include(c => c.SectionDates)
                             .Single();

            var testClasses = database.Context.TestClasses.ToList();

            database.Reload();

            // Update the checkpoint
            checkpoint.TestClasses.Add
            (
                new CheckpointTestClass()
            {
                TestClassId = testClasses[0].Id,
                Required    = false
            }
            );

            // Apply the update
            var modelErrors       = new MockErrorCollection();
            var checkpointService = GetCheckpointService(database.Context);
            var result            = await checkpointService.UpdateCheckpointAsync
                                    (
                "Class1",
                "Project1",
                checkpoint,
                modelErrors
                                    );

            database.Reload();

            checkpoint = database.Context.Checkpoints
                         .Include(c => c.Project)
                         .Include(c => c.Project.Classroom)
                         .Include(c => c.TestClasses)
                         .Include(c => c.SectionDates)
                         .Single();

            Assert.False(result);
            Assert.True(modelErrors.HasErrors);
            Assert.True(modelErrors.VerifyErrors("TestClasses"));

            Assert.Equal(2, checkpoint.TestClasses.Count);
            Assert.Equal(testClasses[0].Id, checkpoint.TestClasses[0].TestClassId);
            Assert.True(checkpoint.TestClasses[0].Required);
            Assert.Equal(testClasses[1].Id, checkpoint.TestClasses[1].TestClassId);
            Assert.True(checkpoint.TestClasses[1].Required);
        }
Exemple #24
0
        public async Task UpdateCheckpointAsync_DuplicateSectionDueDates_CheckpointNotUpdated()
        {
            var database = GetDatabaseBuilderWithCheckpoint().Build();

            var checkpoint = database.Context.Checkpoints
                             .Include(c => c.Project)
                             .Include(c => c.Project.Classroom)
                             .Include(c => c.TestClasses)
                             .Include(c => c.SectionDates)
                             .Single();

            var sections = database.Context.Sections.ToList();

            database.Reload();

            // Update the checkpoint
            checkpoint.SectionDates.Add
            (
                new CheckpointDates()
            {
                SectionId = sections[0].Id,
                DueDate   = DateTime.MinValue
            }
            );

            // Apply the update
            var modelErrors       = new MockErrorCollection();
            var checkpointService = GetCheckpointService(database.Context);
            var result            = await checkpointService.UpdateCheckpointAsync
                                    (
                "Class1",
                "Project1",
                checkpoint,
                modelErrors
                                    );

            database.Reload();

            checkpoint = database.Context.Checkpoints
                         .Include(c => c.Project)
                         .Include(c => c.Project.Classroom)
                         .Include(c => c.TestClasses)
                         .Include(c => c.SectionDates)
                         .Single();

            Assert.False(result);
            Assert.True(modelErrors.HasErrors);
            Assert.True(modelErrors.VerifyErrors("SectionDates"));

            Assert.Equal(2, checkpoint.TestClasses.Count);
            Assert.Equal(sections[0].Id, checkpoint.SectionDates[0].SectionId);
            Assert.Equal(Period1DueDate, checkpoint.SectionDates[0].DueDate);
            Assert.Equal(sections[1].Id, checkpoint.SectionDates[1].SectionId);
            Assert.Equal(Period2DueDate, checkpoint.SectionDates[1].DueDate);
        }
        public async Task UpdateQuestionCategoryAsync_InvalidQuestion_QuestionNotUpdated(
            bool validatorIsValid,
            bool updaterIsValid)
        {
            var database = new TestDatabaseBuilder()
                           .AddClassroom("Class1")
                           .AddQuestionCategory("Class1", "Category1")
                           .AddQuestion("Class1", "Category1", new MethodQuestion()
            {
                Name = "Question1"
            })
                           .AddQuestion("Class1", "Category1", new MethodQuestion()
            {
                Name = "Question2"
            })
                           .Build();

            var modelErrors    = new MockErrorCollection();
            var validator      = GetMockQuestionValidator(validatorIsValid);
            var updaterFactory = GetMockQuestionUpdaterFactory(updaterIsValid);
            var question       = database.Context.Questions
                                 .Single(q => q.Name == "Question2");

            database.Context.Entry(question).State = EntityState.Detached;
            question.AllowPartialCredit            = true;

            var questionService = CreateQuestionService
                                  (
                database.Context,
                questionUpdaterFactory: updaterFactory.Object,
                questionValidator: validator.Object
                                  );

            var result = await questionService.UpdateQuestionAsync
                         (
                "Class1",
                question,
                modelErrors
                         );

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Error"));

            database.Reload();

            var questionCounts = database.Context.Questions
                                 .GroupBy(q => q.Name)
                                 .ToDictionary(g => g.Key, g => g.Count());

            Assert.Equal(2, questionCounts.Count);
            Assert.Equal(1, questionCounts["Question1"]);
            Assert.Equal(1, questionCounts["Question2"]);
        }
Exemple #26
0
        public async Task CreateCheckpointAsync_DuplicateSectionDueDates_CheckpointNotCreated()
        {
            var database = new TestDatabaseBuilder()
                           .AddClassroom("Class1")
                           .AddSection("Class1", "Period1")
                           .AddSection("Class1", "Period2")
                           .AddProject("Class1", "Project1")
                           .Build();

            var sections = database.Context.Sections.ToList();

            database.Reload();

            var modelErrors       = new MockErrorCollection();
            var checkpointService = GetCheckpointService(database.Context);

            var result = await checkpointService.CreateCheckpointAsync
                         (
                "Class1",
                "Project1",
                new Checkpoint()
            {
                Name         = "Checkpoint1",
                DisplayName  = "Checkpoint1 DisplayName",
                SectionDates = Collections.CreateList
                               (
                    new CheckpointDates()
                {
                    SectionId = sections[0].Id,
                    DueDate   = Period1DueDate
                },
                    new CheckpointDates()
                {
                    SectionId = sections[0].Id,
                    DueDate   = Period2DueDate
                }
                               )
            },
                modelErrors
                         );

            database.Reload();
            var checkpoint = database.Context.Checkpoints.SingleOrDefault();

            Assert.False(result);
            Assert.True(modelErrors.HasErrors);
            Assert.True(modelErrors.VerifyErrors("SectionDates"));
            Assert.Null(checkpoint);
        }
        public async Task CreateQuestionAsync_InvalidQuestion_QuestionNotCreated(
            bool validatorIsValid,
            bool updaterIsValid)
        {
            var database = new TestDatabaseBuilder()
                           .AddClassroom("Class1")
                           .AddQuestionCategory("Class1", "Category1")
                           .AddQuestion("Class1", "Category1", new MethodQuestion()
            {
                Name = "Question1"
            })
                           .Build();

            var questionCategoryId = database.Context.QuestionCategories.First().Id;
            var modelErrors        = new MockErrorCollection();
            var validator          = GetMockQuestionValidator(validatorIsValid);
            var updaterFactory     = GetMockQuestionUpdaterFactory(updaterIsValid);

            var questionService = CreateQuestionService
                                  (
                database.Context,
                questionValidator: validator.Object,
                questionUpdaterFactory: updaterFactory.Object
                                  );

            var result = await questionService.CreateQuestionAsync
                         (
                "Class1",
                new MethodQuestion()
            {
                Name = "Question1",
                QuestionCategoryId = questionCategoryId
            },
                modelErrors
                         );

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Error"));

            database.Reload();

            var numQuestions = database.Context.Questions.Count();

            Assert.False(result);
            Assert.True(modelErrors.HasErrors);
            Assert.True(modelErrors.VerifyErrors("Name"));
            Assert.Equal(1, numQuestions);
        }
Exemple #28
0
        public async Task UpdateAssignmentAsync_HasErrors_AssignmentNotUpdated()
        {
            var database = GetDatabaseWithAssignments().Build();

            var assignment = database.Context.Assignments
                             .Include(a => a.Classroom)
                             .Include(a => a.Questions)
                             .Include(a => a.DueDates)
                             .First();

            database.Reload();

            assignment.GroupName = "Updated Group Name";

            var modelErrors         = new MockErrorCollection();
            var assignmentValidator = CreateMockAssignmentValidator
                                      (
                assignment,
                modelErrors,
                validAssignment: false
                                      );

            var assignmentService = GetAssignmentService
                                    (
                database.Context,
                assignmentValidator
                                    );

            var result = await assignmentService.UpdateAssignmentAsync
                         (
                "Class1",
                assignment,
                modelErrors
                         );

            Assert.False(result);
            Assert.True(modelErrors.VerifyErrors("Error"));

            database.Reload();

            assignment = database.Context.Assignments
                         .Include(a => a.Classroom)
                         .Include(a => a.Questions)
                         .Include(a => a.DueDates)
                         .Single(a => a.Id == assignment.Id);

            Assert.Equal("Unit 1", assignment.GroupName);
        }
Exemple #29
0
        public async Task ValidateAssignmentAsync_ValidAssignment_ReturnsTrueWithNoErrors()
        {
            var database    = GetDatabase().Build();
            var modelErrors = new MockErrorCollection();
            var assignment  = database.Context.Assignments.First();

            var assignmentValidator = new AssignmentValidator(database.Context);
            var result = await assignmentValidator.ValidateAssignmentAsync
                         (
                assignment,
                modelErrors
                         );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);
        }
        public async Task UpdateQuestionCategoryAsync_ValidQuestion_QuestionUpdated()
        {
            var database = new TestDatabaseBuilder()
                           .AddClassroom("Class1")
                           .AddQuestionCategory("Class1", "Category1")
                           .AddQuestion("Class1", "Category1",
                                        new MethodQuestion {
                Name = "Question1", AllowPartialCredit = false
            })
                           .Build();

            var question       = database.Context.Questions.First();
            var modelErrors    = new MockErrorCollection();
            var validator      = GetMockQuestionValidator(isValid: true);
            var updaterFactory = GetMockQuestionUpdaterFactory(isValid: true);

            database.Context.Entry(question).State = EntityState.Detached;
            question.AllowPartialCredit            = true;

            var questionService = CreateQuestionService
                                  (
                database.Context,
                questionValidator: validator.Object,
                questionUpdaterFactory: updaterFactory.Object
                                  );

            var result = await questionService.UpdateQuestionAsync
                         (
                "Class1",
                question,
                modelErrors
                         );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);

            database.Reload();

            question = database.Context.Questions
                       .Include(qc => qc.QuestionCategory.Classroom)
                       .Single();

            Assert.Equal("Class1", question.QuestionCategory.Classroom.Name);
            Assert.Equal("Category1", question.QuestionCategory.Name);
            Assert.Equal("Question1", question.Name);
            Assert.True(question.AllowPartialCredit);
        }