public void SetPropertyValueAfterConfirmation_ConfirmationRequiredAndGivenExceptionInSetValue_ExceptionBubbled()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            ICalculation calculation = CalculationTestDataFactory.CreateCalculationWithOutput();

            var changeHandler     = new ObservablePropertyChangeHandler(calculation, new TestCalculationInput());
            var expectedException = new Exception();

            // Call
            TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation(() =>
            {
                throw expectedException;
            });

            // Assert
            var exception = Assert.Throws <Exception>(test);

            Assert.AreSame(expectedException, exception);
        }
        public void SetPropertyValueAfterConfirmation_ConfirmationRequiredButNotGiven_SetValueNotCalledNoAffectedObjectsReturned()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickCancel();
            };

            ICalculation calculation = CalculationTestDataFactory.CreateCalculationWithOutput();

            var propertySet = 0;

            var changeHandler = new ObservablePropertyChangeHandler(calculation, new TestCalculationInput());

            // Precondition
            Assert.IsTrue(calculation.HasOutput);

            // Call
            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(() => propertySet++);

            // Assert
            Assert.AreEqual(0, propertySet);
            CollectionAssert.IsEmpty(affectedObjects);
            Assert.IsTrue(calculation.HasOutput);
        }
        public void RequireConfirmation_CalculationsWithOutput_ReturnTrue()
        {
            // Setup
            var mockRepository = new MockRepository();
            var inquiryHandler = mockRepository.StrictMock <IInquiryHelper>();

            mockRepository.ReplayAll();

            ICalculation[] calculations =
            {
                CalculationTestDataFactory.CreateCalculationWithOutput(),
                CalculationTestDataFactory.CreateCalculationWithoutOutput()
            };

            var handler = new CalculationChangeHandler(calculations,
                                                       string.Empty,
                                                       inquiryHandler);

            // Call
            bool requireConfirmation = handler.RequireConfirmation();

            // Assert
            Assert.IsTrue(requireConfirmation);
            mockRepository.VerifyAll();
        }
        public void SetPropertyValueAfterConfirmation_ConfirmationRequiredAndGivenExceptionInSetValue_ExceptionBubbled()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickOk();
            };

            var testFailureMechanism = new TestCalculatableFailureMechanism(
                new[]
            {
                CalculationTestDataFactory.CreateCalculationWithOutput()
            });

            var changeHandler     = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();
            var expectedException = new Exception();

            // Call
            void Call() =>
            changeHandler.SetPropertyValueAfterConfirmation(testFailureMechanism, 3, (f, v) =>
            {
                throw expectedException;
            });

            // Assert
            var exception = Assert.Throws <Exception>(Call);

            Assert.AreSame(expectedException, exception);
        }
        public void SetPropertyValueAfterConfirmation_ConfirmationRequiredButNotGiven_SetValueNotCalledNoAffectedObjectsReturned()
        {
            // Setup
            DialogBoxHandler = (name, wnd) =>
            {
                var tester = new MessageBoxTester(wnd);
                tester.ClickCancel();
            };

            ICalculation calculationWithOutput    = CalculationTestDataFactory.CreateCalculationWithOutput();
            ICalculation calculationWithoutOutput = CalculationTestDataFactory.CreateCalculationWithoutOutput();

            var testFailureMechanism = new TestCalculatableFailureMechanism(
                new[]
            {
                calculationWithOutput,
                calculationWithoutOutput
            });
            var propertySet = 0;

            var changeHandler = new FailureMechanismPropertyChangeHandler <ICalculatableFailureMechanism>();

            // Call
            IEnumerable <IObservable> affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
                testFailureMechanism,
                3,
                (f, v) => propertySet++);

            // Assert
            Assert.AreEqual(0, propertySet);
            CollectionAssert.IsEmpty(affectedObjects);
            Assert.IsTrue(calculationWithOutput.HasOutput);
        }
        private static IEnumerable ChangePropertyTestCases()
        {
            yield return(new TestCaseData(
                             new ChangePropertyTestCase(CalculationTestDataFactory.CreateCalculationWithOutput())
                             ).SetName("SetPropertyValueAfterConfirmation calculation with output"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(CalculationTestDataFactory.CreateCalculationWithoutOutput())
                             ).SetName("SetPropertyValueAfterConfirmation calculation without output"));
        }
        private static IEnumerable ChangePropertyTestCases()
        {
            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new TestCalculation[0])
                             ).SetName("SetPropertyValueAfterConfirmation No calculations"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new[]
            {
                CalculationTestDataFactory.CreateCalculationWithOutput()
            })
                             ).SetName("SetPropertyValueAfterConfirmation Single calculation with output"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new[]
            {
                CalculationTestDataFactory.CreateCalculationWithoutOutput()
            })
                             ).SetName("SetPropertyValueAfterConfirmation Single calculation without output"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new[]
            {
                CalculationTestDataFactory.CreateCalculationWithoutOutput(),
                CalculationTestDataFactory.CreateCalculationWithoutOutput()
            })
                             ).SetName("SetPropertyValueAfterConfirmation Two calculations without output"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new[]
            {
                CalculationTestDataFactory.CreateCalculationWithOutput(),
                CalculationTestDataFactory.CreateCalculationWithoutOutput()
            })
                             ).SetName("SetPropertyValueAfterConfirmation Calculation without and calculation with output"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new[]
            {
                CalculationTestDataFactory.CreateCalculationWithOutput(),
                CalculationTestDataFactory.CreateCalculationWithOutput()
            })
                             ).SetName("SetPropertyValueAfterConfirmation Two calculations with output"));

            yield return(new TestCaseData(
                             new ChangePropertyTestCase(new[]
            {
                CalculationTestDataFactory.CreateCalculationWithOutput(),
                CalculationTestDataFactory.CreateCalculationWithOutput(),
                CalculationTestDataFactory.CreateCalculationWithoutOutput()
            })
                             ).SetName("SetPropertyValueAfterConfirmation Two calculations with and one calculation without output"));
        }