Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/MacroStabilityInwardsCalculatorFactoryConfigTest.cs =================================================================== diff -u -r966dc7335defa901104fd4168d57c08315db2de0 -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/MacroStabilityInwardsCalculatorFactoryConfigTest.cs (.../MacroStabilityInwardsCalculatorFactoryConfigTest.cs) (revision 966dc7335defa901104fd4168d57c08315db2de0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/MacroStabilityInwardsCalculatorFactoryConfigTest.cs (.../MacroStabilityInwardsCalculatorFactoryConfigTest.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -28,31 +28,38 @@ public class MacroStabilityInwardsCalculatorFactoryConfigTest { [Test] - public void Constructor_FactoryNull_ThrowsArgumentNullException() + public void Constructor_NewInstanceCanBeDisposed() { // Call - TestDelegate call = () => new MacroStabilityInwardsCalculatorFactoryConfig(null); + var factory = new MacroStabilityInwardsCalculatorFactoryConfig(); // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("newFactory", exception.ParamName); + Assert.IsInstanceOf(factory); + Assert.DoesNotThrow(() => factory.Dispose()); } [Test] - public void Constructor_WithFactory_InstanceTemporarilyChanged() + public void Constructor_SetsTestFactoryForMacroStabilityInwardsCalculatorFactory() { - // Setup - IMacroStabilityInwardsCalculatorFactory originalInstance = MacroStabilityInwardsCalculatorFactory.Instance; - var factory = new TestMacroStabilityInwardsCalculatorFactory(); - // Call - using (var config = new MacroStabilityInwardsCalculatorFactoryConfig(factory)) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Assert - Assert.IsInstanceOf(config); - Assert.AreSame(factory, MacroStabilityInwardsCalculatorFactory.Instance); + Assert.IsInstanceOf(MacroStabilityInwardsCalculatorFactory.Instance); } - Assert.AreSame(originalInstance, MacroStabilityInwardsCalculatorFactory.Instance); } + + [Test] + public void Dispose_Always_ResetsFactoryToPreviousValue() + { + // Setup + IMacroStabilityInwardsCalculatorFactory expectedFactory = MacroStabilityInwardsCalculatorFactory.Instance; + + // Call + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { } + + // Assert + Assert.AreSame(expectedFactory, MacroStabilityInwardsCalculatorFactory.Instance); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/MacroStabilityInwardsCalculatorFactoryConfig.cs =================================================================== diff -u -r966dc7335defa901104fd4168d57c08315db2de0 -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/MacroStabilityInwardsCalculatorFactoryConfig.cs (.../MacroStabilityInwardsCalculatorFactoryConfig.cs) (revision 966dc7335defa901104fd4168d57c08315db2de0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/MacroStabilityInwardsCalculatorFactoryConfig.cs (.../MacroStabilityInwardsCalculatorFactoryConfig.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -24,47 +24,41 @@ namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil { /// - /// This class can be used to set a temporary - /// for while testing. - /// Disposing an instance of this class will revert the + /// This class can be used to set a temporary + /// for while testing. + /// Disposing an instance of this class will revert the /// . /// /// /// The following is an example for how to use this class: /// - /// var mockRepository = new MockRepository(); - /// var calculatorFactory = mockRepository.Stub<IMacroStabilityInwardsCalculatorFactory>(); - /// mockRepository.ReplayAll(); - /// - /// using(new MacroStabilityInwardsCalculatorFactoryConfig(calculatorFactory)) + /// using(new MacroStabilityInwardsCalculatorFactoryConfig()) /// { - /// // Perform test with mocked factory + /// var testFactory = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance; + /// + /// // Perform tests with testFactory /// } /// - /// - /// mockRepository.VerifyAll(); /// public class MacroStabilityInwardsCalculatorFactoryConfig : IDisposable { private readonly IMacroStabilityInwardsCalculatorFactory previousFactory; /// /// Creates a new instance of . - /// Sets the to . + /// Sets a to + /// /// - /// The factory that will be used while testing. - /// Thrown when - /// is null. - public MacroStabilityInwardsCalculatorFactoryConfig(IMacroStabilityInwardsCalculatorFactory newFactory) + public MacroStabilityInwardsCalculatorFactoryConfig() { - if (newFactory == null) - { - throw new ArgumentNullException(nameof(newFactory)); - } previousFactory = MacroStabilityInwardsCalculatorFactory.Instance; - MacroStabilityInwardsCalculatorFactory.Instance = newFactory; + MacroStabilityInwardsCalculatorFactory.Instance = new TestMacroStabilityInwardsCalculatorFactory(); } + /// + /// Reverts the to the value + /// it had at time of construction of the . + /// public void Dispose() { MacroStabilityInwardsCalculatorFactory.Instance = previousFactory; Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -r966dc7335defa901104fd4168d57c08315db2de0 -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs) (revision 966dc7335defa901104fd4168d57c08315db2de0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationScenarioContextTreeNodeInfoTest.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -45,7 +45,6 @@ using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; -using Ringtoets.MacroStabilityInwards.KernelWrapper; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil; using Ringtoets.MacroStabilityInwards.Primitives; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -645,7 +644,7 @@ // Expect an activity dialog which is automatically closed }; - using(new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(calculationContext, null, treeViewControl)) { // When Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationActivityTest.cs =================================================================== diff -u -r966dc7335defa901104fd4168d57c08315db2de0 -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationActivityTest.cs (.../MacroStabilityInwardsCalculationActivityTest.cs) (revision 966dc7335defa901104fd4168d57c08315db2de0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationActivityTest.cs (.../MacroStabilityInwardsCalculationActivityTest.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -120,7 +120,7 @@ double norm = new Random(21).NextDouble(); - using (new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var activity = new MacroStabilityInwardsCalculationActivity(validMacroStabilityInwardsCalculation, new MacroStabilityInwardsProbabilityAssessmentInput(), norm, double.NaN); activity.Run(); Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs =================================================================== diff -u -r497172e737ffc201c0f905e85a246cdba3c0cb1c -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision 497172e737ffc201c0f905e85a246cdba3c0cb1c) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -248,7 +248,7 @@ testCalculation.Name = name; - using (new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { Action call = () => { @@ -275,7 +275,7 @@ public void Calculate_ValidCalculationNoOutput_ShouldSetOutput() { // Setup - using (new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Precondition Assert.IsNull(testCalculation.Output); @@ -297,7 +297,7 @@ testCalculation.Output = output; - using (new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Precondition Assert.IsTrue(MacroStabilityInwardsCalculationService.Validate(testCalculation)); @@ -314,7 +314,7 @@ public void Calculate_CompleteInput_SetsInputOnCalculator() { // Setup - using (new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call MacroStabilityInwardsCalculationService.Calculate(testCalculation); @@ -328,7 +328,7 @@ public void Calculate_CalculationRan_SetOutput() { // Setup - using (new MacroStabilityInwardsCalculatorFactoryConfig(new TestMacroStabilityInwardsCalculatorFactory())) + using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance; Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/SubCalculator/PipingSubCalculatorFactoryConfigTest.cs =================================================================== diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/SubCalculator/PipingSubCalculatorFactoryConfigTest.cs (.../PipingSubCalculatorFactoryConfigTest.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil.Test/SubCalculator/PipingSubCalculatorFactoryConfigTest.cs (.../PipingSubCalculatorFactoryConfigTest.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -41,7 +41,7 @@ } [Test] - public void Constructor_SetsTestFactoryForPipingCalculatorService() + public void Constructor_SetsTestFactoryForPipingSubCalculatorFactory() { // Call using (new PipingSubCalculatorFactoryConfig()) Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil/SubCalculator/PipingSubCalculatorFactoryConfig.cs =================================================================== diff -u -r81fa8a9bf3bd503cbd280e88b8f6037a840cff12 -r0c1eb485edd1764f19829f29bdad41e3343f35c1 --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil/SubCalculator/PipingSubCalculatorFactoryConfig.cs (.../PipingSubCalculatorFactoryConfig.cs) (revision 81fa8a9bf3bd503cbd280e88b8f6037a840cff12) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.TestUtil/SubCalculator/PipingSubCalculatorFactoryConfig.cs (.../PipingSubCalculatorFactoryConfig.cs) (revision 0c1eb485edd1764f19829f29bdad41e3343f35c1) @@ -33,8 +33,9 @@ /// /// The following is an example for how to use this class: /// - /// using(new PipingCalculationServiceConfig()) { - /// var testFactory = (TestPipingSubCalculatorFactory) PipingCalculationService.SubCalculatorFactory; + /// using(new PipingSubCalculatorFactoryConfig()) + /// { + /// var testFactory = (TestPipingSubCalculatorFactory) PipingSubCalculatorFactory.Instance; /// /// // Perform tests with testFactory /// }