Fisheye: Tag d753b388a8ad3b2daee5ccbf12cb0ae418b05e07 refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Service/Merge/AssessmentSectionProviderActivity.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/Merge/LoadAssessmentSectionsActivity.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Service/Merge/LoadAssessmentSectionsActivity.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/Merge/LoadAssessmentSectionsActivity.cs (revision d753b388a8ad3b2daee5ccbf12cb0ae418b05e07) @@ -0,0 +1,71 @@ +using System; +using Core.Common.Base.Service; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.Merge; + +namespace Ringtoets.Integration.Service.Merge +{ + /// + /// Activity to load a collection of from a file. + /// + public class LoadAssessmentSectionsActivity : Activity + { + private readonly AssessmentSectionsOwner owner; + private readonly IAssessmentSectionProvider assessmentSectionProvider; + private readonly string filePath; + + private bool canceled; + + /// + /// Creates a new instance of . + /// + /// The owner to set the retrieved collection + /// of on. + /// The provider defining how to + /// retrieve the collection of from a file. + /// The file path to retrieve the collection of + /// from. + /// Thrown when any of the arguments is null. + public LoadAssessmentSectionsActivity(AssessmentSectionsOwner owner, + IAssessmentSectionProvider assessmentSectionProvider, + string filePath) + { + if (owner == null) + { + throw new ArgumentNullException(nameof(owner)); + } + + if (assessmentSectionProvider == null) + { + throw new ArgumentNullException(nameof(assessmentSectionProvider)); + } + + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + this.owner = owner; + this.assessmentSectionProvider = assessmentSectionProvider; + this.filePath = filePath; + } + + protected override void OnRun() + { + owner.AssessmentSections = assessmentSectionProvider.GetAssessmentSections(filePath); + } + + protected override void OnCancel() + { + canceled = true; + } + + protected override void OnFinish() + { + if (canceled) + { + owner.AssessmentSections = null; + } + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj =================================================================== diff -u -r5cb386767f4e8fcfee8737bcd44126664d203144 -rd753b388a8ad3b2daee5ccbf12cb0ae418b05e07 --- Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj (.../Ringtoets.Integration.Service.csproj) (revision 5cb386767f4e8fcfee8737bcd44126664d203144) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj (.../Ringtoets.Integration.Service.csproj) (revision d753b388a8ad3b2daee5ccbf12cb0ae418b05e07) @@ -19,7 +19,7 @@ - + Fisheye: Tag d753b388a8ad3b2daee5ccbf12cb0ae418b05e07 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/AssessmentSectionProviderActivityTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/LoadAssessmentSectionsActivityTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/LoadAssessmentSectionsActivityTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/LoadAssessmentSectionsActivityTest.cs (revision d753b388a8ad3b2daee5ccbf12cb0ae418b05e07) @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Service; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.Merge; +using Ringtoets.Integration.Service.Exceptions; +using Ringtoets.Integration.Service.Merge; + +namespace Ringtoets.Integration.Service.Test.Merge +{ + [TestFixture] + public class LoadAssessmentSectionsActivityTest + { + [Test] + public void Constructor_OwnerNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var provider = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new LoadAssessmentSectionsActivity(null, provider, string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("owner", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_ProviderNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new LoadAssessmentSectionsActivity(new AssessmentSectionsOwner(), null, string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSectionProvider", exception.ParamName); + } + + [Test] + public void Constructor_FilePathNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var provider = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new LoadAssessmentSectionsActivity(new AssessmentSectionsOwner(), + provider, + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("filePath", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var provider = mocks.Stub(); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + + // Call + var activity = new LoadAssessmentSectionsActivity(owner, provider, string.Empty); + + // Assert + Assert.IsInstanceOf(activity); + Assert.AreEqual(ActivityState.None, activity.State); + mocks.VerifyAll(); + } + + [Test] + public void Run_Always_SendsFilePathToGetsAssessmentSections() + { + // Setup + const string filePath = "Path to file"; + + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(filePath)).Return(Enumerable.Empty()); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new LoadAssessmentSectionsActivity(owner, provider, filePath); + + // Call + activity.Run(); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void Run_ProviderReturnsAssessmentSections_SetsActivityStateToExecutedAndSetsAssessmentSections() + { + // Setup + IEnumerable assessmentSections = Enumerable.Empty(); + + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(null)) + .IgnoreArguments() + .Return(assessmentSections); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new LoadAssessmentSectionsActivity(owner, provider, string.Empty); + + // Call + activity.Run(); + + // Assert + Assert.AreEqual(ActivityState.Executed, activity.State); + Assert.AreSame(assessmentSections, owner.AssessmentSections); + mocks.VerifyAll(); + } + + [Test] + public void Run_ProviderThrowsException_SetsActivityStateToFailedAndDoesNotSetAssessmentSections() + { + // Setup + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(null)) + .IgnoreArguments() + .Throw(new AssessmentSectionProviderException()); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new LoadAssessmentSectionsActivity(owner, provider, string.Empty); + + // Call + activity.Run(); + + // Assert + Assert.AreEqual(ActivityState.Failed, activity.State); + Assert.IsNull(owner.AssessmentSections); + mocks.VerifyAll(); + } + + [Test] + public void GivenCancelledActivity_WhenFinishingActivity_ThenActivityStateSetToCancelledAndDoesNotSetAssessmentSections() + { + // Given + IEnumerable assessmentSections = Enumerable.Empty(); + + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(null)) + .IgnoreArguments() + .Return(assessmentSections); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new LoadAssessmentSectionsActivity(owner, provider, string.Empty); + + activity.Run(); + activity.Cancel(); + + // When + activity.Finish(); + + // Assert + Assert.AreEqual(ActivityState.Canceled, activity.State); + Assert.IsNull(owner.AssessmentSections); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj =================================================================== diff -u -r5cb386767f4e8fcfee8737bcd44126664d203144 -rd753b388a8ad3b2daee5ccbf12cb0ae418b05e07 --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision 5cb386767f4e8fcfee8737bcd44126664d203144) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision d753b388a8ad3b2daee5ccbf12cb0ae418b05e07) @@ -21,7 +21,7 @@ - +