public void GenerateConstructorInvocation_GeneratesCorrectInvocation()
		{
			var question = new MethodQuestion();
			var fileBuilder = new JavaFileBuilder();

			var questionGenerator = GetQuestionGenerator(question);
			questionGenerator.GenerateConstructorInvocation(question, fileBuilder);

			Assert.Equal("ConstructorInvocation\n", fileBuilder.GetFileContents());
		}
        public void GenerateClassDefinition_GeneratesCorrectDefinition()
        {
            var javaClass = ExpectedJavaModel.GetFullJavaModel()
                .Single(c => c.ClassName == "RootObject");

            var fileBuilder = new JavaFileBuilder();
            var classDefGenerator = new JavaClassDefinitionGenerator(fileBuilder, javaClass);

            classDefGenerator.GenerateClassDefinition();

            var result = fileBuilder.GetFileContents();
            var expectedResult = c_correctDefinition.Replace("\r\n", "\n");

            Assert.Equal(expectedResult, result);
        }
        public void GenerateConstructorInvocation_GeneratesCorrectInvocation()
        {
            var fileBuilder = new JavaFileBuilder();
            var javaModel = ExpectedJavaModel.GetFullJavaModel();
            var constructorInvocationGen = new JavaConstructorInvocationGenerator
            (
                fileBuilder,
                javaModel
            );

            constructorInvocationGen.GenerateConstructorInvocation
            (
                GetRootObject(),
                "return ",
                ";"
            );

            var result = fileBuilder.GetFileContents();
            var expectedResult = c_correctInvocation.Replace("\r\n", "\n");

            Assert.Equal(expectedResult, result);
        }
		/// <summary>
		/// Returns the contents of the file used to generate the question.
		/// </summary>
		private string GetGeneratorFile(int numImports, string generatorContents, out int lineOffset)
		{
			var fileBuilder = new JavaFileBuilder();
			var javaModel = _questionModelFactory.GetQuestionModel();

			foreach (var javaClass in javaModel)
			{
				var javaClassDefinitionGenerator = _javaCodeGenerationFactory
					.CreateJavaClassDefinitionGenerator(fileBuilder, javaClass);

				javaClassDefinitionGenerator.GenerateClassDefinition();
				fileBuilder.AddBlankLine();
			}

			lineOffset = -fileBuilder.LinesAdded - numImports;
			fileBuilder.AddLines(generatorContents);

			return fileBuilder.GetFileContents().Replace("%", "%%");
		}
		/// <summary>
		/// Returns a new generated question template based off of an existing question. 
		/// The generated question is not saved unless and until it is submitted through 
		/// CreateQuestionAsync.
		/// </summary>
		public async Task<Question> GenerateFromExistingQuestionAsync(
			string classroomName,
			int existingQuestionId)
		{
			var existingQuestion = await GetQuestionAsync(classroomName, existingQuestionId);

			if (existingQuestion is GeneratedQuestionTemplate)
			{
				throw new InvalidOperationException(
					"Cannot generate question from existing generated question.");
			}

			var builder = new JavaFileBuilder();

			builder.AddLine("public class QuestionGenerator");
			builder.BeginScope("{");
				builder.AddLine("public static Question generateQuestion(int seed)");
				builder.BeginScope("{");
					_questionGenerator.GenerateConstructorInvocation
					(
						existingQuestion,
						builder
					);
				builder.EndScope("}");
			builder.EndScope("}");

			return new GeneratedQuestionTemplate()
			{
				Name = $"{existingQuestion.Name} (generated)",
				QuestionCategoryId = existingQuestion.QuestionCategoryId,
				Description = "Generated Question",
				ImportedClasses = new List<ImportedClass>()
				{
					new ImportedClass()
					{
						ClassName = "java.util.*"
					}
				},
				GeneratorContents = builder.GetFileContents()
			};
		}