public void DoPostReplacementUpdates_DuneLocationsAdded_DoNothing()
        {
            // Setup
            var mocks        = new MockRepository();
            var viewCommands = mocks.StrictMock <IViewCommands>();

            mocks.ReplayAll();

            var failureMechanism = new DuneErosionFailureMechanism();

            failureMechanism.SetDuneLocations(new[]
            {
                new TestDuneLocation(),
                new TestDuneLocation()
            });
            var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism);

            handler.Replace(new[]
            {
                new HydraulicBoundaryLocation(1, "Locatie_1_100", 205354, 609735)
            });

            // Precondition
            Assert.AreEqual(1, failureMechanism.DuneLocations.Count());

            // Call
            handler.DoPostReplacementUpdates();

            // Assert
            mocks.VerifyAll(); // Expect no calls in 'viewCommands'
        }
        public void DoPostReplacementUpdates_NoDuneLocationsAdded_CloseAllViewsForFailureMechanism()
        {
            // Setup
            var failureMechanism = new DuneErosionFailureMechanism();

            failureMechanism.SetDuneLocations(new[]
            {
                new TestDuneLocation(),
                new TestDuneLocation()
            });

            var mocks        = new MockRepository();
            var viewCommands = mocks.StrictMock <IViewCommands>();

            viewCommands.Expect(vc => vc.RemoveAllViewsForItem(failureMechanism));
            mocks.ReplayAll();

            var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism);

            handler.Replace(new HydraulicBoundaryLocation[]
            {
                new TestHydraulicBoundaryLocation()
            });

            // Precondition
            CollectionAssert.IsEmpty(failureMechanism.DuneLocations);

            // Call
            handler.DoPostReplacementUpdates();

            // Assert
            mocks.VerifyAll();
        }
        public void Replace_NewLocationsIsDune_LocationAndCalculationsAdded()
        {
            // Setup
            var mocks        = new MockRepository();
            var viewCommands = mocks.Stub <IViewCommands>();

            mocks.ReplayAll();

            var random           = new Random(21);
            var failureMechanism = new DuneErosionFailureMechanism
            {
                DuneLocationCalculationsForUserDefinedTargetProbabilities =
                {
                    new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)),
                    new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01))
                }
            };

            failureMechanism.SetDuneLocations(new[]
            {
                new TestDuneLocation(),
                new TestDuneLocation()
            });

            var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism);

            // Precondition
            Assert.AreEqual(2, failureMechanism.DuneLocations.Count());

            ObservableList <DuneLocationCalculationsForTargetProbability> calculationsForTargetProbabilities =
                failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities;

            Assert.AreEqual(2, calculationsForTargetProbabilities[0].DuneLocationCalculations.Count);
            Assert.AreEqual(2, calculationsForTargetProbabilities[1].DuneLocationCalculations.Count);

            // Call
            handler.Replace(new[]
            {
                new HydraulicBoundaryLocation(1, "test_1_100", 205354, 609735)
            });

            // Assert
            Assert.AreEqual(1, failureMechanism.DuneLocations.Count());

            DuneLocation duneLocation = failureMechanism.DuneLocations.First();

            Assert.AreEqual(1, duneLocation.Id);
            Assert.AreEqual(new Point2D(205354, 609735), duneLocation.Location);
            AssertDuneLocationCalculations(duneLocation, failureMechanism);

            mocks.VerifyAll();
        }
        public void Replace_FailureMechanismHasDuneLocations_LocationsAndCalculationsCleared()
        {
            // Setup
            var mocks        = new MockRepository();
            var viewCommands = mocks.Stub <IViewCommands>();

            mocks.ReplayAll();

            var random           = new Random(21);
            var failureMechanism = new DuneErosionFailureMechanism
            {
                DuneLocationCalculationsForUserDefinedTargetProbabilities =
                {
                    new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)),
                    new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01))
                }
            };

            var duneLocations = new[]
            {
                new TestDuneLocation(),
                new TestDuneLocation()
            };

            failureMechanism.SetDuneLocations(duneLocations);

            var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism);

            // Precondition
            Assert.AreEqual(2, failureMechanism.DuneLocations.Count());

            ObservableList <DuneLocationCalculationsForTargetProbability> calculationsForTargetProbabilities =
                failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities;

            Assert.AreEqual(2, calculationsForTargetProbabilities[0].DuneLocationCalculations.Count);
            Assert.AreEqual(2, calculationsForTargetProbabilities[1].DuneLocationCalculations.Count);

            // Call
            handler.Replace(new HydraulicBoundaryLocation[]
            {
                new TestHydraulicBoundaryLocation()
            });

            // Assert
            CollectionAssert.IsEmpty(failureMechanism.DuneLocations);
            CollectionAssert.IsEmpty(calculationsForTargetProbabilities[0].DuneLocationCalculations);
            CollectionAssert.IsEmpty(calculationsForTargetProbabilities[1].DuneLocationCalculations);
            mocks.VerifyAll();
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var mocks        = new MockRepository();
            var viewCommands = mocks.Stub <IViewCommands>();

            mocks.ReplayAll();

            // Call
            var handler = new DuneLocationsReplacementHandler(viewCommands, new DuneErosionFailureMechanism());

            // Assert
            Assert.IsInstanceOf <IDuneLocationsReplacementHandler>(handler);
            mocks.VerifyAll();
        }
        public void Replace_HydraulicBoundaryLocationsNull_ThrowArgumentNullException()
        {
            // Setup
            var mocks        = new MockRepository();
            var viewCommands = mocks.Stub <IViewCommands>();

            mocks.ReplayAll();

            var failureMechanism = new DuneErosionFailureMechanism();
            var handler          = new DuneLocationsReplacementHandler(viewCommands, failureMechanism);

            // Call
            void Call() => handler.Replace(null);

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

            Assert.AreEqual("hydraulicBoundaryLocations", exception.ParamName);
            mocks.VerifyAll();
        }