Esempio n. 1
0
        public void Add_FinishedPressedWhenOnPage1NoQuestionAdded_ReturnInvalidModelstate()
        {
            //Arrange
            var mockHttpContext = new Mock <IHttpContextAccessor>();

            mockHttpContext.Setup(x => x.HttpContext.Session).Returns(new MyTestSession()
            {
                Id = "abba1", IsAvailable = true
            });
            IUserManagerWrapper fakeUserManagerRepository = new FakeUserManagerRepository();
            var inMemoryDatabase = InMemoryDatabase.GetContextFromInMemoryDatabase();
            CreateQuestionsController createQuestionsController = new CreateQuestionsController(fakeUserManagerRepository, new EFQuestionRepository(inMemoryDatabase), mockHttpContext.Object);

            List <NewQuestionVM> list = new List <NewQuestionVM>();

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuestionsList", list); //storing a list of empty NewQuestionVM objects in teh session object
            NewQuestionVM question = new NewQuestionVM();

            //Act
            NewQuestionVM newQuestion = new NewQuestionVM();

            createQuestionsController.ButtonFinished(question, newQuestion);

            //Assert
            Assert.False(createQuestionsController.ModelState.IsValid);
        }
Esempio n. 2
0
        public void Add_FinishedPressedWhenOnPage1NoQuestionAdded_GoTo()
        {
            //Arrange
            var mockHttpContext = new Mock <IHttpContextAccessor>();

            mockHttpContext.Setup(x => x.HttpContext.Session).Returns(new MyTestSession()
            {
                Id = "abba1", IsAvailable = true
            });
            IUserManagerWrapper fakeUserManagerRepository = new FakeUserManagerRepository();
            var inMemoryDatabase = InMemoryDatabase.GetContextFromInMemoryDatabase();
            CreateQuestionsController createQuestionsController = new CreateQuestionsController(fakeUserManagerRepository, new EFQuestionRepository(inMemoryDatabase), mockHttpContext.Object);

            List <NewQuestionVM> list = new List <NewQuestionVM>();

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuestionsList", list); //storing a list of empty NewQuestionVM objects in teh session object
            NewQuestionVM question = new NewQuestionVM()
            {
                QuestionNr = 1,
                Answer1    = "",
                Answer2    = "",
                Answer3    = "A3",
                Answer4    = "",
                RadioButtonAlternativeAnswer = 1,
                QuestionString = "Test"
            };

            //Act
            NewQuestionVM newQuestion = new NewQuestionVM();
            var           result      = createQuestionsController.ButtonFinished(question, newQuestion) as ViewResult;

            //Assert
            Assert.Equal("Add", result.ViewName);
        }
Esempio n. 3
0
        public void Add_FinishedPressedWhenOnPage1AndOnlyQuestion1IsEnteredCorrectly_StoreToInMemoryDb()
        {
            //Arrange
            var mockHttpContext = new Mock <IHttpContextAccessor>();

            mockHttpContext.Setup(x => x.HttpContext.Session).Returns(new MyTestSession()
            {
                Id = "abba1", IsAvailable = true
            });
            IUserManagerWrapper fakeUserManagerRepository = new FakeUserManagerRepository();
            var inMemoryDatabase = InMemoryDatabase.GetContextFromInMemoryDatabase();
            CreateQuestionsController createQuestionsController = new CreateQuestionsController(fakeUserManagerRepository, new EFQuestionRepository(inMemoryDatabase), mockHttpContext.Object);

            AddNewQuizVM addNewQuizVM = new AddNewQuizVM {
                QuizId = 1, QuizName = "TestQuiz", UserId = "UserId-GUID"
            };

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuizId", addNewQuizVM);
            inMemoryDatabase.Quizzes.Add(new Quiz {
                QuizId = addNewQuizVM.QuizId, QuizName = addNewQuizVM.QuizName, UserId = addNewQuizVM.UserId
            });
            inMemoryDatabase.SaveChanges();


            List <NewQuestionVM> list = new List <NewQuestionVM>();

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuestionsList", list); //storing a list of empty NewQuestionVM objects in teh session object
            NewQuestionVM question = new NewQuestionVM()                                                             // filling the list
            {
                QuestionNr = 1,
                Answer1    = "A1",
                Answer2    = "A2",
                Answer3    = "A3",
                Answer4    = "A4",
                RadioButtonAlternativeAnswer = 3,
                QuestionString = "Test"
            };

            list.Add(question);

            //Act
            NewQuestionVM newQuestion = new NewQuestionVM();

            createQuestionsController.ButtonFinished(question, newQuestion);
            var result = inMemoryDatabase.Questions.FirstOrDefault();

            //Assert
            Assert.Equal(question.QuestionNr, result.QuestionNr);
            Assert.Equal(question.Answer1, result.Answers.ElementAt(0).AnswerText);
            Assert.Equal(question.Answer2, result.Answers.ElementAt(1).AnswerText);
            Assert.Equal(question.Answer3, result.Answers.ElementAt(2).AnswerText);
            Assert.Equal(question.Answer4, result.Answers.ElementAt(3).AnswerText);
            Assert.Equal(question.RadioButtonAlternativeAnswer, result.RadioButtonAlternativeAnswer);
            Assert.Equal(question.QuestionString, result.QuestionString);
        }
