diff --git a/ICD.Common.Utils.Tests/Extensions/DictionaryExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/DictionaryExtensionsTest.cs index ca6d2e5..f1c35ab 100644 --- a/ICD.Common.Utils.Tests/Extensions/DictionaryExtensionsTest.cs +++ b/ICD.Common.Utils.Tests/Extensions/DictionaryExtensionsTest.cs @@ -5,18 +5,18 @@ using System.Linq; namespace ICD.Common.Utils.Tests.Extensions { - [TestFixture] - public sealed class DictionaryExtensionsTest - { - [Test] - public void RemoveValueTest() - { + [TestFixture] + public sealed class DictionaryExtensionsTest + { + [Test] + public void RemoveValueTest() + { Dictionary dict = new Dictionary { - { 1, 10 }, - { 2, 20 }, - { 3, 30 }, - { 4, 40 }, + {1, 10}, + {2, 20}, + {3, 30}, + {4, 40}, }; Assert.IsTrue(dict.RemoveValue(10)); @@ -26,15 +26,15 @@ namespace ICD.Common.Utils.Tests.Extensions Assert.AreEqual(3, dict.Count); } - [Test] - public void RemoveAllValuesTest() - { + [Test] + public void RemoveAllValuesTest() + { Dictionary dict = new Dictionary { - { 1, 10 }, - { 2, 10 }, - { 3, 30 }, - { 4, 40 }, + {1, 10}, + {2, 10}, + {3, 30}, + {4, 40}, }; dict.RemoveAllValues(10); @@ -44,45 +44,45 @@ namespace ICD.Common.Utils.Tests.Extensions Assert.AreEqual(2, dict.Count); } - [Test] - public void GetDefaultTest() - { + [Test] + public void GetDefaultTest() + { Dictionary dict = new Dictionary { - { 1, 10 }, - { 2, 10 }, - { 3, 30 }, - { 4, 40 }, + {1, 10}, + {2, 10}, + {3, 30}, + {4, 40}, }; Assert.AreEqual(10, dict.GetDefault(1)); Assert.AreEqual(0, dict.GetDefault(0)); } - [Test] - public void GetDefaultValueTest() - { + [Test] + public void GetDefaultValueTest() + { Dictionary dict = new Dictionary { - { 1, 10 }, - { 2, 10 }, - { 3, 30 }, - { 4, 40 }, + {1, 10}, + {2, 10}, + {3, 30}, + {4, 40}, }; Assert.AreEqual(10, dict.GetDefault(1, 1000)); Assert.AreEqual(1000, dict.GetDefault(0, 1000)); } - [Test] - public void GetOrAddDefaultTest() - { + [Test] + public void GetOrAddDefaultTest() + { Dictionary dict = new Dictionary { - { 1, 10 }, - { 2, 10 }, - { 3, 30 }, - { 4, 40 }, + {1, 10}, + {2, 10}, + {3, 30}, + {4, 40}, }; Assert.AreEqual(10, dict.GetOrAddDefault(1, 1000)); @@ -91,81 +91,81 @@ namespace ICD.Common.Utils.Tests.Extensions Assert.AreEqual(5, dict.Count); } - [Test] - public void GetKeyTest() - { - Dictionary dict = new Dictionary - { - { 1, 10 }, - { 2, 20 }, - { 3, 30 } - }; + [Test] + public void GetKeyTest() + { + Dictionary dict = new Dictionary + { + {1, 10}, + {2, 20}, + {3, 30} + }; - Assert.AreEqual(1, dict.GetKey(10)); - Assert.AreEqual(2, dict.GetKey(20)); - Assert.AreEqual(3, dict.GetKey(30)); - Assert.Throws(() => dict.GetKey(40)); - } + Assert.AreEqual(1, dict.GetKey(10)); + Assert.AreEqual(2, dict.GetKey(20)); + Assert.AreEqual(3, dict.GetKey(30)); + Assert.Throws(() => dict.GetKey(40)); + } - [Test] - public void TryGetKeyTest() - { - Dictionary dict = new Dictionary - { - { 1, 10 }, - { 2, 20 }, - { 3, 30 } - }; + [Test] + public void TryGetKeyTest() + { + Dictionary dict = new Dictionary + { + {1, 10}, + {2, 20}, + {3, 30} + }; - int key; + int key; - Assert.IsTrue(dict.TryGetKey(10, out key)); - Assert.AreEqual(1, key); + Assert.IsTrue(dict.TryGetKey(10, out key)); + Assert.AreEqual(1, key); - Assert.IsTrue(dict.TryGetKey(20, out key)); - Assert.AreEqual(2, key); + Assert.IsTrue(dict.TryGetKey(20, out key)); + Assert.AreEqual(2, key); - Assert.IsTrue(dict.TryGetKey(30, out key)); - Assert.AreEqual(3, key); - } + Assert.IsTrue(dict.TryGetKey(30, out key)); + Assert.AreEqual(3, key); + } - [Test] - public void GetKeysTest() - { - Dictionary dict = new Dictionary - { - { 1, 10 }, - { 2, 10 }, - { 3, 30 } - }; + [Test] + public void GetKeysTest() + { + Dictionary dict = new Dictionary + { + {1, 10}, + {2, 10}, + {3, 30} + }; - int[] aKeys = dict.GetKeys(10).ToArray(); - int[] bKeys = dict.GetKeys(20).ToArray(); - int[] cKeys = dict.GetKeys(30).ToArray(); + int[] aKeys = dict.GetKeys(10).ToArray(); + int[] bKeys = dict.GetKeys(20).ToArray(); + int[] cKeys = dict.GetKeys(30).ToArray(); - Assert.AreEqual(2, aKeys.Length); - Assert.IsTrue(aKeys.Contains(1)); - Assert.IsTrue(aKeys.Contains(2)); + Assert.AreEqual(2, aKeys.Length); + Assert.IsTrue(aKeys.Contains(1)); + Assert.IsTrue(aKeys.Contains(2)); - Assert.AreEqual(0, bKeys.Length); + Assert.AreEqual(0, bKeys.Length); - Assert.AreEqual(1, cKeys.Length); - Assert.IsTrue(cKeys.Contains(3)); - } + Assert.AreEqual(1, cKeys.Length); + Assert.IsTrue(cKeys.Contains(3)); + } - [Test] - public void UpdateTest() - { + [Test] + public void UpdateTest() + { Dictionary a = new Dictionary { - { 1, 10 }, - { 2, 10 }, + {1, 10}, + {2, 10}, }; Dictionary b = new Dictionary { - { 2, 20 }, - { 3, 30 } + {2, 20}, + {3, 30} }; a.Update(b); @@ -181,51 +181,45 @@ namespace ICD.Common.Utils.Tests.Extensions } - [Test] - public void AddRangeValueKeyFuncTest() - { - Assert.Inconclusive(); - } + [Test] + public void AddRangeValueKeyFuncTest() + { + Assert.Inconclusive(); + } - [Test] - public void AddRangeKeyValueFuncTest() - { - Assert.Inconclusive(); - } + [Test] + public void AddRangeKeyValueFuncTest() + { + Assert.Inconclusive(); + } - [Test] - public void AddRangeTest() - { - Assert.Inconclusive(); - } + [Test] + public void AddRangeTest() + { + Assert.Inconclusive(); + } - [Test] - public void DictionaryEqualTest() - { - Assert.Inconclusive(); - } - - [Test] - public void DictionaryEqualComparerTest() - { + [Test] + public void DictionaryEqualTest() + { Dictionary a = new Dictionary { - { 1, 10 }, - { 2, 20 }, - { 3, 30 }, + {1, 10}, + {2, 20}, + {3, 30} }; Dictionary b = new Dictionary { - { 1, 10 }, - { 2, 20 }, - { 3, 30 }, + {1, 10}, + {2, 20}, + {3, 30} }; Dictionary c = new Dictionary { - { 1, 10 }, - { 2, 20 } + {1, 10}, + {2, 20} }; Assert.IsTrue(a.DictionaryEqual(b)); @@ -235,20 +229,50 @@ namespace ICD.Common.Utils.Tests.Extensions Assert.IsFalse(c.DictionaryEqual(a)); } - [Test] - public void DictionaryEqualFuncComparerTest() - { - Assert.Inconclusive(); - } + [Test] + public void DictionaryEqualComparerTest() + { + Assert.Inconclusive(); + } - [Test] - public void OrderByKeyTest() - { + [Test] + public void DictionaryEqualFuncComparerTest() + { Dictionary a = new Dictionary { - { 1, 10 }, - { 2, 20 }, - { 3, 30 }, + {1, 10}, + {2, 20}, + {3, 30} + }; + + Dictionary b = new Dictionary + { + {1, 10}, + {2, 20}, + {3, 30} + }; + + Dictionary c = new Dictionary + { + {1, 10}, + {2, 20} + }; + + Assert.IsTrue(a.DictionaryEqual(b, (left, right) => left / 10 == right / 10)); + Assert.IsTrue(b.DictionaryEqual(a, (left, right) => left / 10 == right / 10)); + + Assert.IsFalse(a.DictionaryEqual(c, (left, right) => left / 10 == right / 10)); + Assert.IsFalse(c.DictionaryEqual(a, (left, right) => left / 10 == right / 10)); + } + + [Test] + public void OrderByKeyTest() + { + Dictionary a = new Dictionary + { + {1, 10}, + {2, 20}, + {3, 30} }; KeyValuePair[] ordered = a.OrderByKey().ToArray(); @@ -259,14 +283,14 @@ namespace ICD.Common.Utils.Tests.Extensions Assert.AreEqual(30, ordered[2].Value); } - [Test] - public void OrderValuesByKeyTest() - { + [Test] + public void OrderValuesByKeyTest() + { Dictionary a = new Dictionary { - { 1, 10 }, - { 2, 20 }, - { 3, 30 }, + {1, 10}, + {2, 20}, + {3, 30}, }; int[] ordered = a.OrderValuesByKey().ToArray(); @@ -276,5 +300,5 @@ namespace ICD.Common.Utils.Tests.Extensions Assert.AreEqual(20, ordered[1]); Assert.AreEqual(30, ordered[2]); } - } + } } diff --git a/ICD.Common.Utils.Tests/ReflectionUtilsTest.cs b/ICD.Common.Utils.Tests/ReflectionUtilsTest.cs index 28458dc..81b34d9 100644 --- a/ICD.Common.Utils.Tests/ReflectionUtilsTest.cs +++ b/ICD.Common.Utils.Tests/ReflectionUtilsTest.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using System; using System.Collections.Generic; +using ICD.Common.Properties; #if SIMPLSHARP using Crestron.SimplSharp.Reflection; #else @@ -10,18 +11,21 @@ using System.Reflection; namespace ICD.Common.Utils.Tests { [TestFixture] - public sealed class ReflectionUtilsTest - { + public sealed class ReflectionUtilsTest + { + [UsedImplicitly] private string TestProperty { get; set; } + [UsedImplicitly] private void TestMethod(string param1, int param2) { } - private class TestClass + [UsedImplicitly] + private sealed class TestClass { - public string Param1 { get; set; } - public int Param2 { get; set; } + public string Param1 { get; } + public int Param2 { get; } public TestClass(string param1, int param2) { @@ -46,31 +50,31 @@ namespace ICD.Common.Utils.Tests { Assert.Throws(() => ReflectionUtils.MatchesConstructorParameters(null, new object[] { "test", 10 })); - ConstructorInfo constructor = typeof(TestClass).GetConstructor(new Type[] { typeof(string), typeof(int) }); + ConstructorInfo constructor = typeof(TestClass).GetConstructor(new Type[] {typeof(string), typeof(int)}); - Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test", 10 })); - Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { null, 10 })); - Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test", "test" })); - Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test" })); - Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test", "test", "test" })); - Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { 10, 10 })); + Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", 10})); + Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {null, 10})); + Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", "test"})); + Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test"})); + Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", "test", "test"})); + Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {10, 10})); } [Test] public void MatchesMethodParametersTest() { - Assert.Throws(() => ReflectionUtils.MatchesMethodParameters(null, new object[] { "test", 10 })); + Assert.Throws(() => ReflectionUtils.MatchesMethodParameters(null, new object[] {"test", 10})); MethodInfo method = GetType().GetMethod("TestMethod", - BindingFlags.NonPublic | - BindingFlags.Instance); + BindingFlags.NonPublic | + BindingFlags.Instance); - Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test", 10 })); - Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] { null, 10 })); - Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test", "test" })); - Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test" })); - Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test", "test", "test" })); - Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { 10, 10 })); + Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test", 10})); + Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] {null, 10})); + Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test", "test"})); + Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test"})); + Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test", "test", "test"})); + Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {10, 10})); } [Test] @@ -79,9 +83,9 @@ namespace ICD.Common.Utils.Tests Assert.Throws(() => ReflectionUtils.MatchesPropertyParameter(null, 10)); PropertyInfo prop = GetType().GetProperty("TestProperty", - BindingFlags.NonPublic | - BindingFlags.Instance | - BindingFlags.GetProperty); + BindingFlags.NonPublic | + BindingFlags.Instance | + BindingFlags.GetProperty); Assert.IsTrue(ReflectionUtils.MatchesPropertyParameter(prop, "test")); Assert.IsTrue(ReflectionUtils.MatchesPropertyParameter(prop, null));