public void AddChoices_Must_Return_List_Of_Answers_Of_Given_Problem()
        {
            // Arrange
            var db           = StaticMethods.GetDb();
            var service      = new ProblemsService(db, mapper);
            var addProblemBM = GetTestAddProblemBM();
            // Act
            var addedProblem = service.AddProblem(addProblemBM);
            var choices      = service.AddChoices(addProblemBM, addedProblem);

            // Assert
            Assert.True(choices.Count == 4);

            Assert.True(choices[0].GameProblemId == addedProblem.Id);
            Assert.True(choices[0].Content == Answer.A);

            Assert.True(choices[1].GameProblemId == addedProblem.Id);
            Assert.True(choices[1].Content == Answer.B);

            Assert.True(choices[2].GameProblemId == addedProblem.Id);
            Assert.True(choices[2].Content == Answer.C);

            Assert.True(choices[3].GameProblemId == addedProblem.Id);
            Assert.True(choices[3].Content == Answer.D);
        }
        public void GetRandomProblem_Must_Return_Random_ProblemDetailViewModel()
        {
            // Arrange
            var db            = StaticMethods.GetDb();
            var service       = new ProblemsService(db, mapper);
            var addProblemBM1 = GetTestAddProblemBM();
            var addProblemBM2 = GetTestAddProblemBM();
            var addProblemBM3 = GetTestAddProblemBM();
            var addProblemBM4 = GetTestAddProblemBM();
            // Act
            var addedBM1 = service.AddProblem(addProblemBM1);
            var addedBM2 = service.AddProblem(addProblemBM1);
            var addedBM3 = service.AddProblem(addProblemBM1);
            var addedBM4 = service.AddProblem(addProblemBM1);
            var result   = service.GetRandomProblem();

            //Assert
            Assert.True(result != null);
            Assert.True(db.GameProblems.Any(x => x.Id == result.Id));
        }
        public void GetAllProblemsViewModel_Must_Return_ViewModel()
        {
            // Arrange
            var db            = StaticMethods.GetDb();
            var service       = new ProblemsService(db, mapper);
            var addProblemBM1 = GetTestAddProblemBM();
            var addProblemBM2 = GetTestAddProblemBM();
            var addProblemBM3 = GetTestAddProblemBM();
            var addProblemBM4 = GetTestAddProblemBM();
            // Act
            var addedBM1 = service.AddProblem(addProblemBM1);
            var addedBM2 = service.AddProblem(addProblemBM1);
            var addedBM3 = service.AddProblem(addProblemBM1);
            var addedBM4 = service.AddProblem(addProblemBM1);
            var result   = service.GetAllProblemsViewModel();

            //Assert
            Assert.True(result.GameProblems.Count == 4);
            Assert.True(result.GameProblems.All(x => x != null));
        }
        public void AddProblem_Must_Return_Created_Problem()
        {
            // Arrange
            var db           = StaticMethods.GetDb();
            var service      = new ProblemsService(db, mapper);
            var addProblemBM = GetTestAddProblemBM();
            // Act
            var result          = service.AddProblem(addProblemBM);
            var testRightAnswer = service.GetRightAnswerString(addProblemBM);

            //Assert
            Assert.True(result.ProblemContent == addProblemBM.Content);
            Assert.True(result.RightAnswer == testRightAnswer);
            Assert.True(result.Choices.Count == 4);
        }
        public void AddChoice_Must_Return_Created_Choice()
        {
            // Arrange
            var db            = StaticMethods.GetDb();
            var service       = new ProblemsService(db, mapper);
            var addProblemBM  = GetTestAddProblemBM();
            var choiceContent = GetTestContent;
            // Act
            var addedProblem = service.AddProblem(addProblemBM);
            var result       = service.AddChoice(choiceContent, addedProblem);

            //Assert
            Assert.True(result.Content == choiceContent);
            Assert.True(result.GameProblemId == addedProblem.Id);
        }
        public void EditProblem_Must_Return_Edited_Problem()
        {
            // Arrange
            var db           = StaticMethods.GetDb();
            var service      = new ProblemsService(db, mapper);
            var rightAnswer  = ChoiceEnum.A;
            var addProblemBM = GetTestAddProblemBM(rightAnswer);

            // Act
            var addedProblem  = service.AddProblem(addProblemBM);
            var editProblemBM = service.GetEditProblemBindingModel(addedProblem.Id);

            editProblemBM.Content     = "Testing...";
            editProblemBM.AnswerA     = "nice";
            editProblemBM.AnswerB     = "not this";
            editProblemBM.AnswerC     = "THIS IS";
            editProblemBM.AnswerD     = "NoNoNo";
            editProblemBM.RightAnswer = ChoiceEnum.C;

            var result       = service.EditProblem(editProblemBM);
            var resultAnswer = service.GetRightAnswerString(editProblemBM);

            //Assert
            // Testing problem
            Assert.True(result.Id == editProblemBM.Id);
            Assert.True(result.ProblemContent == editProblemBM.Content);
            Assert.True(result.RightAnswer == resultAnswer);

            // Testing AnswerA
            Assert.True(result.Choices[0].Id == addedProblem.Choices[0].Id);
            Assert.True(result.Choices[0].Content == addedProblem.Choices[0].Content);
            Assert.True(result.Choices[0].GameProblemId == addedProblem.Id);

            // Testing AnswerB
            Assert.True(result.Choices[1].Id == addedProblem.Choices[1].Id);
            Assert.True(result.Choices[1].Content == addedProblem.Choices[1].Content);
            Assert.True(result.Choices[1].GameProblemId == addedProblem.Id);

            // Testing AnswerC
            Assert.True(result.Choices[2].Id == addedProblem.Choices[2].Id);
            Assert.True(result.Choices[2].Content == addedProblem.Choices[2].Content);
            Assert.True(result.Choices[2].GameProblemId == addedProblem.Id);

            // Testing AnswerD
            Assert.True(result.Choices[3].Id == addedProblem.Choices[3].Id);
            Assert.True(result.Choices[3].Content == addedProblem.Choices[3].Content);
            Assert.True(result.Choices[3].GameProblemId == addedProblem.Id);
        }
        public void DeleteProblem_Must_Return_Deleted_Problem()
        {
            // Arrange
            var db           = StaticMethods.GetDb();
            var service      = new ProblemsService(db, mapper);
            var addProblemBM = GetTestAddProblemBM();
            // Act
            var addedProblem = service.AddProblem(addProblemBM);
            var result       = service.DeleteProblem(addedProblem.Id);

            //Assert
            Assert.True(result.Id == addedProblem.Id);
            Assert.True(result.ProblemContent == addedProblem.ProblemContent);
            Assert.True(result.RightAnswer == addedProblem.RightAnswer);
            Assert.True(result.Choices.Count == addedProblem.Choices.Count);
        }
        public void GetProblemDetails_Must_Return_ViewModel_With_Given_Id()
        {
            // Arrange
            var db           = StaticMethods.GetDb();
            var service      = new ProblemsService(db, mapper);
            var rightAnswer  = ChoiceEnum.A;
            var addProblemBM = GetTestAddProblemBM(rightAnswer);

            // Act
            var addedProblem = service.AddProblem(addProblemBM);
            var result       = service.GetProblemDetails(addedProblem.Id);

            //Assert
            Assert.True(result.GetType() == typeof(ProblemDetailsViewModel));
            Assert.True(result.Id == addedProblem.Id);
            Assert.True(result.ProblemContent == addedProblem.ProblemContent);
            Assert.True(result.RightAnswer == addedProblem.RightAnswer);
            Assert.True(result.Answers.Count == 3);
        }
        public void GetEditProblemBindingModel_Must_Return_BindingModel_With_Given_Id()
        {
            // Arrange
            var db           = StaticMethods.GetDb();
            var service      = new ProblemsService(db, mapper);
            var rightAnswer  = ChoiceEnum.A;
            var addProblemBM = GetTestAddProblemBM(rightAnswer);

            // Act
            var addedProblem = service.AddProblem(addProblemBM);
            var result       = service.GetEditProblemBindingModel(addedProblem.Id);

            //Assert
            Assert.True(result.GetType() == typeof(EditProblemBindingModel));
            Assert.True(result.Id == addedProblem.Id);
            Assert.True(result.Content == addedProblem.ProblemContent);
            Assert.True(result.RightAnswer == rightAnswer);
            Assert.True(result.AnswerA == Answer.A);
            Assert.True(result.AnswerB == Answer.B);
            Assert.True(result.AnswerC == Answer.C);
            Assert.True(result.AnswerD == Answer.D);
        }