예제 #1
0
		/// <summary>
		/// Returns a build result for the given build.
		/// </summary>
		private async Task<BuildResult> GetBuildResultAsync(Build build)
		{
			var project = build.Commit.Project;

			var isLatestBuild = await IsLatestBuildAsync(project, build);

			var submissions = await _dbContext.Submissions
				.Where(submission => submission.Commit.ProjectId == project.Id)
				.Include(submission => submission.Commit)
				.Include(submission => submission.Checkpoint)
				.Where(submission => submission.Commit.UserId == build.Commit.UserId)
				.ToListAsync();

			var checkpoints = await _dbContext.Checkpoints
				.Where(checkpoint => checkpoint.ProjectId == project.Id)
				.Include(checkpoint => checkpoint.SectionDates)
				.ToListAsync();

			var section = await _dbContext.SectionMemberships
				.Where
				(
					sm => sm.ClassroomMembership.UserId == build.Commit.User.Id
						&& sm.ClassroomMembership.ClassroomId == build.Commit.Project.Classroom.Id
						&& sm.Role == SectionRole.Student
				)
				.Select(sm => sm.Section)
				.FirstOrDefaultAsync();

			var testCounts = await GetBuildTestCountsAsync
			(
				build.Commit.Project,
				build.Commit.UserId
			);

			return new BuildResult
			(
				build,
				isLatestBuild,
				section,
				checkpoints,
				submissions,
				testCounts
			);
		}
예제 #2
0
		/// <summary>
		/// Returns whether or not the given build is the latest build.
		/// </summary>
		private async Task<bool> IsLatestBuildAsync(Project project, Build build)
		{
			var latestBuildId = await GetBuildsDescending(project)
				.Where(b => b.Commit.UserId == build.Commit.UserId)
				.Select(b => b.Id)
				.FirstAsync();

			return build.Id == latestBuildId;
		}
예제 #3
0
		/// <summary>
		/// Returns the number of tests the student passed in each class.
		/// </summary>
		private static JProperty[] GetTestClassCounts(Build build, ICollection<TestClass> testClasses)
		{
			return testClasses.Select
			(
				testClass => new JProperty
				(
					testClass.ClassName.ToAlphaNumeric(),
					build.TestResults
						?.Count
						(
							testResult => 
							   testResult.ClassName == testClass.ClassName &&
							   testResult.Succeeded
						) ?? 0
				)
			).ToArray();
		}
예제 #4
0
		/// <summary>
		/// Returns all test results.
		/// </summary>
		private object[] GetAllTestResults(Build build)
		{
			return build.TestResults != null
				? new[]
				{
					new JProperty
					(
						"childTableData",
						build.Commit.Project.TestClasses.Select
						(
							testClass => _jsonSerializer.SerializeToJObject
							(
								new TestClassTableEntry
								(
									testClass,

									false /*emphasized*/,

									build.TestResults
										.Where(tr => tr.ClassName == testClass.ClassName)
										.ToList(),

									tr => Url.Action
									(
										"TestResult", 
										new
										{
											buildId = build.Id,
											testResultId = tr.Id
										}
									)
								)
							)
						)
					)
				}
				: new object[0];
		}
예제 #5
0
		/// <summary>
		/// Returns the total number of tests the student passed.
		/// </summary>
		private static JProperty GetAllTestCount(Build build)
		{
			return new JProperty
			(
				"AllTests",
				build.TestResults?.Count(tr => tr.Succeeded) ?? 0
			);
		}
예제 #6
0
		/// <summary>
		/// Returns student build information.
		/// </summary>
		private JProperty[] GetBuildInfo(Build build)
		{
			var user = build.Commit.User;
			var buildUrl = Url.Action("BuildResult", new { buildId = build.Id });
			var buildLink = $"<a href=\"{buildUrl}\" target=\"_blank\">(Link)</a>";
			var buildTime = build.Commit.PushDate.FormatShortDateTime(TimeZoneProvider);

			return new[]
			{
				new JProperty("LastName", user.LastName),
				new JProperty("FirstName", user.FirstName),
				new JProperty("BuildSucceeded", $"{(build.Status == BuildStatus.Completed ? "Yes" : "No")} {buildLink}"),
				new JProperty("BuildTime", $"<span style=\"white-space:nowrap\">{buildTime}</span>")
			};
		}
        /// <summary>
        /// Adds a project to the database.
        /// </summary>
        public TestDatabaseBuilder AddCommit(
            string classroomName,
            string projectName,
            string userName,
            string commitSha,
            DateTime pushDate,
            Build build = null,
            string buildJobId = null,
            string buildRequestToken = null)
        {
            var project = _buildContext.Projects
                .Where(p => p.Classroom.Name == classroomName)
                .Single(p => p.Name == projectName);

            var user = _buildContext.Users
                .Single(u => u.UserName == userName);

            _buildContext.Commits.Add
            (
                new Commit()
                {
                    ProjectId = project.Id,
                    UserId = user.Id,
                    PushDate = pushDate,
                    Sha = commitSha,
                    Build = build,
                    BuildJobId = buildJobId,
                    BuildRequestToken = buildRequestToken,
                }
            );

            _buildContext.SaveChanges();

            return this;
        }
		/// <summary>
		/// Returns a database with a project and a student.
		/// </summary>
		private TestDatabaseBuilder GetDatabaseBuilderWithProjectAndStudent(
			bool explicitSubmissions = true, 
			Build firstBuild = null, 
			Build secondBuild = null)
		{
			return GetDatabaseBuilderWithProject(explicitSubmissions)
				.AddSection("Class1", "Section1")
				.AddStudent("Student1", "LastName", "FirstName", "Class1", "Section1", "GitHubUser", inGitHubOrg: true)
				.AddCommit("Class1", "Project1", "Student1", "FirstCommitSha", FirstPushDate, firstBuild)
				.AddCommit("Class1", "Project1", "Student1", "SecondCommitSha", SecondPushDate, secondBuild);
		}
		/// <summary>
		/// Returns a successful build.
		/// </summary>
		private static Build GetSuccessfulBuild()
		{
			var successfulBuild = new Build()
			{
				Status = BuildStatus.Completed,
				TestResults = Collections.CreateList
				(
					new TestResult()
					{
						ClassName = "TestClass1",
						TestName = "TestClass1Test",
						Succeeded = true
					},
					new TestResult()
					{
						ClassName = "TestClass2",
						TestName = "TestClass2Test",
						Succeeded = false
					}
				)
			};
			return successfulBuild;
		}