using System; using System.Linq; using Core.Common.Base; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Forms.Test.PresentationObjects { [TestFixture] public class PipingInputContextTest { [Test] public void ParameteredConstructor_ExpectedValues() { // Setup var pipingInput = new PipingInput(new GeneralPipingInput()); var surfaceLines = new[] { new RingtoetsPipingSurfaceLine() }; var stochasticSoilModels = new[] { new TestStochasticSoilModel() }; var mocks = new MockRepository(); var assessmentSection = mocks.StrictMock(); mocks.ReplayAll(); // Call var context = new PipingInputContext(pipingInput, surfaceLines, stochasticSoilModels, assessmentSection); // Assert Assert.IsInstanceOf>(context); Assert.AreSame(pipingInput, context.WrappedData); Assert.AreSame(assessmentSection, context.AssessmentSection); CollectionAssert.AreEqual(surfaceLines, context.AvailablePipingSurfaceLines); CollectionAssert.AreEqual(stochasticSoilModels, context.AvailableStochasticSoilModels); mocks.VerifyAll(); } [Test] public void ParameteredConstructor_AssessmentSectionIsNull_ThrowArgumentNullException() { // Setup var input = new PipingInput(new GeneralPipingInput()); var surfaceLines = new[] { new RingtoetsPipingSurfaceLine() }; var stochasticSoilModels = new[] { new TestStochasticSoilModel() }; // Call TestDelegate call = () => new PipingInputContext(input, surfaceLines, stochasticSoilModels, null); // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Het traject mag niet 'null' zijn."); } [Test] public void Attach_Observer_ObserverAttachedToPipingInput() { // Setup var mocks = new MockRepository(); var assessmentSectionMock = mocks.StrictMock(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var pipingInput = new PipingInput(new GeneralPipingInput()); var context = new PipingInputContext(pipingInput, Enumerable.Empty(), Enumerable.Empty(), assessmentSectionMock); // Call context.Attach(observer); // Assert pipingInput.NotifyObservers(); // Notification on wrapped object mocks.VerifyAll(); // Expected UpdateObserver call } [Test] public void Detach_Observer_ObserverDetachedFromPipingInput() { // Setup var mocks = new MockRepository(); var assessmentSectionMock = mocks.StrictMock(); var observer = mocks.StrictMock(); mocks.ReplayAll(); var pipingInput = new PipingInput(new GeneralPipingInput()); var context = new PipingInputContext(pipingInput, Enumerable.Empty(), Enumerable.Empty(), assessmentSectionMock); context.Attach(observer); // Call context.Detach(observer); // Assert pipingInput.NotifyObservers(); // Notification on wrapped object mocks.VerifyAll(); // Expected no UpdateObserver call } [Test] public void NotifyObservers_ObserverAttachedToPipingInput_NotificationCorrectlyPropagated() { // Setup var mocks = new MockRepository(); var assessmentSectionMock = mocks.StrictMock(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var pipingInput = new PipingInput(new GeneralPipingInput()); var context = new PipingInputContext(pipingInput, Enumerable.Empty(), Enumerable.Empty(), assessmentSectionMock); pipingInput.Attach(observer); // Attach to wrapped object // Call context.NotifyObservers(); // Notification on context // Assert mocks.VerifyAll(); } } }