public void Test_Confirm_False_WithDelegate()
        {
            //---------------Set up test pack-------------------
            const string       message = "Confirmer message";
            const string       title   = "MessageBoxTitle";
            const DialogResult dialogResultToReturn = DialogResult.No;
            MessageBoxIcon     messageBoxIcon       = TestUtil.GetRandomEnum <MessageBoxIcon>();

            bool delegateWasCalled                    = false;
            bool confirmedParamInDelegate             = true;
            ConfirmationDelegate confirmationDelegate = delegate(bool confirmed)
            {
                delegateWasCalled        = true;
                confirmedParamInDelegate = confirmed;
            };

            MockRepository  mockRepository = new MockRepository();
            IControlFactory controlFactory = SetupControlFactoryMockWithExpectationWithDelegate(
                mockRepository, message, title, messageBoxIcon, dialogResultToReturn, confirmationDelegate);

            MessageBoxConfirmer messageBoxConfirmer = new MessageBoxConfirmer(controlFactory, title, messageBoxIcon);

            mockRepository.ReplayAll();
            //---------------Assert Precondition----------------
            Assert.IsFalse(delegateWasCalled);
            Assert.IsTrue(confirmedParamInDelegate);
            //---------------Execute Test ----------------------
            messageBoxConfirmer.Confirm(message, confirmationDelegate);
            //---------------Test Result -----------------------
            Assert.IsTrue(delegateWasCalled);
            Assert.IsFalse(confirmedParamInDelegate);
            mockRepository.VerifyAll();
        }
        private IControlFactory SetupControlFactoryMockWithExpectationWithDelegate(
            MockRepository mockRepository, string message, string title,
            MessageBoxIcon messageBoxIcon, DialogResult dialogResultToReturn,
            ConfirmationDelegate confirmationDelegate)
        {
            IControlFactory controlFactory = mockRepository.StrictMock <IControlFactory>();

            controlFactory.Expect(
                factory => factory.ShowMessageBox(null, null, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Asterisk, null))
            .Return(dialogResultToReturn).Constraints(
                Is.Equal(message), Is.Equal(title), Is.Equal(MessageBoxButtons.YesNo),
                Is.Equal(messageBoxIcon), Is.Anything())
            .WhenCalled(invocation => confirmationDelegate(dialogResultToReturn == DialogResult.Yes));
            return(controlFactory);
        }
Ejemplo n.º 3
0
 ///<summary>
 /// Gets confirmation from the user after providing them with an option
 /// and executes the provided delegate once the user has responded.
 ///</summary>
 ///<param name="message">The message to display</param>
 ///<param name="confirmationDelegate">The delegate to execute once the user has responded.</param>
 ///<returns>Returns true if the user confirms the choice and false
 /// if they decline the offer</returns>
 public void Confirm(string message, ConfirmationDelegate confirmationDelegate)
 {
     ControlFactory.ShowMessageBox(
         message, Title, MessageBoxButtons.YesNo, MessageBoxIcon,
         (sender, result) => confirmationDelegate(result == DialogResult.Yes));
 }
 ///<summary>
 /// Gets confirmation from the user after providing them with an option
 /// and executes the provided delegate once the user has responded.
 ///</summary>
 ///<param name="message">The message to display</param>
 ///<param name="confirmationDelegate">The delegate to execute once the user has responded.</param>
 ///<returns>Returns true if the user confirms the choice and false
 /// if they decline the offer</returns>
 public void Confirm(string message, ConfirmationDelegate confirmationDelegate)
 {
     ControlFactory.ShowMessageBox(
         message, Title, MessageBoxButtons.YesNo, MessageBoxIcon,
         (sender, result) => confirmationDelegate(result == DialogResult.Yes));
 }
 public void Confirm(string message, ConfirmationDelegate confirmationDelegate)
 {
     confirmationDelegate(WillBeConfirmed);
 }
 public void Confirm(string message, ConfirmationDelegate confirmationDelegate)
 {
     confirmationDelegate(WillBeConfirmed);
 }
 private IControlFactory SetupControlFactoryMockWithExpectationWithDelegate(
     MockRepository mockRepository, string message, string title,
     MessageBoxIcon messageBoxIcon, DialogResult dialogResultToReturn,
     ConfirmationDelegate confirmationDelegate)
 {
     IControlFactory controlFactory = mockRepository.StrictMock<IControlFactory>();
     controlFactory.Expect(
         factory => factory.ShowMessageBox(null, null, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Asterisk, null))
         .Return(dialogResultToReturn).Constraints(
           Is.Equal(message), Is.Equal(title), Is.Equal(MessageBoxButtons.YesNo),
           Is.Equal(messageBoxIcon), Is.Anything())
         .WhenCalled(invocation => confirmationDelegate(dialogResultToReturn == DialogResult.Yes));
     return controlFactory;
 }