From 0488464c2c522e272afe9528540294fe7cd2af1b Mon Sep 17 00:00:00 2001 From: fsimonazzi Date: Mon, 7 Apr 2014 18:57:00 -0300 Subject: [PATCH] (split) add xamarin tests project. refactor existing tests to work with nunit lite and reimplement missing assert functionality. --- ...dParameterKindsAreProperlyHandledHelper.cs | 20 ++++++------- .../InterfaceInterceptorFixture.cs | 8 ++--- .../ParameterCollectionFixture.cs | 29 ++++++++++--------- .../Tests.Unity.Interception/PolicyFixture.cs | 7 +++-- .../TransparentProxyInterceptorFixture.cs | 19 ++++++------ 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/Tests/Tests.Unity.Interception/AssortedParameterKindsAreProperlyHandledHelper.cs b/Tests/Tests.Unity.Interception/AssortedParameterKindsAreProperlyHandledHelper.cs index 74a3f65..748fa3e 100644 --- a/Tests/Tests.Unity.Interception/AssortedParameterKindsAreProperlyHandledHelper.cs +++ b/Tests/Tests.Unity.Interception/AssortedParameterKindsAreProperlyHandledHelper.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. -using System; using System.Linq; +using Microsoft.Practices.Unity.TestSupport; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.Practices.Unity.InterceptionExtension.Tests @@ -71,19 +71,19 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests Assert.AreEqual(84, param4); Assert.AreEqual(5, argumentsCount); - CollectionAssert.AreEqual(new[] { 1, 0, 3, 4, 5 }, argumentsValuesByIndex); - CollectionAssert.AreEqual(new[] { "param1", "param2", "param3", "param4", "param5" }, argumentsNames); - CollectionAssert.AreEqual(new[] { 1, 0, 3, 4, 5 }, argumentsValuesByName); + CollectionAssertExtensions.AreEqual(new[] { 1, 0, 3, 4, 5 }, argumentsValuesByIndex); + CollectionAssertExtensions.AreEqual(new[] { "param1", "param2", "param3", "param4", "param5" }, argumentsNames); + CollectionAssertExtensions.AreEqual(new[] { 1, 0, 3, 4, 5 }, argumentsValuesByName); Assert.AreEqual(4, inputsCount); - CollectionAssert.AreEqual(new[] { 1, 3, 4, 5 }, inputsValuesByIndex); - CollectionAssert.AreEqual(new[] { "param1", "param3", "param4", "param5" }, inputsNames); - CollectionAssert.AreEqual(new[] { 1, 3, 4, 5 }, inputsValuesByName); + CollectionAssertExtensions.AreEqual(new[] { 1, 3, 4, 5 }, inputsValuesByIndex); + CollectionAssertExtensions.AreEqual(new[] { "param1", "param3", "param4", "param5" }, inputsNames); + CollectionAssertExtensions.AreEqual(new[] { 1, 3, 4, 5 }, inputsValuesByName); Assert.AreEqual(2, outputsCount); - CollectionAssert.AreEqual(new[] { 25, 39 }, outputsValuesByIndex); - CollectionAssert.AreEqual(new[] { "param2", "param4" }, outputsNames); - CollectionAssert.AreEqual(new[] { 25, 39 }, outputsValuesByName); + CollectionAssertExtensions.AreEqual(new[] { 25, 39 }, outputsValuesByIndex); + CollectionAssertExtensions.AreEqual(new[] { "param2", "param4" }, outputsNames); + CollectionAssertExtensions.AreEqual(new[] { 25, 39 }, outputsValuesByName); Assert.AreEqual(11 + 25 + 13 + 39 + 15, originalReturnValue); } diff --git a/Tests/Tests.Unity.Interception/InterfaceInterception/InterfaceInterceptorFixture.cs b/Tests/Tests.Unity.Interception/InterfaceInterception/InterfaceInterceptorFixture.cs index 5cfb1dc..abab4b1 100644 --- a/Tests/Tests.Unity.Interception/InterfaceInterception/InterfaceInterceptorFixture.cs +++ b/Tests/Tests.Unity.Interception/InterfaceInterception/InterfaceInterceptorFixture.cs @@ -41,7 +41,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.InterfaceInterce new MethodImplementationInfo(typeof(IInterfaceOne).GetMethod("TargetMethod"), typeof(ImplementationOne).GetMethod("TargetMethod"))).ToList(); - CollectionAssert.AreEquivalent(expected, methods); + CollectionAssertExtensions.AreEquivalent(expected, methods); } [TestMethod] @@ -58,7 +58,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.InterfaceInterce typeof(InterfaceBase).GetMethod("Method3"))) .ToList(); - CollectionAssert.AreEquivalent(expected, methods); + CollectionAssertExtensions.AreEquivalent(expected, methods); } @@ -76,7 +76,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.InterfaceInterce typeof(WrappableThroughInterface).GetMethod("Method3"))) .ToList(); - CollectionAssert.AreEquivalent(expected, methods); + CollectionAssertExtensions.AreEquivalent(expected, methods); } [TestMethod] @@ -89,7 +89,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.InterfaceInterce GetExpectedMethods, GenericImplementationOne>("DoSomething") .ToList(); - CollectionAssert.AreEquivalent(expected, methods); + CollectionAssertExtensions.AreEquivalent(expected, methods); } [TestMethod] diff --git a/Tests/Tests.Unity.Interception/ParameterCollectionFixture.cs b/Tests/Tests.Unity.Interception/ParameterCollectionFixture.cs index 8c8a1e4..4953fc3 100644 --- a/Tests/Tests.Unity.Interception/ParameterCollectionFixture.cs +++ b/Tests/Tests.Unity.Interception/ParameterCollectionFixture.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. using System.Linq; +using Microsoft.Practices.Unity.TestSupport; using Microsoft.Practices.Unity.Utility; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -19,19 +20,19 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests pi => true); Assert.AreEqual(5, collection.Count); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { 10, 20, 30, 40, 50 }, collection); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { 50, 20, 40, 30, 10 }, new[] { 4, 1, 3, 2, 0 }.Select(i => collection[i]).ToArray()); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { 50, 20, 40, 30, 10 }, new[] { "param5", "param2", "param4", "param3", "param1" }.Select(i => collection[i]).ToArray()); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { "param1", "param2", "param3", "param4", "param5" }, Enumerable.Range(0, 5).Select(i => collection.ParameterName(i)).ToArray()); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { "param1", "param2", "param3", "param4", "param5" }, Enumerable.Range(0, 5).Select(i => collection.GetParameterInfo(i).Name).ToArray()); } @@ -47,19 +48,19 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests pi => param++ % 2 == 1); Assert.AreEqual(3, collection.Count); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { 10, 30, 50 }, collection); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { 50, 30, 10 }, new[] { 2, 1, 0 }.Select(i => collection[i]).ToArray()); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { 50, 30, 10 }, new[] { "param5", "param3", "param1" }.Select(i => collection[i]).ToArray()); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { "param1", "param3", "param5" }, Enumerable.Range(0, 3).Select(i => collection.ParameterName(i)).ToArray()); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( new[] { "param1", "param3", "param5" }, Enumerable.Range(0, 3).Select(i => collection.GetParameterInfo(i).Name).ToArray()); } @@ -70,12 +71,12 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests object dummy; object dummy2; var inputsCollection = - new ParameterCollection(new object[] {"one", "two", "three", "four"}, + new ParameterCollection(new object[] { "one", "two", "three", "four" }, StaticReflection.GetMethodInfo(() => MethodWithOuts(out dummy, null, out dummy2, null)).GetParameters(), pi => !pi.IsOut); Assert.AreEqual(2, inputsCollection.Count); - CollectionAssert.AreEqual(new object[] {"two", "four"}, inputsCollection); + CollectionAssertExtensions.AreEqual(new object[] { "two", "four" }, inputsCollection); Assert.AreEqual("two", inputsCollection["param2"]); Assert.AreEqual("four", inputsCollection["param4"]); } @@ -103,8 +104,8 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests StaticReflection.GetMethodInfo(() => TestMethod(null, null, null, null, null)).GetParameters(), p => true); - Assert.IsTrue(new [] {"param1", "param2", "param3", "param4", "param5"}.All(collection.ContainsParameter)); - Assert.IsTrue(new[] {"someOtherParam", "notThisOneEither"}.All(p => !collection.ContainsParameter(p))); + Assert.IsTrue(new[] { "param1", "param2", "param3", "param4", "param5" }.All(collection.ContainsParameter)); + Assert.IsTrue(new[] { "someOtherParam", "notThisOneEither" }.All(p => !collection.ContainsParameter(p))); } public static void TestMethod(object param1, object param2, object param3, object param4, object param5) diff --git a/Tests/Tests.Unity.Interception/PolicyFixture.cs b/Tests/Tests.Unity.Interception/PolicyFixture.cs index 66b3b50..91125a3 100644 --- a/Tests/Tests.Unity.Interception/PolicyFixture.cs +++ b/Tests/Tests.Unity.Interception/PolicyFixture.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; using Microsoft.Practices.Unity.InterceptionExtension.Tests.ObjectsUnderTest; +using Microsoft.Practices.Unity.TestSupport; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.Practices.Unity.InterceptionExtension.Tests @@ -70,7 +71,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests List expectedHandlers = new List(container.ResolveAll()); List actualHandlers = new List(p.GetHandlersFor(member, container)); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( expectedHandlers, actualHandlers, new TypeComparer()); @@ -90,7 +91,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests List expectedHandlers = new List(container.ResolveAll()); List actualHandlers = new List(p.GetHandlersFor(getMethod, container)); - CollectionAssert.AreEqual( + CollectionAssertExtensions.AreEqual( expectedHandlers, actualHandlers, new TypeComparer()); @@ -116,7 +117,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests private static MethodImplementationInfo GetMethodImplInfo(string methodName) { return new MethodImplementationInfo(null, - typeof (T).GetMethod(methodName)); + typeof(T).GetMethod(methodName)); } } diff --git a/Tests/Tests.Unity.Interception/TransparentProxyInterception/TransparentProxyInterceptorFixture.cs b/Tests/Tests.Unity.Interception/TransparentProxyInterception/TransparentProxyInterceptorFixture.cs index a557974..90706bf 100644 --- a/Tests/Tests.Unity.Interception/TransparentProxyInterception/TransparentProxyInterceptorFixture.cs +++ b/Tests/Tests.Unity.Interception/TransparentProxyInterception/TransparentProxyInterceptorFixture.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using Microsoft.Practices.Unity.TestSupport; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxyInterception @@ -16,7 +17,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy { List methods = GetMethods(); - CollectionAssert.AreEquivalent(GetOnlyImplementations(typeof(SingleInterceptableMethod), "MyMethod"), + CollectionAssertExtensions.AreEquivalent(GetOnlyImplementations(typeof(SingleInterceptableMethod), "MyMethod"), methods); } @@ -25,7 +26,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy { List methods = GetMethods(); - CollectionAssert.AreEquivalent( + CollectionAssertExtensions.AreEquivalent( GetOnlyImplementations(typeof(InheritsSingleMethodAndAdds), "MyMethod", "AnotherMethod", "StillMoreMethod"), methods); } @@ -39,7 +40,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy List expected = GetExpectedMethodImplementations(typeof(IMyOperations), typeof(Operations)); - CollectionAssert.AreEquivalent(expected, methods); + CollectionAssertExtensions.AreEquivalent(expected, methods); } [TestMethod] @@ -47,7 +48,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy { List methods = GetMethods(); - CollectionAssert.AreEquivalent( + CollectionAssertExtensions.AreEquivalent( GetExpectedMethodImplementations(typeof(IMyOperations), typeof(Incoherent)) .Concat(GetExpectedMethodImplementations(typeof(ImTiredOfInterfaces), typeof(Incoherent))).ToList(), methods); @@ -58,7 +59,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy { List methods = GetMethods(); - CollectionAssert.AreEquivalent( + CollectionAssertExtensions.AreEquivalent( GetExpectedMethodImplementations(typeof(IMyOperations), typeof(Marked)), methods); } @@ -68,7 +69,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy { List methods = GetMethods(); - CollectionAssert.AreEquivalent( + CollectionAssertExtensions.AreEquivalent( GetOnlyImplementations(typeof(HasProperties), "get_SettableProp", "set_SettableProp", "get_GetOnly"), methods); } @@ -78,7 +79,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy { List methods = GetMethods(); - CollectionAssert.AreEquivalent( + CollectionAssertExtensions.AreEquivalent( GetExpectedMethodImplementations(typeof(IHasProperties), typeof(PropThroughInterface)), methods); } @@ -91,7 +92,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy var expected = GetExpectedMethodImplementations(typeof(IHasProperties), typeof(MBROWithPropThroughInterface)) .Concat(GetOnlyImplementations(typeof(MBROWithPropThroughInterface), "get_Gettable")); - CollectionAssert.AreEquivalent(expected.ToList(), methods); + CollectionAssertExtensions.AreEquivalent(expected.ToList(), methods); } [TestMethod] @@ -101,7 +102,7 @@ namespace Microsoft.Practices.Unity.InterceptionExtension.Tests.TransparentProxy var expected = GetExpectedMethodImplementations(typeof(IMyOperations), typeof(ExplicitImplementation)) .Concat(GetOnlyImplementations(typeof(ExplicitImplementation), "AClassMethod")); - CollectionAssert.AreEquivalent(expected.ToList(), methods); + CollectionAssertExtensions.AreEquivalent(expected.ToList(), methods); } [TestMethod]