From 472b1639fb3decd4d4e8693345ad2264f95eb03b Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Wed, 22 Feb 2023 08:21:19 +0100 Subject: [PATCH] LazyEnumParse tests --- README.md | 4 +-- src/DotNetStac.Test/Common/Enum/Enum.cs | 30 +++++++++++++++++++ .../Common/StacAccessorsHelpersTests.cs | 17 ++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/DotNetStac.Test/Common/Enum/Enum.cs diff --git a/README.md b/README.md index 29f1b6f6..431d4e07 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@

-![Build Status](https://github.com/Terradue/DotNetStac/actions/workflows/build.yaml/badge.svg?branch=feature/dc) +![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/dc/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) diff --git a/src/DotNetStac.Test/Common/Enum/Enum.cs b/src/DotNetStac.Test/Common/Enum/Enum.cs new file mode 100644 index 00000000..9113cf51 --- /dev/null +++ b/src/DotNetStac.Test/Common/Enum/Enum.cs @@ -0,0 +1,30 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; + +namespace Stac.Test.Common +{ + public enum Enum1 + { + test, + + summary + } + + public enum Enum2 + { + [JsonProperty("test")] + Test, + + [JsonProperty("summary")] + Summary + } + + public enum Enum3 + { + [EnumMember(Value = @"cql2-text")] + Cql2Text, + + [EnumMember(Value = @"cql2-json")] + Cql2Json + } +} diff --git a/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs b/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs index a0db1e5b..6146c2b8 100644 --- a/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs +++ b/src/DotNetStac.Test/Common/StacAccessorsHelpersTests.cs @@ -8,7 +8,7 @@ using Stac.Common; using Xunit; -namespace Stac.Test.Item +namespace Stac.Test.Common { public class StacAccessorsHelpersTests : TestBase { @@ -73,5 +73,20 @@ public void GetPropertyTest() Assert.Equal(summaryItemType, item.GetProperty("summary")); } + + [Fact] + public void LazyEnumParseTests() + { + Enum1 test = Enum1.test; + Assert.Equal(test, StacAccessorsHelpers.LazyEnumParse(typeof(Enum1), "test")); + + Enum2 test2 = Enum2.Test; + Assert.Equal(test2, StacAccessorsHelpers.LazyEnumParse(typeof(Enum2), "test")); + + Enum3 test3 = Enum3.Cql2Json; + Assert.Equal(test3, StacAccessorsHelpers.LazyEnumParse(typeof(Enum3), "cql2-json")); + + Assert.Equal(test3, StacAccessorsHelpers.LazyEnumParse(typeof(Enum3), "Cql2Json")); + } } }