Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/AssessmentSectionProviderActivityTest.cs =================================================================== diff -u -r243afdde7d5f96f47c8803ddaec2ec5ddc297669 -rc7a1a30a7fafe8671a06b10bf2a3d56cf9f510a4 --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/AssessmentSectionProviderActivityTest.cs (.../AssessmentSectionProviderActivityTest.cs) (revision 243afdde7d5f96f47c8803ddaec2ec5ddc297669) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Merge/AssessmentSectionProviderActivityTest.cs (.../AssessmentSectionProviderActivityTest.cs) (revision c7a1a30a7fafe8671a06b10bf2a3d56cf9f510a4) @@ -1,7 +1,11 @@ -using Core.Common.Base.Service; +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 @@ -20,10 +24,82 @@ var owner = new AssessmentSectionsOwner(); // Call - var activity = new AssessmentSectionProviderActivity(owner, provider); + var activity = new AssessmentSectionProviderActivity(owner, provider, string.Empty); // Assert Assert.IsInstanceOf(activity); + Assert.AreEqual(ActivityState.None, activity.State); } + + [Test] + public void Run_ProviderReturnsAssessmentSections_SetsActivityStateToExecutedAndSetsAssessmentSections() + { + // Setup + const string filePath = "Path to file"; + IEnumerable assessmentSections = Enumerable.Empty(); + + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(filePath)).Return(assessmentSections); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new AssessmentSectionProviderActivity(owner, provider, filePath); + + // Call + activity.Run(); + + // Assert + Assert.AreEqual(ActivityState.Executed, activity.State); + Assert.AreSame(assessmentSections, owner.AssessmentSections); + } + + [Test] + public void Run_ProviderThrowsException_SetsActivityStateToFailedAndDoesNotSetAssessmentSections() + { + // Setup + const string filePath = "Path to file"; + + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(filePath)).Throw(new AssessmentSectionProviderException()); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new AssessmentSectionProviderActivity(owner, provider, filePath); + + // Call + activity.Run(); + + // Assert + Assert.AreEqual(ActivityState.Failed, activity.State); + Assert.IsNull(owner.AssessmentSections); + } + + [Test] + public void GivenCancelledActivity_WhenFinishingActivity_ThenActivityStateSetToCancelledAndDoesNotSetAssessmentSections() + { + // Given + const string filePath = "Path to file"; + IEnumerable assessmentSections = Enumerable.Empty(); + + var mocks = new MockRepository(); + var provider = mocks.Stub(); + provider.Expect(p => p.GetAssessmentSections(filePath)).Return(assessmentSections); + mocks.ReplayAll(); + + var owner = new AssessmentSectionsOwner(); + var activity = new AssessmentSectionProviderActivity(owner, provider, filePath); + + activity.Run(); + activity.Cancel(); + + // When + activity.Finish(); + + // Assert + Assert.AreEqual(ActivityState.Canceled, activity.State); + Assert.IsNull(owner.AssessmentSections); + } } } \ No newline at end of file