From 35811f82734fe15da25ac7562f3d3363f0860660 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 13 Oct 2017 17:10:44 -0400 Subject: [PATCH] Tidying, additional test stubs --- .../Extensions/HashSetExtensionsTest.cs | 50 +++++++++++++++++++ .../Extensions/JsonExtensionsTest.cs | 38 ++++++++++++++ .../Extensions/ReflectionExtensionsTest.cs | 14 ++++++ ICD.Common.Utils/AttributeUtils.cs | 9 ++-- .../Attributes/Rpc/RpcAttribute.cs | 12 ++--- .../Extensions/ReflectionExtensions.cs | 8 +-- 6 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 ICD.Common.Utils.Tests/Extensions/HashSetExtensionsTest.cs create mode 100644 ICD.Common.Utils.Tests/Extensions/JsonExtensionsTest.cs create mode 100644 ICD.Common.Utils.Tests/Extensions/ReflectionExtensionsTest.cs diff --git a/ICD.Common.Utils.Tests/Extensions/HashSetExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/HashSetExtensionsTest.cs new file mode 100644 index 0000000..330d969 --- /dev/null +++ b/ICD.Common.Utils.Tests/Extensions/HashSetExtensionsTest.cs @@ -0,0 +1,50 @@ +using NUnit.Framework; + +namespace ICD.Common.Utils.Tests.Extensions +{ + [TestFixture] + public sealed class HashSetExtensionsTest + { + [Test] + public void SubtractTest() + { + Assert.Inconclusive(); + } + + [Test] + public void IsSubsetOfTest() + { + Assert.Inconclusive(); + } + + [Test] + public void IntersectionTest() + { + Assert.Inconclusive(); + } + + [Test] + public void NonIntersectionTest() + { + Assert.Inconclusive(); + } + + [Test] + public void IsProperSubsetOfTest() + { + Assert.Inconclusive(); + } + + [Test] + public void IsSupersetOfTest() + { + Assert.Inconclusive(); + } + + [Test] + public void IsProperSupersetOfTest() + { + Assert.Inconclusive(); + } + } +} diff --git a/ICD.Common.Utils.Tests/Extensions/JsonExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/JsonExtensionsTest.cs new file mode 100644 index 0000000..7327c7f --- /dev/null +++ b/ICD.Common.Utils.Tests/Extensions/JsonExtensionsTest.cs @@ -0,0 +1,38 @@ +using NUnit.Framework; + +namespace ICD.Common.Utils.Tests.Extensions +{ + [TestFixture] + public sealed class JsonExtensionsTest + { + [Test] + public void WriteObjectTest() + { + Assert.Inconclusive(); + } + + [Test] + public void GetValueAsIntTest() + { + Assert.Inconclusive(); + } + + [Test] + public void GetValueAsStringTest() + { + Assert.Inconclusive(); + } + + [Test] + public void GetValueAsBoolTest() + { + Assert.Inconclusive(); + } + + [Test] + public void GetValueAsEnumTest() + { + Assert.Inconclusive(); + } + } +} diff --git a/ICD.Common.Utils.Tests/Extensions/ReflectionExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/ReflectionExtensionsTest.cs new file mode 100644 index 0000000..2b03880 --- /dev/null +++ b/ICD.Common.Utils.Tests/Extensions/ReflectionExtensionsTest.cs @@ -0,0 +1,14 @@ +using NUnit.Framework; + +namespace ICD.Common.Utils.Tests.Extensions +{ + [TestFixture] + public sealed class ReflectionExtensionsTest + { + [Test] + public void GetCustomAttributesTest() + { + Assert.Inconclusive(); + } + } +} diff --git a/ICD.Common.Utils/AttributeUtils.cs b/ICD.Common.Utils/AttributeUtils.cs index 1201088..7f5f343 100644 --- a/ICD.Common.Utils/AttributeUtils.cs +++ b/ICD.Common.Utils/AttributeUtils.cs @@ -112,16 +112,17 @@ namespace ICD.Common.Utils s_TypeToAttributesCache[type] = new IcdHashSet(type.GetCustomAttributes(false)); methods = type.GetMethods(); #else - s_TypeToAttributesCache[type] = new IcdHashSet(type.GetTypeInfo().GetCustomAttributes(false)); - methods = type.GetTypeInfo().GetMethods(); + s_TypeToAttributesCache[type] = + new IcdHashSet(ReflectionExtensions.GetCustomAttributes(type.GetTypeInfo(), false)); + methods = type.GetTypeInfo().GetMethods(); #endif } - // GetMethods for Open Generic Types is not supported. + // GetMethods for Open Generic Types is not supported. catch (NotSupportedException) { return; } - // Not sure why this happens :/ + // Not sure why this happens :/ catch (InvalidProgramException) { return; diff --git a/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs b/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs index eaeb64a..e7f0bab 100644 --- a/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs +++ b/ICD.Common.Utils/Attributes/Rpc/RpcAttribute.cs @@ -111,13 +111,13 @@ namespace ICD.Common.Attributes.Rpc #if SIMPLSHARP .GetCType() #else - .GetTypeInfo() + .GetTypeInfo() #endif .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - .Where(m => m.GetCustomAttributes(true) - .Any(a => a.m_Key == key)) + .Where(m => ReflectionExtensions.GetCustomAttributes(m, true) + .Any(a => a.m_Key == key)) .ToHashSet(); } @@ -154,13 +154,13 @@ namespace ICD.Common.Attributes.Rpc #if SIMPLSHARP .GetCType() #else - .GetTypeInfo() + .GetTypeInfo() #endif .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - .Where(p => p.CanWrite && p.GetCustomAttributes(true) - .Any(a => a.m_Key == key)) + .Where(p => p.CanWrite && ReflectionExtensions.GetCustomAttributes(p, true) + .Any(a => a.m_Key == key)) .ToHashSet(); } diff --git a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs index c26f090..2b2a656 100644 --- a/ICD.Common.Utils/Extensions/ReflectionExtensions.cs +++ b/ICD.Common.Utils/Extensions/ReflectionExtensions.cs @@ -1,8 +1,11 @@ -#if SIMPLSHARP -using System; +using System; using System.Collections.Generic; using System.Linq; +#if SIMPLSHARP using Crestron.SimplSharp.Reflection; +#else +using System.Reflection; +#endif namespace ICD.Common.Utils.Extensions { @@ -28,4 +31,3 @@ namespace ICD.Common.Utils.Extensions } } } -#endif