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_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_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"));
        }
        public async Task UpdateQuestionAsync_UpdatesImportedClasses()
        {
            var database = GetDatabase().Build();
            var question = database.Context.GeneratedQuestions
                           .Include(q => q.ImportedClasses)
                           .First();

            database.Reload();

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

            var errors            = new MockErrorCollection();
            var timeProvider      = new Mock <ITimeProvider>();
            var questionGenerator = GetMockQuestionGenerator
                                    (
                question,
                new QuestionGenerationResult(null)
                                    );

            var updater = new GeneratedQuestionUpdater
                          (
                database.Context,
                question,
                errors,
                questionGenerator.Object,
                timeProvider.Object
                          );

            await updater.UpdateQuestionAsync();

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

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

            Assert.False(errors.HasErrors);
            Assert.Single(question.ImportedClasses);
            Assert.Equal("NewImported", question.ImportedClasses[0].ClassName);
        }
        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,
                    seed: 0
                )
                                    );

            var errors       = new MockErrorCollection();
            var timeProvider = new Mock <ITimeProvider>();
            var dateUpdated  = new DateTime(2017, 1, 1, 0, 0, 0);

            timeProvider
            .Setup(m => m.UtcNow)
            .Returns(dateUpdated);

            var updater = new GeneratedQuestionUpdater
                          (
                database.Context,
                question,
                errors,
                questionGenerator.Object,
                timeProvider.Object
                          );

            await updater.UpdateQuestionAsync();

            Assert.False(errors.HasErrors);
            Assert.Equal("FullGeneratorFileContents", question.FullGeneratorFileContents);
            Assert.Equal(-10, question.FullGeneratorFileLineOffset);
            Assert.Equal(dateUpdated, question.DateModified);
        }