public async Task UpdateQuestionAsync_ValidTemplate_UpdatesCachedContents() { var database = GetDatabase().Build(); var question = database.Context.GeneratedQuestions.First(); database.Reload(); question.GeneratorContents = "NewGeneratedContents"; var questionGenerator = GetMockQuestionGenerator ( question, new QuestionGenerationResult ( "SerializedQuestion", "FullGeneratorFileContents", fullGeneratorFileLineOffset: -10 ) ); var errors = new MockErrorCollection(); var updater = new GeneratedQuestionUpdater ( database.Context, question, errors, questionGenerator.Object ); await updater.UpdateQuestionAsync(); Assert.False(errors.HasErrors); Assert.Equal("FullGeneratorFileContents", question.FullGeneratorFileContents); Assert.Equal(-10, question.FullGeneratorFileLineOffset); }
public async Task UpdateQuestionAsync_UpdatesTests_NoError() { var database = GetDatabase().Build(); var question = database.Context.ProgramQuestions .Include(q => q.Tests) .First(); database.Reload(); question.Tests.Clear(); question.Tests.Add(new ProgramQuestionTest() { Name = "NewTest1", ExpectedOutput = "Line1\r\nLine2" }); question.Tests.Add(new ProgramQuestionTest() { Name = "NewTest2", ExpectedOutput = "Line1\r\nLine2" }); var errors = new MockErrorCollection(); var updater = new ProgramQuestionUpdater(database.Context, question, errors); await updater.UpdateQuestionAsync(); database.Context.Questions.Update(question); database.Context.SaveChanges(); database.Reload(); question = database.Context.ProgramQuestions .Include(q => q.Tests) .First(); Assert.False(errors.HasErrors); Assert.Equal(2, question.Tests.Count); Assert.Equal("NewTest1", question.Tests[0].Name); Assert.Equal("NewTest2", question.Tests[1].Name); }
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 updater = new GeneratedQuestionUpdater ( database.Context, question, errors, questionGenerator.Object ); await updater.UpdateQuestionAsync(); Assert.True(errors.HasErrors); Assert.True(errors.VerifyErrors("GeneratorContents")); }
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.Equal(1, question.ImportedClasses.Count); Assert.Equal("NewImported", question.ImportedClasses[0].ClassName); }
public async Task UpdateQuestionAsync_UpdatesCodeConstraints() { var database = GetDatabase().Build(); var question = database.Context.ClassQuestions .Include(q => q.CodeConstraints) .Include(q => q.Tests) .First(); database.Reload(); question.CodeConstraints.Clear(); question.CodeConstraints.Add(new CodeConstraint() { Regex = "NewRegex1" }); question.CodeConstraints.Add(new CodeConstraint() { Regex = "NewRegex2" }); 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.CodeConstraints) .Include(q => q.Tests) .First(); Assert.False(errors.HasErrors); Assert.Equal(2, question.CodeConstraints.Count); Assert.Equal("NewRegex1", question.CodeConstraints[0].Regex); Assert.Equal(0, question.CodeConstraints[0].Order); Assert.Equal("NewRegex2", question.CodeConstraints[1].Regex); Assert.Equal(1, question.CodeConstraints[1].Order); }
public async Task UpdateQuestionAsync_PrerequisiteQuestions() { var database = GetDatabase().Build(); var questions = database.Context.ClassQuestions .Include(q => q.PrerequisiteQuestions) .ToList(); database.Reload(); questions[1].PrerequisiteQuestions.Clear(); questions[1].PrerequisiteQuestions.Add ( new PrerequisiteQuestion() { FirstQuestionId = questions[2].Id, } ); questions[1].PrerequisiteQuestions.Add ( new PrerequisiteQuestion() { FirstQuestionId = questions[3].Id, } ); var errors = new MockErrorCollection(); var updater = GetQuestionUpdater(database, questions[1], errors); await updater.UpdateQuestionAsync(); database.Context.Questions.Update(questions[1]); database.Context.SaveChanges(); database.Reload(); var question = database.Context.ClassQuestions .Include(q => q.PrerequisiteQuestions) .Skip(1) .First(); Assert.False(errors.HasErrors); Assert.Equal(2, question.PrerequisiteQuestions.Count); Assert.Equal(questions[2].Id, question.PrerequisiteQuestions[0].FirstQuestionId); Assert.Equal(0, question.PrerequisiteQuestions[0].Order); Assert.Equal(questions[3].Id, question.PrerequisiteQuestions[1].FirstQuestionId); Assert.Equal(1, question.PrerequisiteQuestions[1].Order); }
public async Task UpdateQuestionAsync_UpdatesRequiredMethods() { var database = GetDatabase().Build(); var question = database.Context.ClassQuestions .Include(q => q.RequiredMethods) .Include(q => q.Tests) .First(); database.Reload(); question.RequiredMethods.Clear(); question.RequiredMethods.Add(new RequiredMethod() { Name = "NewRequired" }); var errors = new MockErrorCollection(); var updater = new ClassQuestionUpdater(database.Context, question, errors); await updater.UpdateQuestionAsync(); Assert.False(errors.HasErrors); Assert.Equal(1, question.RequiredMethods.Count); Assert.Equal("NewRequired", question.RequiredMethods[0].Name); }
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_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 RegisterFirstSuperUserAsync_WrongActivationToken_DoesNotRegister() { var database = new TestDatabaseBuilder().Build(); var modelErrors = new MockErrorCollection(); var activationToken = new ActivationToken("ActivationToken"); var userService = GetUserService ( database.Context, activationToken: activationToken ); var result = await userService.RegisterFirstSuperUserAsync ( new SuperUserRegistration() { ActivationToken = "Wrong" }, modelErrors ); Assert.Equal(RegisterNewUserResult.Failed, result); Assert.True(modelErrors.VerifyErrors("ActivationToken")); Assert.Equal(0, database.Context.Users.Count()); }
public async Task CreateQuestionAsync_NameCollision_QuestionNotCreated() { 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 updaterFactory = GetMockQuestionUpdaterFactory(); var questionService = CreateQuestionService ( database.Context, questionUpdaterFactory: updaterFactory.Object ); var result = await questionService.CreateQuestionAsync ( "Class1", new MethodQuestion() { Name = "Question1", QuestionCategoryId = questionCategoryId }, modelErrors ); database.Reload(); var numQuestions = database.Context.Questions.Count(); Assert.False(result); Assert.True(modelErrors.HasErrors); Assert.True(modelErrors.VerifyErrors("Name")); Assert.Equal(1, numQuestions); }
public async Task CreateCheckpointAsync_CheckpointCreated() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Period1") .AddSection("Class1", "Period2") .AddProject("Class1", "Project1") .AddProjectTestClass("Class1", "Project1", "TestClass1") .AddProjectTestClass("Class1", "Project1", "TestClass2") .Build(); var testClasses = database.Context.TestClasses.ToList(); 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", TestClasses = Collections.CreateList ( new CheckpointTestClass() { TestClassId = testClasses[0].Id }, new CheckpointTestClass() { TestClassId = testClasses[1].Id } ), SectionDates = Collections.CreateList ( new CheckpointDates() { SectionId = sections[0].Id, DueDate = Period1DueDate }, new CheckpointDates() { SectionId = sections[1].Id, DueDate = Period2DueDate } ) }, modelErrors ); database.Reload(); var checkpoint = database.Context.Checkpoints .Include(c => c.Project) .Include(c => c.Project.Classroom) .Include(c => c.TestClasses) .Include(c => c.SectionDates) .Single(); Assert.True(result); Assert.False(modelErrors.HasErrors); Assert.Equal("Class1", checkpoint.Project.Classroom.Name); Assert.Equal("Project1", checkpoint.Project.Name); Assert.Equal("Checkpoint1", checkpoint.Name); Assert.Equal(2, checkpoint.TestClasses.Count); Assert.Equal(testClasses[0].Id, checkpoint.TestClasses[0].TestClassId); Assert.Equal(testClasses[1].Id, checkpoint.TestClasses[1].TestClassId); Assert.Equal(2, checkpoint.SectionDates.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 RegisterFirstSuperUserAsync_ValidRegistration_Successful() { var database = new TestDatabaseBuilder().Build(); var modelErrors = new MockErrorCollection(); var activationToken = new ActivationToken("ActivationToken"); var gitHubUserClient = GetMockGitHubUserClient(userExists: true); var identityProvider = GetMockIdentityProvider(GetIdentity("User1")); var userService = GetUserService ( database.Context, identityProvider.Object, gitHubUserClient.Object, activationToken: activationToken ); var result = await userService.RegisterFirstSuperUserAsync ( new SuperUserRegistration() { LastName = "LastName", FirstName = "FirstName", ActivationToken = "ActivationToken", GitHubLogin = "******", EmailAddress = "EmailAddress" }, modelErrors ); database.Reload(); var user = database.Context.Users.Single(); Assert.Equal(RegisterNewUserResult.Success, result); Assert.False(modelErrors.HasErrors); Assert.Equal(1, database.Context.Users.Count()); Assert.Equal("LastName", user.LastName); Assert.Equal("FirstName", user.FirstName); Assert.Equal("User1Id", user.UniqueId); Assert.Equal("User1", user.UserName); Assert.Equal("GitHubUser", user.GitHubLogin); Assert.Equal("EmailAddress", user.EmailAddress); Assert.True(user.EmailAddressConfirmed); Assert.True(user.SuperUser); }
public async Task UpdateUserAsync_ValidGitHubUser_UserOnTeamUpdated() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .AddStudent("User1", "LastName", "FirstName", "Class1", "Section1", "OldGitHubUser", inGitHubOrg: true) .Build(); var user = database.Context.Users.Single(); database.Reload(); user.GitHubLogin = "******"; var modelErrors = new MockErrorCollection(); var userClient = GetMockGitHubUserClient(userExists: true); var teamClient = GetMockGitHubTeamClient("Class1"); var userService = GetUserService ( database.Context, gitHubUserClient: userClient.Object, gitHubTeamClient: teamClient.Object ); var result = await userService.UpdateUserAsync ( user, "ConfirmationUrlBuilder", modelErrors ); database.Reload(); user = database.Context.Users .Include(u => u.ClassroomMemberships) .Single(); Assert.True(result); Assert.False(modelErrors.HasErrors); Assert.Equal("GitHubUser", user.GitHubLogin); Assert.False(user.ClassroomMemberships.Single().InGitHubOrganization); teamClient.Verify ( tc => tc.RemoveUserFromTeamAsync ( "Class1GitHubOrg", It.Is<GitHubTeam>(t => t.Name == "LastNameFirstName"), "OldGitHubUser" ), Times.Once ); teamClient.Verify ( tc => tc.InviteUserToTeamAsync ( "Class1GitHubOrg", It.Is<GitHubTeam>(t => t.Name == "LastNameFirstName"), "GitHubUser" ), Times.Once ); }
public async Task RegisterNewStudentAsync_ValidRegistration_SendsConfirmationMail() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .Build(); var modelErrors = new MockErrorCollection(); var identityProvider = GetMockIdentityProvider(GetIdentity("User1")); var gitHubUserClient = GetMockGitHubUserClient(userExists: true); var gitHubTeamClient = GetMockGitHubTeamClient("Class1"); var emailProvider = GetMockEmailProvider("EmailAddress"); var userService = GetUserService ( database.Context, identityProvider.Object, gitHubUserClient.Object, gitHubTeamClient: gitHubTeamClient.Object, emailProvider: emailProvider.Object ); await userService.RegisterNewStudentAsync ( "Class1", "Section1", new StudentRegistration() { FirstName = "FirstName", GitHubLogin = "******", EmailAddress = "EmailAddress", }, "ConfirmationUrl", modelErrors ); emailProvider.Verify ( ep => ep.SendMessageAsync ( "EmailAddress", It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>() ), Times.Once ); }
public async Task RegisterNewStudentAsync_ValidRegistrationDuplicateName_UniqueGitHubTeam() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .AddStudent("User1", "LastName", "FirstName", "Class1", "Section1") .Build(); var modelErrors = new MockErrorCollection(); var identityProvider = GetMockIdentityProvider(GetIdentity("User2")); var gitHubUserClient = GetMockGitHubUserClient(userExists: true); var gitHubTeamClient = GetMockGitHubTeamClient("Class1"); var emailProvider = GetMockEmailProvider("EmailAddress"); var userService = GetUserService ( database.Context, identityProvider.Object, gitHubUserClient.Object, gitHubTeamClient: gitHubTeamClient.Object, emailProvider: emailProvider.Object ); var result = await userService.RegisterNewStudentAsync ( "Class1", "Section1", new StudentRegistration() { FirstName = "FirstName", GitHubLogin = "******", EmailAddress = "EmailAddress", }, "ConfirmationUrl", modelErrors ); database.Reload(); var student = database.Context.Users .Include(u => u.ClassroomMemberships) .ThenInclude(cm => cm.Classroom) .Include(u => u.ClassroomMemberships) .ThenInclude(cm => cm.SectionMemberships) .ThenInclude(sm => sm.Section) .Single(u => u.UserName == "User2"); var classroomMembership = student.ClassroomMemberships.Single(); var sectionMembership = classroomMembership.SectionMemberships.Single(); Assert.Equal(RegisterNewUserResult.Success, result); Assert.False(modelErrors.HasErrors); Assert.Equal(2, database.Context.Users.Count()); Assert.Equal("LastName", student.LastName); Assert.Equal("FirstName", student.FirstName); Assert.Equal("User2Id", student.UniqueId); Assert.Equal("User2", student.UserName); Assert.Equal("GitHubUser", student.GitHubLogin); Assert.Equal("EmailAddress", student.EmailAddress); Assert.False(student.EmailAddressConfirmed); Assert.False(student.SuperUser); Assert.NotNull(student.EmailConfirmationCode); Assert.Equal("Class1", classroomMembership.Classroom.Name); Assert.Equal("Section1", sectionMembership.Section.Name); Assert.Equal("LastNameFirstName2", classroomMembership.GitHubTeam); }
public async Task RegisterNewStudentAsync_ValidRegistration_InvitesToTeam() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .Build(); var modelErrors = new MockErrorCollection(); var identityProvider = GetMockIdentityProvider(GetIdentity("User1")); var gitHubUserClient = GetMockGitHubUserClient(userExists: true); var gitHubTeamClient = GetMockGitHubTeamClient("Class1"); var emailProvider = GetMockEmailProvider("EmailAddress"); var userService = GetUserService ( database.Context, identityProvider.Object, gitHubUserClient.Object, gitHubTeamClient: gitHubTeamClient.Object, emailProvider: emailProvider.Object ); await userService.RegisterNewStudentAsync ( "Class1", "Section1", new StudentRegistration() { FirstName = "FirstName", GitHubLogin = "******", EmailAddress = "EmailAddress", }, "ConfirmationUrl", modelErrors ); gitHubTeamClient.Verify ( gc => gc.InviteUserToTeamAsync ( "Class1GitHubOrg", It.Is<GitHubTeam>(t => t.Name == "LastNameFirstName"), "GitHubUser" ), Times.Once ); }
public async Task RegisterNewStudentAsync_NonExistentGitHubUser_DoesNotRegister() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .Build(); var modelErrors = new MockErrorCollection(); var identityProvider = GetMockIdentityProvider(GetIdentity("User1")); var gitHubUserClient = GetMockGitHubUserClient(userExists: false); var userService = GetUserService ( database.Context, identityProvider.Object, gitHubUserClient.Object ); var result = await userService.RegisterNewStudentAsync ( "Class1", "Section1", new StudentRegistration() { GitHubLogin = "******" }, "ConfirmationUrl", modelErrors ); Assert.Equal(RegisterNewUserResult.Failed, result); Assert.True(modelErrors.VerifyErrors("GitHubLogin")); Assert.Equal(0, database.Context.Users.Count()); }
public async Task RegisterNewStudentAsync_AlreadyRegistered_DoesNotRegister() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .AddStudent("User1", "LastName", "FirstName", "Class1", "Section1") .Build(); var modelErrors = new MockErrorCollection(); var identityProvider = GetMockIdentityProvider(GetIdentity("User1")); var userService = GetUserService ( database.Context, identityProvider.Object ); var result = await userService.RegisterNewStudentAsync ( "Class1", "Section1", new StudentRegistration(), "ConfirmationUrl", modelErrors ); Assert.Equal(RegisterNewUserResult.AlreadyRegistered, result); Assert.Equal(1, database.Context.Users.Count()); }
public async Task RegisterNewStudentAsync_SectionNotOpen_DoesNotRegister() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1", allowRegistrations: false) .Build(); var modelErrors = new MockErrorCollection(); var userService = GetUserService(database.Context); var result = await userService.RegisterNewStudentAsync ( "Class1", "Section1", new StudentRegistration(), "ConfirmationUrl", modelErrors ); Assert.Equal(RegisterNewUserResult.SectionNotOpen, result); Assert.Equal(0, database.Context.Users.Count()); }
public async Task RegisterFirstSuperUserAsync_ExistingUser_DoesNotRegister() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .AddStudent("User1", "LastName", "FirstName", "Class1", "Section1") .Build(); var modelErrors = new MockErrorCollection(); var userService = GetUserService(database.Context); var result = await userService.RegisterFirstSuperUserAsync ( new SuperUserRegistration(), modelErrors ); Assert.Equal(RegisterNewUserResult.AlreadyRegistered, result); Assert.Equal(1, database.Context.Users.Count()); }
public async Task UpdateUserAsync_InvalidGitHubUser_UserNotUpdated() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .AddStudent("User1", "LastName", "FirstName", "Class1", "Section1", "OldGitHubUser") .Build(); var user = database.Context.Users.Single(); database.Reload(); user.GitHubLogin = "******"; var modelErrors = new MockErrorCollection(); var userClient = GetMockGitHubUserClient(userExists: false); var userService = GetUserService ( database.Context, gitHubUserClient: userClient.Object ); var result = await userService.UpdateUserAsync ( user, "ConfirmationUrlBuilder", modelErrors ); database.Reload(); user = database.Context.Users.Single(); Assert.False(result); Assert.True(modelErrors.HasErrors); Assert.True(modelErrors.VerifyErrors("GitHubLogin")); Assert.Equal("OldGitHubUser", user.GitHubLogin); }
public async Task UpdateQuestionAsync_IncorrectTemplate_Error() { var database = GetDatabase().Build(); var question = database.Context.ClassQuestions .Include(q => q.Tests) .First(); database.Reload(); question.FileTemplate = "Missing Submission Expression"; var errors = new MockErrorCollection(); var loader = new ClassQuestionUpdater(database.Context, question, errors); await loader.UpdateQuestionAsync(); Assert.True(errors.HasErrors); Assert.True(errors.VerifyErrors("FileTemplate")); database.Reload(); question = database.Context.ClassQuestions.First(); Assert.Equal("%SUBMISSION%", question.FileTemplate); }
public async Task UpdateCheckpointAsync_ValidModification_CheckpointUpdated() { 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(); var testClasses = database.Context.TestClasses.ToList(); database.Reload(); // Update the checkpoint checkpoint.TestClasses.RemoveAt(0); checkpoint.TestClasses.Add ( new CheckpointTestClass() { TestClassId = testClasses[0].Id, Required = false } ); checkpoint.SectionDates.RemoveAt(0); 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(); var checkpointTestClasses = checkpoint.TestClasses .OrderBy(tc => tc.Id) .ToList(); var checkpointDates = checkpoint.SectionDates .OrderBy(cd => cd.Id) .ToList(); Assert.True(result); Assert.False(modelErrors.HasErrors); Assert.Equal("Class1", checkpoint.Project.Classroom.Name); Assert.Equal("Project1", checkpoint.Project.Name); Assert.Equal("Checkpoint1", checkpoint.Name); Assert.Equal(2, checkpoint.TestClasses.Count); Assert.Equal(testClasses[1].Id, checkpointTestClasses[0].TestClassId); Assert.True(checkpointTestClasses[0].Required); Assert.Equal(testClasses[0].Id, checkpointTestClasses[1].TestClassId); Assert.False(checkpointTestClasses[1].Required); Assert.Equal(2, checkpoint.SectionDates.Count); Assert.Equal(sections[1].Id, checkpointDates[0].SectionId); Assert.Equal(Period2DueDate, checkpointDates[0].DueDate); Assert.Equal(sections[0].Id, checkpointDates[1].SectionId); Assert.Equal(DateTime.MinValue, checkpointDates[1].DueDate); }
public async Task UpdateUserAsync_EmailAddressNotUpdated_NoConfirmationEmailSent() { var database = new TestDatabaseBuilder() .AddClassroom("Class1") .AddSection("Class1", "Section1") .AddStudent("User1", "LastName", "FirstName", "Class1", "Section1") .Build(); var user = database.Context.Users.Single(); user.EmailAddressConfirmed = true; database.Context.SaveChanges(); database.Reload(); var modelErrors = new MockErrorCollection(); var emailProvider = GetMockEmailProvider("User1Email"); var userService = GetUserService ( database.Context, emailProvider: emailProvider.Object ); await userService.UpdateUserAsync ( user, "ConfirmationUrlBuilder", modelErrors ); database.Reload(); user = database.Context.Users.Single(); Assert.Equal(user.EmailConfirmationCode, "User1EmailConfirmationCode"); Assert.True(user.EmailAddressConfirmed); emailProvider.Verify ( ep => ep.SendMessageAsync ( "User1Email", It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>() ), Times.Never ); }
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); }
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 updater = GetCodeQuestionUpdater(database, question, errors); await updater.UpdateQuestionAsync(); database.Context.Questions.Update(question); database.Context.SaveChanges(); 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); }
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 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 RegisterFirstSuperUserAsync_NonExistentGitHubUser_DoesNotRegister() { var database = new TestDatabaseBuilder().Build(); var modelErrors = new MockErrorCollection(); var activationToken = new ActivationToken("ActivationToken"); var gitHubUserClient = GetMockGitHubUserClient(userExists: false); var userService = GetUserService ( database.Context, activationToken: activationToken, gitHubUserClient: gitHubUserClient.Object ); var result = await userService.RegisterFirstSuperUserAsync ( new SuperUserRegistration() { ActivationToken = "ActivationToken", GitHubLogin = "******" }, modelErrors ); Assert.Equal(RegisterNewUserResult.Failed, result); Assert.True(modelErrors.VerifyErrors("GitHubLogin")); Assert.Equal(0, database.Context.Users.Count()); }