-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- #24: Add tests for: - GdalConfigurationDocument - RuntimeMapLayerCollection - RuntimeMapGroupCollection
- Loading branch information
1 parent
1027af1
commit bf98073
Showing
15 changed files
with
483 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
OSGeo.MapGuide.MaestroAPI.Tests/GdalConfigurationDocumentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#region Disclaimer / License | ||
|
||
// Copyright (C) 2017, Jackie Ng | ||
// https:/jumpinjackie/mapguide-maestro | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
#endregion Disclaimer / License | ||
using OSGeo.MapGuide.MaestroAPI.SchemaOverrides; | ||
using Xunit; | ||
|
||
namespace OSGeo.MapGuide.MaestroAPI.Tests | ||
{ | ||
public class GdalConfigurationDocumentTests | ||
{ | ||
[Fact] | ||
public void GdalDocument_AddLocationDeDupes() | ||
{ | ||
var doc = new GdalConfigurationDocument(); | ||
var loc = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; | ||
doc.AddLocation(loc); | ||
Assert.Equal(1, doc.RasterLocations.Length); | ||
var loc2 = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; | ||
doc.AddLocation(loc2); | ||
Assert.Equal(1, doc.RasterLocations.Length); | ||
var loc3 = new GdalRasterLocationItem { Location = "C:\\temp\\location_2" }; | ||
doc.AddLocation(loc3); | ||
Assert.Equal(2, doc.RasterLocations.Length); | ||
} | ||
|
||
[Fact] | ||
public void GdalDocument_Remove() | ||
{ | ||
var doc = new GdalConfigurationDocument(); | ||
var loc = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; | ||
Assert.False(doc.RemoveLocation(loc)); | ||
doc.AddLocation(loc); | ||
var loc2 = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; | ||
Assert.True(doc.RemoveLocation(loc2)); | ||
} | ||
|
||
[Fact] | ||
public void GdalDocument_CalculateExtents() | ||
{ | ||
var doc = new GdalConfigurationDocument(); | ||
Assert.Null(doc.CalculateExtent()); | ||
var loc = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; | ||
loc.AddItem(new GdalRasterItem { FileName = "1_1.tif", MinX = 1, MinY = 1, MaxX = 2, MaxY = 2 }); | ||
doc.AddLocation(loc); | ||
var ext = doc.CalculateExtent(); | ||
Assert.Equal(1, ext.MinX); | ||
Assert.Equal(1, ext.MinY); | ||
Assert.Equal(2, ext.MaxX); | ||
Assert.Equal(2, ext.MaxY); | ||
var loc2 = new GdalRasterLocationItem { Location = "C:\\temp\\location_2" }; | ||
loc2.AddItem(new GdalRasterItem { FileName = "2_1.tif", MinX = -1, MinY = -1, MaxX = 2, MaxY = 2 }); | ||
doc.AddLocation(loc2); | ||
ext = doc.CalculateExtent(); | ||
Assert.Equal(-1, ext.MinX); | ||
Assert.Equal(-1, ext.MinY); | ||
Assert.Equal(2, ext.MaxX); | ||
Assert.Equal(2, ext.MaxY); | ||
loc2.AddItem(new GdalRasterItem { FileName = "1_2.tif", MinX = 2, MinY = 1, MaxX = 3, MaxY = 3 }); | ||
ext = doc.CalculateExtent(); | ||
Assert.Equal(-1, ext.MinX); | ||
Assert.Equal(-1, ext.MinY); | ||
Assert.Equal(3, ext.MaxX); | ||
Assert.Equal(3, ext.MaxY); | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
OSGeo.MapGuide.MaestroAPI.Tests/KeyValueCollectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#region Disclaimer / License | ||
|
||
// Copyright (C) 2017, Jackie Ng | ||
// https:/jumpinjackie/mapguide-maestro | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
#endregion Disclaimer / License | ||
using OSGeo.MapGuide.MaestroAPI.Exceptions; | ||
using OSGeo.MapGuide.MaestroAPI.Mapping; | ||
using System.Collections; | ||
using Xunit; | ||
|
||
namespace OSGeo.MapGuide.MaestroAPI.Tests | ||
{ | ||
public abstract class KeyValueCollectionTests<TCollection, TKey, TValue> | ||
where TValue : class | ||
where TCollection : KeyValueCollection<TKey, TValue> | ||
{ | ||
protected abstract TCollection CreateCollection(); | ||
|
||
protected abstract TValue CreateTestValue1(string desiredKey = null); | ||
|
||
protected abstract TValue CreateTestValue2(string desiredKey = null); | ||
|
||
public virtual void Collection_BasicManipulation() | ||
{ | ||
var collection = CreateCollection(); | ||
var val1 = CreateTestValue1(); | ||
Assert.True(collection.IndexOf(val1) < 0); | ||
Assert.False(collection.Contains(val1)); | ||
collection.Add(val1); | ||
Assert.True(collection.IndexOf(val1) >= 0); | ||
Assert.True(collection.Contains(val1)); | ||
|
||
collection.Clear(); | ||
Assert.Equal(0, collection.Count); | ||
|
||
var val2 = CreateTestValue2(); | ||
collection.Insert(0, val1); | ||
collection.Insert(0, val2); | ||
|
||
Assert.Equal(2, collection.Count); | ||
Assert.False(collection.IsReadOnly); | ||
} | ||
|
||
public virtual void Collection_BasicManipulation_AsIList() | ||
{ | ||
IList collection = CreateCollection(); | ||
var val1 = CreateTestValue1(); | ||
Assert.True(collection.IndexOf(val1) < 0); | ||
Assert.False(collection.Contains(val1)); | ||
collection.Add(val1); | ||
Assert.True(collection.IndexOf(val1) >= 0); | ||
Assert.True(collection.Contains(val1)); | ||
|
||
collection.Clear(); | ||
Assert.Equal(0, collection.Count); | ||
|
||
var val2 = CreateTestValue2(); | ||
collection.Insert(0, val1); | ||
collection.Insert(0, val2); | ||
|
||
Assert.Equal(2, collection.Count); | ||
Assert.False(collection.IsReadOnly); | ||
Assert.False(collection.IsFixedSize); | ||
} | ||
|
||
public virtual void Collection_IsEnumerable() | ||
{ | ||
var collection = CreateCollection(); | ||
var val1 = CreateTestValue1(); | ||
var val2 = CreateTestValue2(); | ||
collection.Add(val1); | ||
collection.Add(val2); | ||
foreach (var v in collection) | ||
{ | ||
Assert.True(v == val1 || v == val2); | ||
} | ||
} | ||
|
||
public virtual void Collection_IsEnumerable_AsIList() | ||
{ | ||
IList collection = CreateCollection(); | ||
var val1 = CreateTestValue1(); | ||
var val2 = CreateTestValue2(); | ||
collection.Add(val1); | ||
collection.Add(val2); | ||
foreach (var v in collection) | ||
{ | ||
Assert.True(v == val1 || v == val2); | ||
} | ||
} | ||
|
||
public virtual void Collection_InsertDuplicateKeyThrows() | ||
{ | ||
var collection = CreateCollection(); | ||
var val1 = CreateTestValue1("Key1"); | ||
var val2 = CreateTestValue2("Key1"); | ||
collection.Insert(0, val1); | ||
Assert.Throws<DuplicateKeyException>(() => collection.Insert(0, val2)); | ||
} | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
OSGeo.MapGuide.MaestroAPI.Tests/Mapping/CollectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#region Disclaimer / License | ||
|
||
// Copyright (C) 2017, Jackie Ng | ||
// https:/jumpinjackie/mapguide-maestro | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
// | ||
|
||
#endregion Disclaimer / License | ||
using Moq; | ||
using OSGeo.MapGuide.MaestroAPI.Mapping; | ||
using System; | ||
using Xunit; | ||
|
||
namespace OSGeo.MapGuide.MaestroAPI.Tests.Mapping | ||
{ | ||
public class LayerCollectionTests : KeyValueCollectionTests<RuntimeMapLayerCollection, string, RuntimeMapLayer> | ||
{ | ||
protected override RuntimeMapLayerCollection CreateCollection() | ||
{ | ||
var type = typeof(RuntimeMapLayerCollection); | ||
var ctor = type.GetInternalConstructor(new[] { typeof(RuntimeMap) }); | ||
|
||
var map = Mock.Of<RuntimeMap>(); | ||
return ctor.Invoke(new[] { map }) as RuntimeMapLayerCollection; | ||
} | ||
|
||
protected override RuntimeMapLayer CreateTestValue1(string desiredKey = null) | ||
{ | ||
var id = Guid.NewGuid().ToString(); | ||
var layer = new Mock<RuntimeMapLayer>(); | ||
layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue1"); | ||
layer.Setup(l => l.ObjectId).Returns(id); | ||
return layer.Object; | ||
} | ||
|
||
protected override RuntimeMapLayer CreateTestValue2(string desiredKey = null) | ||
{ | ||
var id = Guid.NewGuid().ToString(); | ||
var layer = new Mock<RuntimeMapLayer>(); | ||
layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue2"); | ||
layer.Setup(l => l.ObjectId).Returns(id); | ||
return layer.Object; | ||
} | ||
|
||
[Fact] | ||
public override void Collection_BasicManipulation() | ||
{ | ||
base.Collection_BasicManipulation(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_InsertDuplicateKeyThrows() | ||
{ | ||
base.Collection_InsertDuplicateKeyThrows(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_BasicManipulation_AsIList() | ||
{ | ||
base.Collection_BasicManipulation_AsIList(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_IsEnumerable() | ||
{ | ||
base.Collection_IsEnumerable(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_IsEnumerable_AsIList() | ||
{ | ||
base.Collection_IsEnumerable_AsIList(); | ||
} | ||
} | ||
|
||
public class GroupCollectionTests : KeyValueCollectionTests<RuntimeMapGroupCollection, string, RuntimeMapGroup> | ||
{ | ||
protected override RuntimeMapGroupCollection CreateCollection() | ||
{ | ||
var type = typeof(RuntimeMapGroupCollection); | ||
var ctor = type.GetInternalConstructor(new[] { typeof(RuntimeMap) }); | ||
|
||
var map = Mock.Of<RuntimeMap>(); | ||
return ctor.Invoke(new[] { map }) as RuntimeMapGroupCollection; | ||
} | ||
|
||
protected override RuntimeMapGroup CreateTestValue1(string desiredKey = null) | ||
{ | ||
var layer = new Mock<RuntimeMapGroup>(); | ||
layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue1"); | ||
return layer.Object; | ||
} | ||
|
||
protected override RuntimeMapGroup CreateTestValue2(string desiredKey = null) | ||
{ | ||
var layer = new Mock<RuntimeMapGroup>(); | ||
layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue2"); | ||
return layer.Object; | ||
} | ||
|
||
[Fact] | ||
public override void Collection_BasicManipulation() | ||
{ | ||
base.Collection_BasicManipulation(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_InsertDuplicateKeyThrows() | ||
{ | ||
base.Collection_InsertDuplicateKeyThrows(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_BasicManipulation_AsIList() | ||
{ | ||
base.Collection_BasicManipulation_AsIList(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_IsEnumerable() | ||
{ | ||
base.Collection_IsEnumerable(); | ||
} | ||
|
||
[Fact] | ||
public override void Collection_IsEnumerable_AsIList() | ||
{ | ||
base.Collection_IsEnumerable_AsIList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.