Esempio n. 4
0
        private CreateQuestionsController setupBeforeTestWithFakeDb()
        {
            var mockHttpContext = new Mock <IHttpContextAccessor>();

            mockHttpContext.Setup(x => x.HttpContext.Session).Returns(new MyTestSession()
            {
                Id = "abba1", IsAvailable = true
            });
            IUserManagerWrapper fakeUserManagerRepository = new FakeUserManagerRepository();

            inMemoryDatabase = InMemoryDatabase.GetContextFromInMemoryDatabase();
            return(new CreateQuestionsController(fakeUserManagerRepository, new EFQuestionRepository(inMemoryDatabase), mockHttpContext.Object));
        }
Esempio n. 5
0
        public void Add_XXXXXXFinishedPressedWhenOnPage1TwoQuestionsAddedInSessionAndFormFilledWithValidData_StoreToInMemoryDb()
        {
            //Arrange
            var mockHttpContext = new Mock <IHttpContextAccessor>();

            mockHttpContext.Setup(x => x.HttpContext.Session).Returns(new MyTestSession()
            {
                Id = "abba1", IsAvailable = true
            });
            IUserManagerWrapper fakeUserManagerRepository = new FakeUserManagerRepository();
            var inMemoryDatabase = InMemoryDatabase.GetContextFromInMemoryDatabase();
            CreateQuestionsController createQuestionsController = new CreateQuestionsController(fakeUserManagerRepository, new EFQuestionRepository(inMemoryDatabase), mockHttpContext.Object);

            AddNewQuizVM addNewQuizVM = new AddNewQuizVM {
                QuizId = 1, QuizName = "TestQuiz", UserId = "UserId-GUID"
            };

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuizId", addNewQuizVM);
            inMemoryDatabase.Quizzes.Add(new Quiz {
                QuizId = addNewQuizVM.QuizId, QuizName = addNewQuizVM.QuizName, UserId = addNewQuizVM.UserId
            });
            inMemoryDatabase.SaveChanges();

            List <NewQuestionVM> list = new List <NewQuestionVM>();

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuestionsList", list); //storing a list of empty NewQuestionVM objects in teh session object


            NewQuestionVM question = new NewQuestionVM() // filling the list
            {
                QuestionNr = 1,
                Answer1    = "A1",
                Answer2    = "A2",
                Answer3    = "A3",
                Answer4    = "A4",
                RadioButtonAlternativeAnswer = 3,
                QuestionString = "Test"
            };

            list.Add(question);

            question = new NewQuestionVM() // filling the list
            {
                QuestionNr = 2,
                Answer1    = "A1-2",
                Answer2    = "A2-2",
                Answer3    = "A3-2",
                Answer4    = "A4-2",
                RadioButtonAlternativeAnswer = 2,
                QuestionString = "Test2"
            };
            list.Add(question);

            createQuestionsController.MyContextAccessor.HttpContext.Session.SetJson("CreateNewQuestionsList", list); //storing a list of empty NewQuestionVM objects in teh session object

            NewQuestionVM question2 = new NewQuestionVM()                                                            // filling the list
            {
                QuestionNr = 1,
                Answer1    = "A1-1",
                Answer2    = "A2-1",
                Answer3    = "A3",
                Answer4    = "A4",
                RadioButtonAlternativeAnswer = 3,
                QuestionString = "Test"
            };

            //Act
            NewQuestionVM newQuestion = new NewQuestionVM();

            createQuestionsController.ButtonFinished(question2, newQuestion);
            var result = inMemoryDatabase.Questions.Count();

            //Assert
            Assert.Equal(2, result);
        }
