コード例 #1
0
 /// <summary>
 /// Creates a new mock question duplicator.
 /// </summary>
 private static CodeQuestionDuplicator<CodeQuestion> GetCodeQuestionDuplicator(
     TestDatabase database,
     CodeQuestion question)
 {
     return new Mock<CodeQuestionDuplicator<CodeQuestion>>(database.Context, question).Object;
 }
コード例 #2
0
		/// <summary>
		/// Creates a new code question updater.
		/// </summary>
		private static CodeQuestionUpdater<CodeQuestion> GetCodeQuestionUpdater(
			TestDatabase database,
			CodeQuestion question,
			IModelErrorCollection errors)
		{
			return new Mock<CodeQuestionUpdater<CodeQuestion>>(database.Context, question, errors).Object;
		}
コード例 #3
0
		/// <summary>
		/// Returns a code question grader. For a given question, the grader 
		/// returns a given simulated result for a given submission.
		/// </summary>
		public CodeQuestionGrader<CodeQuestion> GetCodeQuestionGrader(
			CodeQuestion question,
			CodeQuestionSubmission submission,
			CodeJobResult simulatedResult,
			IList<DefinitionError> definitionErrors = null)
		{
			var grader = new Mock<CodeQuestionGrader<CodeQuestion>>
			(
				question,
				null /*codeRunnerService*/
			);

			grader.CallBase = true;

			grader.Protected()
				.Setup<Task<CodeJobResult>>
				(
					"ExecuteJobAsync", 
					ItExpr.Is<CodeQuestionSubmission>(s => s == submission)
				).Returns(Task.FromResult(simulatedResult));

			grader.Protected()
				.Setup<string>("GetTestDescription", ItExpr.IsAny<CodeQuestionTest>())
				.Returns<CodeQuestionTest>(test => test.Name);

			if (definitionErrors != null)
			{
				grader.Protected()
					.Setup<IEnumerable<CodeQuestionError>>
					(
						"GetDefinitionErrors",
						ItExpr.Is<CodeQuestionSubmission>(s => s == submission),
						ItExpr.Is<CodeJobResult>(r => r == simulatedResult)
					).Returns(definitionErrors);
			}

			return grader.Object;
		}