Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Domain/CoverageFunctionTest.cs =================================================================== diff -u -r4638 -r4786 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Domain/CoverageFunctionTest.cs (.../CoverageFunctionTest.cs) (revision 4638) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Domain/CoverageFunctionTest.cs (.../CoverageFunctionTest.cs) (revision 4786) @@ -24,27 +24,24 @@ using GeoAPI.Geometries; using NetTopologySuite.Geometries; using NUnit.Framework; -using Rhino.Mocks; +using NSubstitute; namespace Deltares.Maps.Tests.Domain { [TestFixture] public class CoverageFunctionTest { - private MockRepository mocks; private IFeatureRepository repository; [Test] public void GetCoverageFunction_NoAttributesInList_Throws() { - mocks.ReplayAll(); Assert.That(() => CoverageFunction.GetCoverageFunc(repository, new List()), Throws.ArgumentException); } [Test] public void GetCoverageFunction_AttributeListContainsInvalidString_Throws() { - mocks.ReplayAll(); Assert.That(() => CoverageFunction.GetCoverageFunc(repository, new List { "" @@ -54,14 +51,12 @@ [Test] public void GetCoverageFunction_SupportedAttributeListIsNull_Throws() { - mocks.ReplayAll(); Assert.That(() => repository.GetCoverageFunc("SomeAttribute", null), Throws.ArgumentNullException); } [Test] public void GetCoverageFunction_RepositoryIsNull_Throws() { - mocks.ReplayAll(); Assert.That(() => CoverageFunction.GetCoverageFunc(null, new[] { "SomeAttribute" @@ -71,7 +66,6 @@ [Test] public void UsingCoverageFunction_AttributeNameIsNullOrEmpty_Throws() { - mocks.ReplayAll(); Func func = CoverageFunction.GetCoverageFunc(repository, new[] { "SomeAttribute" @@ -93,14 +87,10 @@ var geom = Feature.Create(lineString); rep.Add(geom); - //Expect.Call(repository.Features).Return(new[] { geom }); - const string attribute = "SomeAttribute"; const string expected = "test"; geom.AddAttribute(attribute, expected); - //Expect.Call(repository.SupportedAttributes).Return(new[] { attribute }); - Func func = rep.GetCoverageFunc(); var actual = (string) func(attribute.ToUpper(), 1, 1); Assert.That(actual, Is.Not.Null); @@ -109,14 +99,11 @@ actual = (string) func(attribute.ToLower(), 1, 1); Assert.That(actual, Is.Not.Null); Assert.That(actual, Is.EqualTo(expected)); - - mocks.ReplayAll(); } [Test] public void UsingCoverageFunction_AttributeNamenotContainedInAttributeList_Throws() { - mocks.ReplayAll(); Func func = CoverageFunction.GetCoverageFunc(repository, new[] { "SomeAttribute" @@ -125,7 +112,7 @@ } [Test] - public void UsingCoverageFunction_MoreThenOneGeometyFoundAtGivenLocation_Throws() + public void UsingCoverageFunction_MoreThenOneGeometryFoundAtGivenLocation_Throws() { var square = new Polygon(new LinearRing(new[] { @@ -137,28 +124,25 @@ })); var geom = Feature.Create(square); - //Expect.Call(repository.Features).Return(new[] {geom, geom}); - Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + repository.Query(Arg.Any()).Returns(new[] { geom, geom }); const string attribute = "SomeAttribute"; - Expect.Call(repository.SupportedAttributes).Return(new[] + repository.SupportedAttributes.Returns(new[] { attribute.ToUpper() }); - mocks.ReplayAll(); - Func func = repository.GetCoverageFunc(); Assert.That(() => func(attribute, 0, 0), Throws.InstanceOf().With.Message.EqualTo("Multiple geometries found covering point (0 0)")); } [Test] - public void UsingCoverageFunction_NoGeometyFoundAtGivenLocation_Throws() + public void UsingCoverageFunction_NoGeometryFoundAtGivenLocation_Throws() { var square = new Polygon(new LinearRing(new[] { @@ -170,26 +154,23 @@ })); const string attribute = "SomeAttribute"; - Expect.Call(repository.SupportedAttributes).Return(new[] + repository.SupportedAttributes.Returns(new[] { attribute.ToUpper() }); var geom = Feature.Create(square); - //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + repository.Query(Arg.Any()).Returns(new[] { geom }); - mocks.ReplayAll(); - Func func = repository.GetCoverageFunc(); Assert.That(() => func("SomeAttribute", 10, 10), Throws.InstanceOf().With.Message.EqualTo("No geometries found covering point (10 10)")); } [Test] - public void UsingCoverageFunction_GeometyFoundAtGivenLocation_ReturnsAttributeValueAsDouble() + public void UsingCoverageFunction_GeometryFoundAtGivenLocation_ReturnsAttributeValueAsDouble() { var square = new Polygon(new LinearRing(new[] { @@ -201,8 +182,7 @@ })); var geom = Feature.Create(square); - //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + repository.Query(Arg.Any()).Returns(new[] { geom }); @@ -211,20 +191,18 @@ const double expected = 20; geom.AddAttribute(attribute, expected); - Expect.Call(repository.SupportedAttributes).Return(new[] + repository.SupportedAttributes.Returns(new[] { attribute.ToUpper() }); - mocks.ReplayAll(); - Func func = repository.GetCoverageFunc(); var actual = (double) func(attribute, 0, 0); Assert.That(actual, Is.EqualTo(expected).Within(0.0001)); } [Test] - public void UsingCoverageFunction_GeometyFoundAtGivenLocation_ReturnsAttributeValueAsStringType() + public void UsingCoverageFunction_GeometryFoundAtGivenLocation_ReturnsAttributeValueAsStringType() { var square = new Polygon(new LinearRing(new[] { @@ -236,8 +214,7 @@ })); var geom = Feature.Create(square); - //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + repository.Query(Arg.Any()).Returns(new[] { geom }); @@ -246,13 +223,11 @@ const string expected = "test"; geom.AddAttribute(attribute, expected); - Expect.Call(repository.SupportedAttributes).Return(new[] + repository.SupportedAttributes.Returns(new[] { attribute }); - mocks.ReplayAll(); - Func func = repository.GetCoverageFunc(); var actual = (string) func(attribute, 0, 0); Assert.That(actual, Is.Not.Null); @@ -269,8 +244,7 @@ }); var geom = Feature.Create(lineString); - //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + repository.Query(Arg.Any()).Returns(new[] { geom }); @@ -279,13 +253,11 @@ const double expected = 5; geom.AddAttribute(attribute, expected); - Expect.Call(repository.SupportedAttributes).Return(new[] + repository.SupportedAttributes.Returns(new[] { attribute }); - mocks.ReplayAll(); - Func func = repository.GetCoverageFunc(); var actual = (double) func(attribute, 1, 1); Assert.That(actual, Is.EqualTo(expected)); @@ -298,7 +270,7 @@ } [Test] - public void UsingCoverageFunctionCreatedByGeometryRepository_GeometyFoundAtGivenLocation_ReturnsAttributeValue() + public void UsingCoverageFunctionCreatedByGeometryRepository_GeometryFoundAtGivenLocation_ReturnsAttributeValue() { const string attribute = "SomeAttribute"; const double expected = 20; @@ -314,18 +286,15 @@ var geom = Feature.Create(square); geom.AddAttribute(attribute, expected); - //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + repository.Query(Arg.Any()).Returns(new[] { geom }); - Expect.Call(repository.SupportedAttributes).Return(new[] + repository.SupportedAttributes.Returns(new[] { attribute.ToUpper() }); - mocks.ReplayAll(); - Func func = repository.GetCoverageFunc(attribute); var actual = (double) func(0, 0); Assert.That(actual, Is.EqualTo(expected).Within(0.0001)); @@ -334,26 +303,11 @@ #region Setup [SetUp] - public void FixtureSetup() - { - mocks = new MockRepository(); - } - - [TearDown] - public void FixtureTearDown() {} - - [SetUp] public void TestSetup() { - repository = mocks.DynamicMock(); + repository = Substitute.For(); } - - [TearDown] - public void TestTearDown() - { - mocks.VerifyAll(); - } - + #endregion } } \ No newline at end of file