public void Test_Constructor() { //---------------Set up test pack------------------- const string message = "Confirmer message"; const DialogResult dialogResultToReturn = DialogResult.Yes; string title = TestUtil.GetRandomString(); MessageBoxIcon messageBoxIcon = MessageBoxIcon.None; MockRepository mockRepository = new MockRepository(); IControlFactory controlFactory = SetupControlFactoryMockWithExpectation(mockRepository, message, title, messageBoxIcon, dialogResultToReturn); //-------------Assert Preconditions ------------- //---------------Execute Test ---------------------- MessageBoxConfirmer messageBoxConfirmer = new MessageBoxConfirmer(controlFactory, title, messageBoxIcon); //---------------Test Result ----------------------- Assert.IsInstanceOf(typeof(IConfirmer), messageBoxConfirmer); Assert.AreSame(controlFactory, messageBoxConfirmer.ControlFactory); Assert.AreEqual(title, messageBoxConfirmer.Title); Assert.AreEqual(messageBoxIcon, messageBoxConfirmer.MessageBoxIcon); }
public void Test_Confirm_True() { //---------------Set up test pack------------------- const string message = "Confirmer message"; const string title = "MessageBoxTitle"; const DialogResult dialogResultToReturn = DialogResult.Yes; MessageBoxIcon messageBoxIcon = TestUtil.GetRandomEnum<MessageBoxIcon>(); MockRepository mockRepository = new MockRepository(); IControlFactory controlFactory = SetupControlFactoryMockWithExpectation(mockRepository, message, title, messageBoxIcon, dialogResultToReturn); MessageBoxConfirmer messageBoxConfirmer = new MessageBoxConfirmer(controlFactory, title, messageBoxIcon); mockRepository.ReplayAll(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- bool confirmResult = messageBoxConfirmer.Confirm(message); //---------------Test Result ----------------------- Assert.IsTrue(confirmResult); mockRepository.VerifyAll(); }
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(); }