public void ShowQuestionTest()
        {
            var messageService = new MockMessageService();

            var view    = new object();
            var message = "Hello World";
            var format  = "Result: {0}";

            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null !, null, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null !, null, message));

            bool showQuestionCalled = false;

            messageService.ShowQuestionStub = (_, m) =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.ShowQuestionStub = (o, m) =>
            {
                showQuestionCalled = true;
                Assert.AreSame(view, o);
                Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowQuestion(view, format, 42) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionStub = (_, m) =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(message));
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionStub = (o, m) =>
            {
                showQuestionCalled = true;
                Assert.AreSame(view, o);
                Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(view, format, 42));
            Assert.IsTrue(showQuestionCalled);
        }
        public void ShowQuestionTest()
        {
            MockMessageService messageService = new MockMessageService();

            string message = "Hello World";
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null, message));
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null, message));

            bool showQuestionCalled = false;
            messageService.ShowQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return true;
            };
            Assert.IsTrue(messageService.ShowQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return true;
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);
        }
示例#3
0
        public void ShowQuestionTest()
        {
            var messageService = new MockMessageService();

            var message = "Hello World";

            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null !, message));

            bool showQuestionCalled = false;

            messageService.ShowQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(message));
            Assert.IsTrue(showQuestionCalled);
        }