Skip to content

Commit

Permalink
more cov on core
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed May 25, 2021
1 parent 5b45f2c commit b62ff93
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 11 deletions.
74 changes: 73 additions & 1 deletion src/DotNetStac.Test/Item/ItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public void CanSerializeMinimalSample()

var properties = new Dictionary<string, object>();

properties.Add("datetime", DateTime.Parse("2016-05-03T13:21:30.040Z").ToUniversalTime());
properties.Add("collection", "CS3");

StacItem item = new StacItem("CS3-20160503_132130_04", geometry, properties);

item.CommonMetadata().DateTime = new Itenso.TimePeriod.TimeInterval(DateTime.Parse("2016-05-03T13:21:30.040Z"));

item.Links.Add(StacLink.CreateSelfLink(new Uri("http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.json")));
item.SetCollection("cool-sat", new Uri("http://cool-sat.com/catalog.json"));

Expand All @@ -99,6 +100,77 @@ public void CanSerializeMinimalSample()
Assert.Null(item.Collection);
}

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

var geometry = new Polygon(new LineString[] { new LineString(coordinates[0]) });

var properties = new Dictionary<string, object>();

properties.Add("collection", "CS3");

StacItem item = new StacItem("CS3-20160503_132130_04", geometry, properties);

item.CommonMetadata().DateTime = new Itenso.TimePeriod.TimeInterval(DateTime.MinValue, DateTime.MaxValue);
item.CommonMetadata().DateTime = new Itenso.TimePeriod.TimeInterval(DateTime.Parse("2016-05-03T13:21:30.040Z"), DateTime.Parse("2016-05-03T14:21:30.040Z"));

item.Links.Add(StacLink.CreateSelfLink(new Uri("http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.json")));
item.SetCollection("cool-sat", new Uri("http://cool-sat.com/catalog.json"));

item.Assets.Add("analytic", new StacAsset(item, new Uri("relative-path/to/analytic.tif", UriKind.Relative), null, "4-Band Analytic", null));
item.Assets.Add("thumbnail", StacAsset.CreateThumbnailAsset(item, new Uri("http://cool-sat.com/catalog/CS3-20160503_132130_04/thumbnail.png"), null, "Thumbnail"));

item.CommonMetadata().Created = new DateTime(2018, 1, 1);
item.CommonMetadata().Updated = new DateTime(2018, 1, 1);

Assert.Equal(new DateTime(2018, 1, 1), item.CommonMetadata().Created);
Assert.Equal(new DateTime(2018, 1, 1), item.CommonMetadata().Updated);

item.CommonMetadata().Gsd = 0;
item.CommonMetadata().Gsd = 1;
Assert.Equal(1, item.CommonMetadata().Gsd);

item.CommonMetadata().Title = "CS3-20160503_132130_04";
Assert.Equal("CS3-20160503_132130_04", item.CommonMetadata().Title);

item.CommonMetadata().Platform = "coolsat-3";
Assert.Equal("coolsat-3", item.CommonMetadata().Platform);

item.CommonMetadata().Mission = "coolsat-3";
Assert.Equal("coolsat-3", item.CommonMetadata().Mission);

item.CommonMetadata().Constellation = "coolsat";
Assert.Equal("coolsat", item.CommonMetadata().Constellation);

// item.BoundingBoxes = new double[4] { -122.59750209, 37.48803556, -122.2880486, 37.613537207 };
item.BoundingBoxes = item.GetBoundingBoxFromGeometryExtent();

var actualJson = StacConvert.Serialize(item);

ValidateJson(actualJson);

var expectedJson = GetJson("Item");

ValidateJson(expectedJson);

JsonAssert.AreEqual(expectedJson, actualJson);

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

[Fact]
public void CanManageDates()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"stac_version": "1.0.0-rc.4",
"type": "Feature",
"id": "CS3-20160503_132130_04",
"bbox": [
-122.597502109,
37.488035566,
-122.2880486,
37.613537207
],
"collection": "cool-sat",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-122.308150179,
37.488035566
],
[
-122.597502109,
37.538869539
],
[
-122.576687533,
37.613537207
],
[
-122.288048600,
37.562818007
],
[
-122.308150179,
37.488035566
]
]
]
},
"properties": {
"title": "CS3-20160503_132130_04",
"platform": "coolsat-3",
"mission": "coolsat-3",
"constellation": "coolsat",
"datetime": "2016-05-03T13:21:30.040Z",
"start_datetime": "2016-05-03T13:21:30.040Z",
"end_datetime": "2016-05-03T14:21:30.040Z",
"collection": "CS3",
"created": "2018-01-01T00:00:00Z",
"updated": "2018-01-01T00:00:00Z",
"gsd": 1.0
},
"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"
]
}
}
}
2 changes: 2 additions & 0 deletions src/DotNetStac/StacAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json;
using System.Net.Mime;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis;

namespace Stac
{
Expand Down Expand Up @@ -229,6 +230,7 @@ public IDictionary<string, object> Properties
public IStacObject ParentStacObject { get => parentStacObject; internal set => parentStacObject = value; }

#pragma warning disable 1591
[ExcludeFromCodeCoverage]
public bool ShouldSerializeStacExtensions()
{
// don't serialize the Manager property if an employee is their own manager
Expand Down
19 changes: 9 additions & 10 deletions src/DotNetStac/StacCommonMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,25 @@ public Itenso.TimePeriod.ITimePeriod DateTime
}
set
{
// remove previous values
stacPropertiesContainer.Properties.Remove("datetime");
stacPropertiesContainer.Properties.Remove("start_datetime");
stacPropertiesContainer.Properties.Remove("end_datetime");

// datetime, start_datetime, end_datetime
if (value.IsAnytime)
{
stacPropertiesContainer.Properties.Add("datetime", null);
stacPropertiesContainer.RemoveProperty("start_datetime");
stacPropertiesContainer.RemoveProperty("end_datetime");
stacPropertiesContainer.SetProperty("datetime", null);
}

if (value.IsMoment)
{
stacPropertiesContainer.Properties.Add("datetime", value.Start);
stacPropertiesContainer.RemoveProperty("start_datetime");
stacPropertiesContainer.RemoveProperty("end_datetime");
stacPropertiesContainer.SetProperty("datetime", value.Start);
}
else
{
stacPropertiesContainer.Properties.Add("datetime", value.Start);
stacPropertiesContainer.Properties.Add("start_datetime", value.Start);
stacPropertiesContainer.Properties.Add("end_datetime", value.End);
stacPropertiesContainer.SetProperty("datetime", value.Start);
stacPropertiesContainer.SetProperty("start_datetime", value.Start);
stacPropertiesContainer.SetProperty("end_datetime", value.End);
}
}
}
Expand Down

0 comments on commit b62ff93

Please sign in to comment.