Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Domain/CoverageFunctionTest.cs =================================================================== diff -u -r4012 -r4070 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Domain/CoverageFunctionTest.cs (.../CoverageFunctionTest.cs) (revision 4012) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Maps.Tests/Domain/CoverageFunctionTest.cs (.../CoverageFunctionTest.cs) (revision 4070) @@ -21,13 +21,9 @@ using System; using System.Collections.Generic; - using GeoAPI.Geometries; - using NetTopologySuite.Geometries; - using NUnit.Framework; - using Rhino.Mocks; namespace Deltares.Maps.Tests.Domain @@ -38,33 +34,6 @@ private MockRepository mocks; private IFeatureRepository repository; - #region Setup - - [SetUp] - public void FixtureSetup() - { - mocks = new MockRepository(); - } - - [TearDown] - public void FixtureTearDown() - { - } - - [SetUp] - public void TestSetup() - { - repository = mocks.DynamicMock(); - } - - [TearDown] - public void TestTearDown() - { - mocks.VerifyAll(); - } - - #endregion - [Test] public void GetCoverageFunction_NoAttributesInList_Throws() { @@ -76,7 +45,10 @@ public void GetCoverageFunction_AttributeListContainsInvalidString_Throws() { mocks.ReplayAll(); - Assert.That(() => CoverageFunction.GetCoverageFunc(repository, new List { "" }), Throws.ArgumentException); + Assert.That(() => CoverageFunction.GetCoverageFunc(repository, new List + { + "" + }), Throws.ArgumentException); } [Test] @@ -90,25 +62,35 @@ public void GetCoverageFunction_RepositoryIsNull_Throws() { mocks.ReplayAll(); - Assert.That(() => CoverageFunction.GetCoverageFunc(null, new[] { "SomeAttribute" }), Throws.ArgumentNullException); + Assert.That(() => CoverageFunction.GetCoverageFunc(null, new[] + { + "SomeAttribute" + }), Throws.ArgumentNullException); } [Test] public void UsingCoverageFunction_AttributeNameIsNullOrEmpty_Throws() { mocks.ReplayAll(); - Func func = CoverageFunction.GetCoverageFunc(repository, new[] { "SomeAttribute" }); + Func func = CoverageFunction.GetCoverageFunc(repository, new[] + { + "SomeAttribute" + }); Assert.That(() => func("", 0, 0), Throws.ArgumentNullException); } [Test] public void CoverageFunction_AttributeNamesAndDifferentCase_ReturnsExpectedValue() { - var lineString = new LineString(new[] { new Coordinate(1, 1), new Coordinate(1, 2) }); + var lineString = new LineString(new[] + { + new Coordinate(1, 1), + new Coordinate(1, 2) + }); var rep = new FeatureRepository(); - Feature geom = Feature.Create(lineString); + var geom = Feature.Create(lineString); rep.Add(geom); //Expect.Call(repository.Features).Return(new[] { geom }); @@ -120,11 +102,11 @@ //Expect.Call(repository.SupportedAttributes).Return(new[] { attribute }); Func func = rep.GetCoverageFunc(); - var actual = (string)func(attribute.ToUpper(), 1, 1); + var actual = (string) func(attribute.ToUpper(), 1, 1); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); - actual = (string)func(attribute.ToLower(), 1, 1); + actual = (string) func(attribute.ToLower(), 1, 1); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); @@ -135,7 +117,10 @@ public void UsingCoverageFunction_AttributeNamenotContainedInAttributeList_Throws() { mocks.ReplayAll(); - Func func = CoverageFunction.GetCoverageFunc(repository, new[] { "SomeAttribute" }); + Func func = CoverageFunction.GetCoverageFunc(repository, new[] + { + "SomeAttribute" + }); Assert.That(() => func("AnotherAttribute", 0, 0), Throws.InstanceOf()); } @@ -150,21 +135,25 @@ new Coordinate(-1, -1), new Coordinate(-1, 1) })); - - Feature geom = Feature.Create(square); + + var geom = Feature.Create(square); //Expect.Call(repository.Features).Return(new[] {geom, geom}); - Expect.Call(repository.Query((IGeometry)null)).IgnoreArguments().Return(new[] { geom, geom }); - + Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + { + geom, + geom + }); + const string attribute = "SomeAttribute"; Expect.Call(repository.SupportedAttributes).Return(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)")); } @@ -179,19 +168,22 @@ new Coordinate(-1, -1), new Coordinate(-1, 1) })); - + const string attribute = "SomeAttribute"; Expect.Call(repository.SupportedAttributes).Return(new[] { attribute.ToUpper() }); - - Feature geom = Feature.Create(square); + + var geom = Feature.Create(square); //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry)null)).IgnoreArguments().Return(new[] { geom }); - + Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(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)")); } @@ -208,9 +200,12 @@ new Coordinate(-1, 1) })); - Feature geom = Feature.Create(square); + var geom = Feature.Create(square); //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry)null)).IgnoreArguments().Return(new[] { geom }); + Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + { + geom + }); const string attribute = "SomeAttribute"; const double expected = 20; @@ -224,7 +219,7 @@ mocks.ReplayAll(); Func func = repository.GetCoverageFunc(); - var actual = (double)func(attribute, 0, 0); + var actual = (double) func(attribute, 0, 0); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual, 0.0001); } @@ -241,51 +236,67 @@ new Coordinate(-1, 1) })); - Feature geom = Feature.Create(square); + var geom = Feature.Create(square); //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry)null)).IgnoreArguments().Return(new[] { geom }); + Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + { + geom + }); const string attribute = "SomeAttribute"; const string expected = "test"; geom.AddAttribute(attribute, expected); - Expect.Call(repository.SupportedAttributes).Return(new[] { attribute }); + Expect.Call(repository.SupportedAttributes).Return(new[] + { + attribute + }); mocks.ReplayAll(); Func func = repository.GetCoverageFunc(); - var actual = (string)func(attribute, 0, 0); + var actual = (string) func(attribute, 0, 0); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); } [Test] public void UsingCoverageFunctionForGivenLocation_RepositoryContainsLinestringGeometryType_ReturnsValue() { - var lineString = new LineString(new[] { new Coordinate(1, 1), new Coordinate(1, 2) }); + var lineString = new LineString(new[] + { + new Coordinate(1, 1), + new Coordinate(1, 2) + }); - Feature geom = Feature.Create(lineString); + var geom = Feature.Create(lineString); //Expect.Call(repository.Features).Return(new[] { geom }); - Expect.Call(repository.Query((IGeometry)null)).IgnoreArguments().Return(new[] { geom }); + Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + { + geom + }); const string attribute = "SomeAttribute"; const double expected = 5; geom.AddAttribute(attribute, expected); - Expect.Call(repository.SupportedAttributes).Return(new[] { attribute }); + Expect.Call(repository.SupportedAttributes).Return(new[] + { + attribute + }); mocks.ReplayAll(); Func func = repository.GetCoverageFunc(); - var actual = (double)func(attribute, 1, 1); + var actual = (double) func(attribute, 1, 1); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); - actual = (double)func(attribute, 1, 2); + actual = (double) func(attribute, 1, 2); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); - actual = (double)func(attribute, 1, 1.5); + actual = (double) func(attribute, 1, 1.5); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); } @@ -305,10 +316,13 @@ new Coordinate(-1, 1) })); - Feature geom = Feature.Create(square); + 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[] { geom }); + Expect.Call(repository.Query((IGeometry) null)).IgnoreArguments().Return(new[] + { + geom + }); Expect.Call(repository.SupportedAttributes).Return(new[] { attribute.ToUpper() @@ -317,9 +331,34 @@ mocks.ReplayAll(); Func func = repository.GetCoverageFunc(attribute); - var actual = (double)func(0, 0); + var actual = (double) func(0, 0); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual, 0.0001); } + + #region Setup + + [SetUp] + public void FixtureSetup() + { + mocks = new MockRepository(); + } + + [TearDown] + public void FixtureTearDown() {} + + [SetUp] + public void TestSetup() + { + repository = mocks.DynamicMock(); + } + + [TearDown] + public void TestTearDown() + { + mocks.VerifyAll(); + } + + #endregion } } \ No newline at end of file