public void GameInClosedStateWithoutATitle_Open_ThrowsException() { // arrange var quiz = TestQuiz.GetQuiz(); var game = new Game { State = GameState.Closed, QuizId = quiz.Id }; // act & assert var exception = Assert.ThrowsException <DomainException>(() => game.SetState(GameState.Open)); Assert.AreEqual(ResultCode.InvalidGameStateTransition, exception.ResultCode); Assert.AreEqual("Can't open the game without a quiz and/or a title.", exception.Message); Assert.IsTrue(exception.IsBadRequest); }
public void TestQuiz_AnswerMrSemiIncorrect_ZeroTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var mrQuestion = TestQuiz.GetMRQuestion(); var answer = new Answer(quiz.QuizSections.First().Id, mrQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, new[] { 1, 3 })); // Act mrQuestion.Score(answer); // Assert Assert.AreEqual(0, answer.TotalScore); }
public void TestQuiz_AnswerMcCorrect_OneTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var mcQuestion = TestQuiz.GetMCQuestion(); var answer = new Answer(quiz.QuizSections.First().Id, mcQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, new[] { 3 })); // Act mcQuestion.Score(answer); // Assert Assert.AreEqual(1, answer.TotalScore); }
public void TestQuiz_AnswerSaMultipleSolutionCorrect2_OneTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var saQuestion = TestQuiz.GetSAWithMultipleSolutionsQuestion(); var answer = new Answer(quiz.QuizSections[1].Id, saQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, "ansver")); // Act saQuestion.Score(answer); // Assert Assert.AreEqual(1, answer.TotalScore); }
public void TestQuiz_AnswerSaCorrect_OneTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var saQuestion = TestQuiz.GetSAQuestion(); var answer = new Answer(quiz.QuizSections.First().Id, saQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, "answer")); // Act saQuestion.Score(answer); // Assert Assert.AreEqual(1, answer.TotalScore); }
public void TestQuiz_AnswerEt_FlaggedForManualCorrectionNoScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var etQuestion = TestQuiz.GetETQuestion(); var answer = new Answer(quiz.QuizSections[1].Id, etQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, "an answer")); // Act etQuestion.Score(answer); // Assert Assert.AreEqual(0, answer.TotalScore); Assert.IsTrue(answer.FlaggedForManualCorrection); }
public void TestQuiz_AnswerMultipleSaSecondCorrect_TwoTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var multipleSaQuestion = TestQuiz.GetMultipleSAQuestion(); var answer = new Answer(quiz.QuizSections[1].Id, multipleSaQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, "wrong answer")); answer.InteractionResponses.Add(new InteractionResponse(2, "answer2")); // Act multipleSaQuestion.Score(answer); // Assert Assert.AreEqual(2, answer.TotalScore); }
public void TestQuiz_AnswerMultipleSaCorrect_ThreeTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var multipleSaQuestion = TestQuiz.GetMultipleSAQuestion(); // quiz.QuizSections.First().QuestionItems[4]; var answer = new Answer(quiz.QuizSections[1].Id, multipleSaQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, "answer1")); answer.InteractionResponses.Add(new InteractionResponse(2, "answer2")); // Act multipleSaQuestion.Score(answer); // Assert Assert.AreEqual(3, answer.TotalScore); }
public void TestQuiz_AnswerSaIncorrectNoAnswer_ZeroTotalScore() { // Arrange var quiz = TestQuiz.GetQuiz(); var saQuestion = TestQuiz.GetSAQuestion(); var answer = new Answer(quiz.QuizSections.First().Id, saQuestion.Id); answer.InteractionResponses.Add(new InteractionResponse(1, string.Empty)); // Act saQuestion.Score(answer); // Assert Assert.AreEqual(0, answer.TotalScore); Assert.IsTrue(answer.FlaggedForManualCorrection); }
public void Initialize() { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // var memoryCache = new MemoryCache(new MemoryCacheOptions()); // // ICollectionOptions inMemoryCollectionOptions = new InMemoryDatabaseOptions(); // UnitOfWork = new NoActionUnitOfWork(memoryCache, LoggerFactory, inMemoryCollectionOptions); var services = new ServiceCollection(); Directory.Delete("quiz", true); Directory.CreateDirectory("quiz"); services .AddLogging(builder => builder.AddConsole()) .AddMemoryCache() .AddSingleton(_ => new QuizrSettings { BaseUrl = "https://localhost:5001", WebRootPath = "", ContentPath = "quiz" }) .AddSingleton <ICollectionOptions, InMemoryDatabaseOptions>() .AddScoped <IUnitOfWork, NoActionUnitOfWork>(); AddDI(services); AddMediatr(_container, typeof(TeamRegistered).Assembly); _container.Collection.Register(typeof(IRequestPreProcessor <>), new[] { typeof(RequestValidationPreProcessor <>) }); var serviceProvider = services.BuildServiceProvider(); serviceProvider.UseSimpleInjector(_container); _container.Verify(); _scope = AsyncScopedLifestyle.BeginScope(_container); LoggerFactory = _container.GetInstance <ILoggerFactory>(); UnitOfWork = _container.GetInstance <IUnitOfWork>(); Mediator = _container.GetInstance <IMediator>(); QuizrSettings = _container.GetInstance <QuizrSettings>(); var quizCollection = UnitOfWork.GetCollection <Quiz>(); var userCollection = UnitOfWork.GetCollection <User>(); var teamCollection = UnitOfWork.GetCollection <Team>(); var gameCollection = UnitOfWork.GetCollection <Game>(); var questionCollection = UnitOfWork.GetCollection <QuizItem>(); Users = TestUsers.GetUsers(); Quiz = TestQuiz.GetQuiz(); Game = TestGame.GetGame(Users.Where(u => u.UserName == "Quiz master 1").Select(u => u.Id), Quiz); Users.First(u => u.UserName == "Quiz master 1").GameIds.Add(Game.Id); Users.First(u => u.UserName == "Quiz master 1").QuizIds.Add(Quiz.Id); Teams = TestTeams.GetTeams(teamCollection, Game.Id); Game.QuizId = Quiz.Id; Game.TeamIds = Teams.Select(t => t.Id).ToList(); QuestionsInQuiz = TestQuiz.GetQuizItems(); OtherQuestions = new List <QuizItem> { new QuizItem(), new QuizItem(), new QuizItem() }; Task.WaitAll( quizCollection.AddAsync(Quiz), QuestionsInQuiz.ToAsyncEnumerable().ForEachAsync(q => questionCollection.AddAsync(q)), OtherQuestions.ToAsyncEnumerable().ForEachAsync(q => questionCollection.AddAsync(q)), Teams.ToAsyncEnumerable().ForEachAsync(t => teamCollection.AddAsync(t)), Users.ToAsyncEnumerable().ForEachAsync(u => userCollection.AddAsync(u)), gameCollection.AddAsync(Game)); }