Beispiel #1
0
        public void TestNewQuestionCheckAnswerAndGetSummary()
        {
            var testSm = new QuestionSessionManager(new TestWeirdDatabase());



            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(i < 5);
                var question = testSm.GetNewQuestion();

                if (i == 0)
                {
                    var questionAnswer = testSm.CheckAnswer(question.Id, 2);
                    Assert.AreEqual(questionAnswer.IsCorrect, false);
                    Assert.AreEqual(questionAnswer.Explanation, "One plus one is two");
                }


                if (i == 1)
                {
                    var questionAnswer = testSm.CheckAnswer(question.Id, 2);
                    Assert.AreEqual(questionAnswer.IsCorrect, false);
                    Assert.AreEqual(questionAnswer.Explanation, "(often be absorbed in) take up the attention of(someone); interest greatly");
                }

                if (i == 2)
                {
                    var questionAnswer = testSm.CheckAnswer(question.Id, 2);
                    Assert.AreEqual(questionAnswer.IsCorrect, true);
                    Assert.AreEqual(questionAnswer.Explanation, "Accuse of");
                }


                if (i == 3)
                {
                    var questionAnswer = testSm.CheckAnswer(question.Id, 2);
                    Assert.AreEqual(questionAnswer.IsCorrect, true);
                    Assert.AreEqual(questionAnswer.Explanation, "“It’s” is only ever used when short for “it is”. “Its” indicates something belonging to something that isn’t masculine or feminine (like “his” and “hers”, but used when you’re not talking about a person).");
                }



                if (question.IsLastQuestion)
                {
                    var questionSummary = testSm.GetSummary();
                    Assert.AreEqual(questionSummary.TotalQuestions, 4);
                    Assert.AreEqual(questionSummary.CorrectQuestions, 2);
                    break;
                }
            }
        }
Beispiel #2
0
        public QuestionPage(IWeirdDatabase database)
        {
            _testSm = new QuestionSessionManager(database);

            _header = new Label
            {
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                FontAttributes    = FontAttributes.None,
                HorizontalOptions = LayoutOptions.Center,
                FontFamily        = FontFamily,
                Margin            = 5,
                TextColor         = Color.FromHex("#373a3c")
            };



            var relativeLayout = new RelativeLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.FromHex("#f9f9f9"),
                //TODO does not work ... Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5)
            };

            relativeLayout.Children.Add(_header, Constraint.RelativeToParent((parent) => { return(0); }));


            _contentView = new ContentView();


            _stackLayout = new StackLayout
            {
                Spacing           = 10,
                HorizontalOptions =
                    LayoutOptions.FillAndExpand,
                Padding = new Thickness(5, 5, 5, 5)
            };


            _button = new Button
            {
                Text        = "Check",
                Font        = Font.SystemFontOfSize(NamedSize.Large),
                BorderWidth = 1,
                IsEnabled   = false,
            };

            _button.Clicked += OnButtonClicked;

            relativeLayout.Children.Add(_button,
                                        Constraint.RelativeToParent((parent) => { return(5); }),
                                        Constraint.RelativeToParent((parent) => { return(parent.Height - 50); }),
                                        Constraint.RelativeToParent((parent) => { return(parent.Width - 10); })
                                        );

            relativeLayout.Children.Add(
                _stackLayout,
                Constraint.RelativeToView(_header, (parent, sibling) => { return(10); }),
                Constraint.RelativeToView(_header, (parent, sibling) => { return(sibling.Height + 30); }),
                Constraint.RelativeToParent((parent) => { return(parent.Width - 20); })
                );


            _contentViewContent = new Label {
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
            };
            //Label... no padding!!!

            _contentView.Content          = _contentViewContent;
            _contentViewContent.IsVisible = false;

            //var parentContainer = (RelativeLayout)Content;


            relativeLayout.Children.Add(_contentView,
                                        Constraint.RelativeToParent((parent) => { return(0); }),
                                        Constraint.RelativeToParent((parent) => { return(parent.Height / 3); }),
                                        Constraint.RelativeToParent((parent) => { return(parent.Width - 20); }),
                                        Constraint.RelativeToParent((parent) => { return(parent.Height / 3); }));


            this.Content = relativeLayout;
            LoadQuestion();
        }