Esempio n. 6
0
        public GameController setupBeforeTests()
        {
            //Arrange

            var mockHttpContext = new Mock <IHttpContextAccessor>();

            mockHttpContext.Setup(x => x.HttpContext.Session).Returns(new MyTestSession()
            {
                Id = "abba1", IsAvailable = true
            });
            var            inMemoryDatabase = InMemoryDatabase.GetContextFromInMemoryDatabase();
            GameController gameController   = new GameController(new EFQuestionRepository(inMemoryDatabase), mockHttpContext.Object);

            if (!inMemoryDatabase.Questions.Any())
            {
                var question1 = new Question
                {
                    QuestionNr     = 1,
                    QuestionString = "(inMemoryDatabase)Når begynte de første norske prøvesendingene med fjernsyn?",
                    RadioButtonAlternativeAnswer = 2,
                    Answers = new List <Answer> {
                        new  Answer {
                            AnswerText = "1949"
                        },
                        new  Answer {
                            AnswerText = "1954"
                        },
                        new  Answer {
                            AnswerText = "1958"
                        }
                    }
                };

                var question2 = new Question
                {
                    QuestionNr     = 2,
                    QuestionString = "(inMemoryDatabase)Når startet TV2 sine sendinger?",
                    RadioButtonAlternativeAnswer = 1,
                    Answers = new List <Answer> {
                        new  Answer {
                            AnswerText = "1992"
                        },
                        new  Answer {
                            AnswerText = "1994"
                        },
                        new  Answer {
                            AnswerText = "1995"
                        }
                    }
                };


                var question3 = new Question
                {
                    QuestionNr     = 3,
                    QuestionString = "(inMemoryDatabase)Hvem spilte Derrick i TV-serien med samme navn?",
                    RadioButtonAlternativeAnswer = 3,
                    Answers = new List <Answer> {
                        new  Answer {
                            AnswerText = "Peter Falk"
                        },
                        new  Answer {
                            AnswerText = "James Hed"
                        },
                        new  Answer {
                            AnswerText = "Horst Tappert"
                        }
                    }
                };

                var question4 = new Question
                {
                    QuestionNr     = 4,
                    QuestionString = "(inMemoryDatabase)Hva het kaféverten i 'Allo 'allo?",
                    RadioButtonAlternativeAnswer = 1,
                    Answers = new List <Answer> {
                        new  Answer {
                            AnswerText = "Renè"
                        },
                        new  Answer {
                            AnswerText = "Manuel"
                        },
                        new  Answer {
                            AnswerText = "Hercules"
                        }
                    }
                };

                var question5 = new Question
                {
                    QuestionNr     = 5,
                    QuestionString = "(inMemoryDatabase)Hva het Fleksnes til fornavn?",
                    RadioButtonAlternativeAnswer = 1,
                    Answers = new List <Answer> {
                        new  Answer {
                            AnswerText = "Marve"
                        },
                        new  Answer {
                            AnswerText = "Anton"
                        },
                        new  Answer {
                            AnswerText = "Kurt"
                        }
                    }
                };


                inMemoryDatabase.AddRange(question1, question2, question3, question4, question5);
                inMemoryDatabase.SaveChanges();
            }

            int page_nr                   = 1;
            int numberOfQuestions         = inMemoryDatabase.Questions.Count();
            List <ShowQuestionsVM> ListVM = new List <ShowQuestionsVM>();

            foreach (Question q in inMemoryDatabase.Questions)
            {
                ListVM.Add(new ShowQuestionsVM()
                {
                    Page       = page_nr++,
                    QuestionId = q.QuestionNr,
                    TotalPages = numberOfQuestions,
                    RadioButtonChosenAlternativeAnswer = null,
                    QuestionString = q.QuestionString,
                    ListOfAnswers  = q.Answers
                });
            }
            gameController.MyContextAccessor.HttpContext.Session.SetJson("ListWithAllQuestionsAndAnswers", ListVM);
            int?[] ChosenAlternativeAnswer = new int?[numberOfQuestions + 1];
            gameController.MyContextAccessor.HttpContext.Session.SetJson("ListWithChosenAlternativeAnswersForAllQuestions", ChosenAlternativeAnswer);

            return(gameController);
        }