Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseBreakWaterPropertiesTest.cs =================================================================== diff -u -rbb80820ff4a4e09793da242cb7b36ca2bce59c32 -r7918a30f6ddc1ba9067a5eb461a1d7a8cb5bc8a0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseBreakWaterPropertiesTest.cs (.../UseBreakWaterPropertiesTest.cs) (revision bb80820ff4a4e09793da242cb7b36ca2bce59c32) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseBreakWaterPropertiesTest.cs (.../UseBreakWaterPropertiesTest.cs) (revision 7918a30f6ddc1ba9067a5eb461a1d7a8cb5bc8a0) @@ -98,20 +98,13 @@ public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() { // Setup - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(3); - mockRepository.ReplayAll(); - var breakWater = new BreakWater(BreakWaterType.Caisson, 2.2); var testUseBreakWater = new TestUseBreakWater { BreakWater = breakWater }; var properties = new UseBreakWaterProperties(testUseBreakWater, new TestCalculation()); - testUseBreakWater.Attach(observerMock); - // Call properties.UseBreakWater = true; properties.BreakWaterType = BreakWaterType.Dam; @@ -122,10 +115,33 @@ Assert.AreEqual(BreakWaterType.Dam, properties.BreakWaterType); Assert.AreEqual(1.1, properties.BreakWaterHeight, properties.BreakWaterHeight.GetAccuracy()); Assert.AreEqual(string.Empty, properties.ToString()); - mockRepository.VerifyAll(); } [Test] + [TestCase(true)] + [TestCase(false)] + public void DikeHeight_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput(bool hasOutput) + { + SetPropertyAndVerifyNotifcationsAndOutput(hasOutput, properties => properties.BreakWaterHeight = new Random(21).NextRoundedDouble()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void BreakWaterType_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput(bool hasOutput) + { + SetPropertyAndVerifyNotifcationsAndOutput(hasOutput, properties => properties.BreakWaterType = new Random(21).NextEnumValue()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void UseBreakWater_WithOrWithoutOutput_HasOutputFalseInputNotifiedAndCalculationNotifiedWhenHadOutput(bool hasOutput) + { + SetPropertyAndVerifyNotifcationsAndOutput(hasOutput, properties => properties.UseBreakWater = new Random(21).NextBoolean()); + } + + [Test] public void DefaultConstructor_Always_ReadOnlyProperties() { // Call @@ -213,5 +229,40 @@ public bool UseBreakWater { get; set; } public BreakWater BreakWater { get; set; } } + + private void SetPropertyAndVerifyNotifcationsAndOutput( + bool hasOutput, + Action setProperty) + { + // Setup + var mocks = new MockRepository(); + var calculationObserver = mocks.StrictMock(); + var inputObserver = mocks.StrictMock(); + int numberOfChangedProperties = hasOutput ? 1 : 0; + calculationObserver.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties); + inputObserver.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var calculation = new TestCalculation(); + if (hasOutput) + { + calculation.Output = new object(); + } + + calculation.Attach(calculationObserver); + var input = new TestUseBreakWater(); + input.Attach(inputObserver); + input.BreakWater = new BreakWater(BreakWaterType.Caisson, 3.2); + + var properties = new UseBreakWaterProperties(input, calculation); + + // Call + setProperty(properties); + + // Assert + Assert.IsFalse(calculation.HasOutput); + + mocks.VerifyAll(); + } } } \ No newline at end of file