예제 #1
0
        public void Should_Validate_To_Invalid()
        {
            using (StringWriter output = new StringWriter()) {
                using (StringReader input = new StringReader("")) {
                    // arrange
                    Mock <IUserTerminal> mock_user_terminal = new Mock <IUserTerminal>( );
                    mock_user_terminal.SetupGet(x => x.Printer).Returns(output);
                    mock_user_terminal.SetupGet(x => x.Scanner).Returns(input);

                    Mock <IQuestionnaire> mock_questionnaire = new Mock <IQuestionnaire>( );
                    mock_questionnaire.SetupGet(x => x.Terminal).Returns(mock_user_terminal.Object);
                    mock_questionnaire.SetupGet(x => x.Settings).Returns(new QuestionnaireSetting());

                    MockQuestion mockQuestion = new MockQuestion("some questions", mock_questionnaire.Object)
                    {
                        ErrorMessage = "some error message"
                    };

                    mockQuestion.Validator((q) => q.Answer != null, "some error message");

                    mockQuestion.Ask();

                    Assert.Equal(QuestionStates.Invalid, mockQuestion.State);
                }
            }
        }
예제 #2
0
        public void should_not_call_onFinish_when_validation_fails()
        {
            using (StringWriter output = new StringWriter()) {
                using (StringReader input = new StringReader("sss")) {
                    // arrange
                    Mock <IUserTerminal> mock_user_terminal = new Mock <IUserTerminal>( );
                    mock_user_terminal.SetupGet(x => x.Printer).Returns(output);
                    mock_user_terminal.SetupGet(x => x.Scanner).Returns(input);

                    Mock <IQuestionnaire> mock_questionnaire = new Mock <IQuestionnaire>( );
                    mock_questionnaire.SetupGet(x => x.Terminal).Returns(mock_user_terminal.Object);
                    mock_questionnaire.SetupGet(x => x.Settings).Returns(new QuestionnaireSetting());

                    MockQuestion mockQuestion = new MockQuestion("some questions", mock_questionnaire.Object)
                    {
                        ErrorMessage = "some error message"
                    };

                    mockQuestion.Validator(x => false, "some error message");

                    // act
                    bool isFinishMethodCalled = false;
                    mockQuestion.Finish((q) => {
                        isFinishMethodCalled = true;
                    });
                    mockQuestion.Ask();

                    // assert
                    Assert.Equal(QuestionStates.Invalid, mockQuestion.State);
                    Assert.False(isFinishMethodCalled);
                }
            }
        }
예제 #3
0
        public void A_Null_validator_should_fail()
        {
            // arrange
            Mock <IQuestionnaire> mock_questionnaire = new Mock <IQuestionnaire>( );

            string       text     = "What's your name?";
            MockQuestion question = new MockQuestion(text, mock_questionnaire.Object);

            // assert
            Assert.Throws <ArgumentNullException>(() => {
                // act
                question.Validator(null, "Invalid");
            });
        }