Skip to content

Commit

Permalink
more cov
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed May 25, 2021
1 parent cd0a6eb commit 5b45f2c
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

<h3 align="center">

![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=feature/testcov)
![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=develop)
[![NuGet](https://img.shields.io/nuget/vpre/DotNetStac)](https://www.nuget.org/packages/DotNetStac/)
[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/feature/testcov/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac)
[![codecov](https://codecov.io/gh/Terradue/DotNetStac/branch/develop/graph/badge.svg)](https://codecov.io/gh/Terradue/DotNetStac)
[![Gitter](https://img.shields.io/gitter/room/SpatioTemporal-Asset-Catalog/Lobby?color=yellow)](https://gitter.im/SpatioTemporal-Asset-Catalog/Lobby)
[![License](https://img.shields.io/badge/license-AGPL3-blue.svg)](LICENSE)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Terradue/DotNetStac/master?filepath=example.ipynb)
Expand Down
3 changes: 1 addition & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

coverage:
status:
project:
default:
target: auto
threshold: 5
threshold: 0%
2 changes: 1 addition & 1 deletion src/DotNetStac.Test/Catalog/CatalogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void CatalogStacObjectLink()
{
var simpleJson = GetJson("Catalog", "CanDeserializeMinimalSample");
ValidateJson(simpleJson);
StacCollection simpleCollection = StacConvert.Deserialize<StacCollection>(simpleJson);
StacCatalog simpleCollection = StacConvert.Deserialize<StacCatalog>(simpleJson);
StacObjectLink stacObjectLink = (StacObjectLink)StacLink.CreateObjectLink(simpleCollection, new Uri("file:///test"));
}

Expand Down
9 changes: 7 additions & 2 deletions src/DotNetStac.Test/Collection/CollectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using GeoJSON.Net;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
Expand All @@ -19,7 +21,10 @@ public void CanDeserializeSentinel2Sample()

ValidateJson(json);

var item = JsonConvert.DeserializeObject<StacCollection>(json);
byte[] byteArray = Encoding.ASCII.GetBytes(json);
MemoryStream stream = new MemoryStream(byteArray);

var item = StacConvert.Deserialize<StacCollection>(stream);

Assert.NotNull(item);

Expand Down Expand Up @@ -232,7 +237,7 @@ public void CollectionStacObjectLink()
StacObjectLink stacObjectLink = (StacObjectLink)StacLink.CreateObjectLink(simpleCollection, new Uri("file:///test"));
}



}
}
13 changes: 13 additions & 0 deletions src/DotNetStac.Test/Exceptions/ExceptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Stac.Exceptions;
using Xunit;

namespace Stac.Test.Exceptions
Expand All @@ -15,6 +16,18 @@ public void StacObjectLink()
Assert.Throws<InvalidOperationException>(() => stacObjectLink.Title = "test");
Assert.Throws<InvalidOperationException>(() => stacObjectLink.ContentType = new System.Net.Mime.ContentType("text/plain"));
Assert.Equal(simpleitem, stacObjectLink.StacObject);
StacLink nullStacLink = null;
Assert.Throws<ArgumentNullException>(() => new StacLink(nullStacLink));
}

[Fact]
public void StacConvertEx()
{
var simpleJson = GetJson("Exceptions", "MinimalSample");
ValidateJson(simpleJson);
Assert.Throws<InvalidCastException>(() => StacConvert.Deserialize<IStacCatalog>(simpleJson));
var errorJson = GetJson("Exceptions", "ErrorSample");
Assert.Throws<InvalidStacDataException>(() => StacConvert.Deserialize<StacItem>(errorJson));
}

}
Expand Down
3 changes: 3 additions & 0 deletions src/DotNetStac.Test/Extensions/EoExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public void SetAssetBands()

k3MissingBands.Assets["MS1"].EoExtension().Bands = new EoBandObject[] { eoBandObject };

Assert.Same(k3MissingBands, k3MissingBands.StacObjectContainer);
Assert.Same(k3MissingBands, k3MissingBands.Assets.First().Value.StacObjectContainer);

Assert.NotNull(k3MissingBands.GetAsset(EoBandCommonName.blue));
Assert.Equal(2001, k3MissingBands.GetBandObject(EoBandCommonName.blue).SolarIllumination);

Expand Down
60 changes: 60 additions & 0 deletions src/DotNetStac.Test/Item/ItemTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GeoJSON.Net;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
Expand Down Expand Up @@ -93,6 +94,9 @@ public void CanSerializeMinimalSample()
ValidateJson(expectedJson);

JsonAssert.AreEqual(expectedJson, actualJson);

item.Links.Remove(item.Links.First(l => l.RelationshipType == "collection"));
Assert.Null(item.Collection);
}

[Fact]
Expand Down Expand Up @@ -164,5 +168,61 @@ public void GetProperty()

var array = item.GetProperty<string[]>("test");
}

[Fact]
public void Geometry()
{
var pextentCheck = new[]
{
new List<IPosition>
{
new Position(37.488035566,-122.308150179, 10),
new Position(37.488035566,-122.308150179, 10),
}
};

var extentCheck = new[]
{
new List<IPosition>
{
new Position(37.488035566,-122.597502109, 10),
new Position(37.613537207,-122.288048600, 10),
}
};

var coordinates = new[]
{
new List<IPosition>
{
new Position(37.488035566,-122.308150179, 10),
new Position(37.538869539,-122.597502109, 10),
new Position(37.613537207,-122.576687533, 10),
new Position(37.562818007,-122.288048600, 10),
new Position(37.488035566,-122.308150179, 10)
}
};

Point point = new Point(coordinates[0][0]);
var extent = StacGeometryHelpers.GetBoundingBox(point);
Assert.Equal<IPosition>(pextentCheck.First().ToArray(), extent);
MultiPoint mpoint = new MultiPoint(Array.ConvertAll<IPosition, Point>(coordinates[0].ToArray(), p => new Point(p)));
extent = StacGeometryHelpers.GetBoundingBox(mpoint);
Assert.Equal<IPosition>(extentCheck.First().ToArray(), extent);
var lineString = new LineString(coordinates[0]);
extent = StacGeometryHelpers.GetBoundingBox(lineString);
Assert.Equal<IPosition>(extentCheck.First().ToArray(), extent);
var mlinestring = new MultiLineString(new LineString[] { lineString });
extent = StacGeometryHelpers.GetBoundingBox(mlinestring);
Assert.Equal<IPosition>(extentCheck.First().ToArray(), extent);
var polygon = new Polygon(new LineString[] { lineString });
extent = StacGeometryHelpers.GetBoundingBox(polygon);
Assert.Equal<IPosition>(extentCheck.First().ToArray(), extent);
var mpolygon = new MultiPolygon(new Polygon[] { polygon });
extent = StacGeometryHelpers.GetBoundingBox(mpolygon);
Assert.Equal<IPosition>(extentCheck.First().ToArray(), extent);
var gcollection = new GeometryCollection(new IGeometryObject[] { polygon, lineString });
// extent = StacGeometryHelpers.GetBoundingBox(gcollection);
// Assert.Equal<IPosition>(extentCheck.First().ToArray(), extent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"stac_version": "1.0.0-rc.4",
"type": "Feature",
"id": "CS3-20160503_132130_04",
"collection": "CS3",
"bbox": [
-122.59750209,
37.48803556,
-122.2880486,
37.613537207
],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
37.488035566
],
[
-122.597502109,
37.538869539
],
[
-122.576687533,
37.613537207
],
[
-122.288048600,
37.562818007
],
[
-122.308150179,
37.488035566
]
]
]
},
"properties": {
"datetime": "2016-05-03T13:21:30.040Z",
},
"links": [
{
"rel": "self",
"href": "http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.json"
},
{
"rel": "collection",
"href": "http://cool-sat.com/catalog.json"
}
],
"assets": {
"analytic": {
"href": "relative-path/to/analytic.tif",
"title": "4-Band Analytic"
},
"thumbnail": {
"href": "http://cool-sat.com/catalog/CS3-20160503_132130_04/thumbnail.png",
"title": "Thumbnail",
"roles": [
"thumbnail"
]
}
}
}
3 changes: 1 addition & 2 deletions src/DotNetStac.Test/StacLink/StacLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ public class StacLinkTests : TestBase
[Fact]
public void CreateHelpers()
{
new StacLink(new Uri("file:///test"));
StacLink.CreateDerivedFromLink(new Uri("file:///test"));
StacLink.CreateAlternateLink(new Uri("file:///test"));
StacLink.CreateChildLink(new Uri("file:///test"));
var stacLink = StacLink.CreateItemLink(new Uri("file:///test"), "text/plain");
stacLink.Title = "test";
var cloned = new StacLink(stacLink);
Assert.Equal(stacLink, cloned);
cloned = stacLink.Clone();
Assert.Equal(stacLink, cloned);
}
}
}
2 changes: 1 addition & 1 deletion src/DotNetStac/Exceptions/InvalidStacDataException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Stac.Exceptions
{
[Serializable]
internal class InvalidStacDataException : Exception
public class InvalidStacDataException : Exception
{
public InvalidStacDataException()
{
Expand Down
4 changes: 1 addition & 3 deletions src/DotNetStac/Extensions/VirtualAssets/VirtualAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public VirtualAsset(IStacObject stacObject, IList<Uri> uris) : base(stacObject,
set { }
}

/// <summary>
/// do not serialize href
/// </summary>
#pragma warning disable 1591
public bool ShouldSerializeUri() => false;
}
}
5 changes: 1 addition & 4 deletions src/DotNetStac/StacAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ public IDictionary<string, object> Properties
[JsonIgnore]
public IStacObject ParentStacObject { get => parentStacObject; internal set => parentStacObject = value; }

/// <summary>
///
/// </summary>
/// <returns></returns>
#pragma warning disable 1591
public bool ShouldSerializeStacExtensions()
{
// don't serialize the Manager property if an employee is their own manager
Expand Down
1 change: 1 addition & 0 deletions src/DotNetStac/StacCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ internal void OnDeserializedMethod(StreamingContext context)
StacExtensions = new SortedSet<string>(StacExtensions);
}

#pragma warning disable 1591
public bool ShouldSerializeSummaries()
{
// don't serialize the Manager property if an employee is their own manager
Expand Down
10 changes: 5 additions & 5 deletions src/DotNetStac/StacConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class StacConvert

public static T Deserialize<T>(string json, JsonSerializerSettings serializerSettings = null) where T : IStacObject
{
if (typeof(T) == typeof(StacItem)
|| typeof(T) == typeof(StacCollection)
|| typeof(T) == typeof(StacCatalog)
|| typeof(T) == typeof(ItemCollection))
return JsonConvert.DeserializeObject<T>(json);
// if (typeof(T) == typeof(StacItem)
// || typeof(T) == typeof(StacCollection)
// || typeof(T) == typeof(StacCatalog)
// || typeof(T) == typeof(ItemCollection))
// return JsonConvert.DeserializeObject<T>(json);
if (serializerSettings == null)
serializerSettings = defaultJsonSerializerSettings;
serializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
Expand Down
8 changes: 2 additions & 6 deletions src/DotNetStac/StacItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void LinksCollectionChanged(object sender, NotifyCollectionChangedEventA
{
if (e.OldItems != null)
{
foreach (var oldLink in e.NewItems.Cast<StacLink>())
foreach (var oldLink in e.OldItems.Cast<StacLink>())
{
if (oldLink.RelationshipType == "collection")
{
Expand Down Expand Up @@ -118,6 +118,7 @@ public string Collection
set
{
if (value != null) Root.SetProperty("collection", value);
else Root.RemoveProperty("collection");
}
}

Expand Down Expand Up @@ -160,10 +161,5 @@ public bool ShouldSerializeStacExtensions()

[JsonIgnore]
public IStacObject StacObjectContainer => this;

public object RasterExtension()
{
throw new NotImplementedException();
}
}
}
2 changes: 2 additions & 0 deletions src/DotNetStac/StacItemRootPropertyContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Stac
{
Expand All @@ -15,6 +16,7 @@ public StacItemRootPropertyContainer(StacItem stacItem)

public IDictionary<string, object> Properties { get => properties; internal set => properties = value; }

[ExcludeFromCodeCoverage]
public IStacObject StacObjectContainer => stacItem;
}
}

0 comments on commit 5b45f2c

Please sign in to comment.