Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure Search] Add new skill and cognitive services attachment to SDK #5223

Merged
merged 15 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public override string ToString()

private static Dictionary<string, T> CreateNameMap()
{
IEnumerable<FieldInfo> allPublicStaticFields =
IEnumerable<FieldInfo> allNonObsoletePublicStaticFields =
typeof(T).GetTypeInfo().DeclaredFields
.Where(f => f.IsStatic && f.IsPublic && f.GetCustomAttribute(typeof(ObsoleteAttribute), false) != null);
.Where(f => f.IsStatic && f.IsPublic && f.GetCustomAttribute(typeof(ObsoleteAttribute), false) == null);

IEnumerable<T> allKnownValues =
allPublicStaticFields
allNonObsoletePublicStaticFields
.Where(f => f.FieldType == typeof(T))
.Select(f => f.GetValue(null))
.OfType<T>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Microsoft.Azure.Search.Tests
{
using Microsoft.Azure.Search.Models;
using System;
using System.Linq;
using System.Reflection;
using Xunit;

public class ExtensibleEnumTests
Expand Down Expand Up @@ -69,6 +72,23 @@ public void CannotCompareDifferentEnumsForEquality()
Assert.False(TestEnum.A.Equals((object)TestEnum2.A));
}

[Fact]
public void CanCreateNonObsoleteTypeFromValue()
{
TestEnumWithObsolete notObsolete = TestEnumWithObsolete.Create("NotObsolete");
Assert.Same(TestEnumWithObsolete.NotObsolete, notObsolete);
}

[Fact]
public void CannotCreateObsoleteTypeFromValue()
{
// this should result in a new TestEnumWithObsolete instance being created
TestEnumWithObsolete obsolete = TestEnumWithObsolete.Create("Obsolete");
#pragma warning disable CS0612 // Type or member is obsolete
Assert.NotSame(TestEnumWithObsolete.Obsolete, obsolete);
#pragma warning restore CS0612 // Type or member is obsolete
}

private class TestEnum : ExtensibleEnum<TestEnum>
{
public static readonly TestEnum A = new TestEnum("a");
Expand All @@ -90,5 +110,20 @@ private TestEnum2(string name) : base(name) { }

public static TestEnum2 Create(string name) => Lookup(name) ?? new TestEnum2(name);
}

private class TestEnumWithObsolete : ExtensibleEnum<TestEnumWithObsolete>
{
public static readonly TestEnumWithObsolete NotObsolete = new TestEnumWithObsolete("NotObsolete");

[Obsolete]
public static readonly TestEnumWithObsolete Obsolete = new TestEnumWithObsolete("NotObsolete");

[Obsolete]
public static readonly TestEnumWithObsolete Obsolete2 = new TestEnumWithObsolete("Obsolete");

private TestEnumWithObsolete(string name) : base(name) { }

public static TestEnumWithObsolete Create(string name) => Lookup(name) ?? new TestEnumWithObsolete(name);
}
}
}