Permalink
Browse files

- upgrading xUnit.net to v1.6.1

- updating AssertPatched accordingly
  • Loading branch information...
1 parent 628c7c9 commit bb3fe07ac21f2a446d0f80e3632eb35734c3f0cb @mckamey mckamey committed Jul 28, 2010
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
<TestRunner>
- <FriendlyName>xUnit.net {0}.{1} build {3}</FriendlyName>
+ <FriendlyName>xUnit.net {0}.{1}.{2} build {3}</FriendlyName>
<AssemblyPath>xunit.runner.tdnet.dll</AssemblyPath>
<TypeName>Xunit.Runner.TdNet.TdNetRunner</TypeName>
</TestRunner>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -103,6 +103,11 @@
Gets the version of xunit.dll used by the test assembly.
</summary>
</member>
+ <member name="M:Xunit.ExecutorWrapper.#cctor">
+ <summary>
+ Initializes the <see cref="T:Xunit.ExecutorWrapper"/> class.
+ </summary>
+ </member>
<member name="M:Xunit.ExecutorWrapper.#ctor(System.String,System.String,System.Boolean)">
<summary>
Initializes a new instance of the <see cref="T:Xunit.ExecutorWrapper"/> class.
@@ -34,6 +34,16 @@
<param name="comparer">The comparer used to equate objects in the collection with the expected object</param>
<exception cref="T:Xunit.Sdk.ContainsException">Thrown when the object is not present in the collection</exception>
</member>
+ <member name="M:Xunit.Assert.Contains(System.String,System.Collections.Generic.IEnumerable{System.String},System.StringComparer)">
+ <summary>
+ Verifies that a collection contains a given string, using a string comparer.
+ </summary>
+ <typeparam name="T">The type of the object to be verified</typeparam>
+ <param name="expected">The string expected to be in the collection</param>
+ <param name="collection">The collection to be inspected</param>
+ <param name="comparer">The comparer used to equate objects in the collection with the expected string</param>
+ <exception cref="T:Xunit.Sdk.ContainsException">Thrown when the string is not present in the collection</exception>
+ </member>
<member name="M:Xunit.Assert.Contains``1(``0,System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IComparer{``0})">
<summary>
Verifies that a collection contains a given object, using a comparer.
@@ -80,6 +90,16 @@
<param name="comparer">The comparer used to equate objects in the collection with the expected object</param>
<exception cref="T:Xunit.Sdk.DoesNotContainException">Thrown when the object is present inside the container</exception>
</member>
+ <member name="M:Xunit.Assert.DoesNotContain(System.String,System.Collections.Generic.IEnumerable{System.String},System.StringComparer)">
+ <summary>
+ Verifies that a collection does not contain a given string, using a string comparer.
+ </summary>
+ <typeparam name="T">The type of the string to be compared</typeparam>
+ <param name="expected">The string that is expected not to be in the collection</param>
+ <param name="collection">The collection to be inspected</param>
+ <param name="comparer">The comparer used to equate strings in the collection with the expected string</param>
+ <exception cref="T:Xunit.Sdk.DoesNotContainException">Thrown when the string is present inside the container</exception>
+ </member>
<member name="M:Xunit.Assert.DoesNotContain``1(``0,System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IComparer{``0})">
<summary>
Verifies that a collection does not contain a given object, using a comparer.
@@ -140,6 +160,16 @@
<param name="comparer">The comparer used to compare the two objects</param>
<exception cref="T:Xunit.Sdk.EqualException">Thrown when the objects are not equal</exception>
</member>
+ <member name="M:Xunit.Assert.Equal(System.String,System.String,System.StringComparer)">
+ <summary>
+ Verifies that two strings are equal, using the given string comparer.
+ </summary>
+ <typeparam name="T">The type of the strings to be compared</typeparam>
+ <param name="expected">The expected value</param>
+ <param name="actual">The value to be compared against</param>
+ <param name="comparer">The comparer used to compare the two strings</param>
+ <exception cref="T:Xunit.Sdk.EqualException">Thrown when the strings are not equal</exception>
+ </member>
<member name="M:Xunit.Assert.Equal``1(``0,``0,System.Collections.Generic.IComparer{``0})">
<summary>
Verifies that two objects are equal, using a custom comparer.
@@ -266,6 +296,16 @@
<param name="comparer">The comparer used to examine the objects</param>
<exception cref="T:Xunit.Sdk.NotEqualException">Thrown when the objects are equal</exception>
</member>
+ <member name="M:Xunit.Assert.NotEqual(System.String,System.String,System.StringComparer)">
+ <summary>
+ Verifies that two strings are not equal, using the given string comparer.
+ </summary>
+ <typeparam name="T">The type of the strings to be compared</typeparam>
+ <param name="expected">The expected string</param>
+ <param name="actual">The actual string</param>
+ <param name="comparer">The comparer used to examine the strings</param>
+ <exception cref="T:Xunit.Sdk.NotEqualException">Thrown when the strings are equal</exception>
+ </member>
<member name="M:Xunit.Assert.NotEqual``1(``0,``0,System.Collections.Generic.IComparer{``0})">
<summary>
Verifies that two objects are not equal, using a custom comparer.
@@ -348,6 +388,18 @@
<exception cref="T:Xunit.Sdk.SingleException">Thrown when the collection does not contain
exactly one element.</exception>
</member>
+ <member name="M:Xunit.Assert.Single``1(System.Collections.Generic.IEnumerable{``0},System.Predicate{``0})">
+ <summary>
+ Verifies that the given collection contains only a single
+ element of the given type which matches the given predicate.
+ </summary>
+ <typeparam name="T">The collection type.</typeparam>
+ <param name="collection">The collection.</param>
+ <param name="predicate">The item matching predicate.</param>
+ <returns>The single item in the filtered collection.</returns>
+ <exception cref="T:Xunit.Sdk.SingleException">Thrown when the filtered collection does
+ not contain exactly one element.</exception>
+ </member>
<member name="M:Xunit.Assert.Throws``1(Xunit.Assert.ThrowsDelegate)">
<summary>
Verifies that the exact exception is thrown (and not a derived exception type).
@@ -53,13 +53,10 @@ public class AssertPatchedTests
[Trait(TraitName, TraitValue)]
public void Assert_ExactlyEqualNestedArrays_ThrowsEqualException()
{
- Assert.Throws<EqualException>(
- delegate()
- {
- Assert.Equal(
- new[] { new[] { "Foo" }, new[] { "Bar" } },
- new[] { new[] { "Foo" }, new[] { "Bar" } });
- });
+ // this works as of v1.6.1
+ Assert.Equal(
+ new[] { new[] { "Foo" }, new[] { "Bar" } },
+ new[] { new[] { "Foo" }, new[] { "Bar" } });
}
[Fact]
@@ -145,6 +142,9 @@ public void AssertPatched_EquivalentNotStrictDictionaries_Passes()
#endregion AssertPatched Tests
}
+ /// <summary>
+ /// Patches xunit.Assert to allow less strict comparisons (doesn't enforce exact type)
+ /// </summary>
internal class AssertPatched : Assert
{
#region AssertEqualityComparer<T> Entry Points
@@ -279,175 +279,112 @@ static IComparer<T> GetComparer<T>(bool strict)
#region AssertEqualityComparer<T>
- class AssertEqualityComparer<T> :
+ class AssertEqualityComparer<T> :
IEqualityComparer<T>,
IComparer<T>
- {
- #region Fields
-
- readonly bool StrictTyping;
- IDictionary<Type, Delegate> methodCache;
+ {
+ static AssertEqualityComparer<object> innerComparer = new AssertEqualityComparer<object>(false);
+ static AssertEqualityComparer<object> innerComparerStrict = new AssertEqualityComparer<object>(true);
- #endregion Fields
+ readonly bool Strict;
- #region Init
-
- /// <summary>
- /// Ctor
- /// </summary>
- /// <param name="strictTyping">Forces types to match exactly</param>
- public AssertEqualityComparer(bool strictTyping)
+ public AssertEqualityComparer(bool strict)
{
- this.StrictTyping = strictTyping;
+ this.Strict = strict;
}
- #endregion Init
-
- #region IComparer<T> Members
-
- public int Compare(T x, T y)
- {
- return Equals(x, y) ? 0 : 1;
- }
-
- #endregion IComparer<T> Members
-
- #region IEqualityComparer<T> Members
-
public bool Equals(T x, T y)
- {
- Type type = typeof(T);
-
- // Null?
- if (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable<>))))
- {
- if (Object.Equals(x, default(T)))
- return Object.Equals(y, default(T));
+ {
+ Type type = typeof(T);
- if (Object.Equals(y, default(T)))
- return false;
- }
+ // Null?
+ if (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable<>))))
+ {
+ if (Object.Equals(x, default(T)))
+ return Object.Equals(y, default(T));
- // Same type?
- if (this.StrictTyping &&
- x.GetType() != y.GetType())
- {
- return false;
- }
+ if (Object.Equals(y, default(T)))
+ return false;
+ }
- // Implements IEquatable<T>?
- IEquatable<T> equatable = x as IEquatable<T>;
- if (equatable != null)
- return equatable.Equals(y);
+ // Same type?
+ if (this.Strict && x.GetType() != y.GetType())
+ return false;
- // Implements IComparable<T>?
- IComparable<T> comparable1 = x as IComparable<T>;
- if (comparable1 != null)
- return comparable1.CompareTo(y) == 0;
+ // Implements IEquatable<T>?
+ IEquatable<T> equatable = x as IEquatable<T>;
+ if (equatable != null)
+ return equatable.Equals(y);
- // Implements IComparable?
- IComparable comparable2 = x as IComparable;
- if (comparable2 != null)
- return comparable2.CompareTo(y) == 0;
+ // Implements IComparable<T>?
+ IComparable<T> comparable1 = x as IComparable<T>;
+ if (comparable1 != null)
+ return comparable1.CompareTo(y) == 0;
- // Enumerable?
- IEnumerable enumerableX = x as IEnumerable;
- IEnumerable enumerableY = y as IEnumerable;
+ // Implements IComparable?
+ IComparable comparable2 = x as IComparable;
+ if (comparable2 != null)
+ return comparable2.CompareTo(y) == 0;
- if (enumerableX != null && enumerableY != null)
- return EnumerableEquals(enumerableX, enumerableY);
+ #region IDictionary<string, object> hack
- // Last case, rely on default comparers
- return EqualityComparer<T>.Default.Equals(x, y);
- }
+ // equivalent ExpandoObjects
- private bool EnumerableEquals(IEnumerable x, IEnumerable y)
- {
- IEnumerator enumeratorX = x.GetEnumerator();
- IEnumerator enumeratorY = y.GetEnumerator();
+ IDictionary<string, object> dictionaryX = x as IDictionary<string, object>;
+ IDictionary<string, object> dictionaryY = y as IDictionary<string, object>;
- while (true)
+ if (dictionaryX != null && dictionaryY != null)
{
- bool hasNextX = enumeratorX.MoveNext();
- bool hasNextY = enumeratorY.MoveNext();
-
- if (!hasNextX || !hasNextY)
- return (hasNextX == hasNextY);
-
- object currentX = enumeratorX.Current;
- object currentY = enumeratorY.Current;
-
- if (!this.ObjectEquals(currentX, currentY))
+ if (dictionaryX.Count != dictionaryY.Count)
return false;
- }
- }
-
- private bool ObjectEquals(object x, object y)
- {
- if (typeof(T) != typeof(object) && x is T && y is T)
- return this.Equals((T)x, (T)y);
- if (x == null)
- return (y == null);
+ foreach (string key in dictionaryX.Keys)
+ {
+ if (!dictionaryY.ContainsKey(key) ||
+ !(this.Strict ? innerComparerStrict : innerComparer).Equals(dictionaryX[key], dictionaryY[key]))
+ return false;
+ }
- if (y == null)
- return false;
-
- // TODO: find a way to generalize these types of exceptional situations
- if (x is KeyValuePair<string, object>)
- {
- KeyValuePair<string, object> pairX = (KeyValuePair<string, object>)x;
- KeyValuePair<string, object> pairy = (KeyValuePair<string, object>)y;
-
- return this.ObjectEquals(pairX.Key, pairX.Key) &&
- this.ObjectEquals(pairX.Value, pairX.Value);
+ return true;
}
- Type itemType = x.GetType();
- if (this.StrictTyping &&
- y.GetType() != itemType)
- return false;
+ #endregion IDictionary<string, object> hack
// Enumerable?
- IEnumerable enumerableX = x as IEnumerable;
- IEnumerable enumerableY = y as IEnumerable;
+ IEnumerable enumerableX = x as IEnumerable;
+ IEnumerable enumerableY = y as IEnumerable;
- if (enumerableX != null && enumerableY != null)
- return EnumerableEquals(enumerableX, enumerableY);
+ if (enumerableX != null && enumerableY != null)
+ {
+ IEnumerator enumeratorX = enumerableX.GetEnumerator();
+ IEnumerator enumeratorY = enumerableY.GetEnumerator();
- if (methodCache == null)
- methodCache = new Dictionary<Type, Delegate>();
+ while (true)
+ {
+ bool hasNextX = enumeratorX.MoveNext();
+ bool hasNextY = enumeratorY.MoveNext();
- Delegate equalsMethod;
- if (methodCache.ContainsKey(itemType))
- {
- equalsMethod = methodCache[itemType];
- }
- else
- {
- // get comparer type and instantiate
- Type comparerType = typeof(AssertEqualityComparer<>).MakeGenericType(itemType);
- object comparer = comparerType.GetConstructor(new Type[] { typeof(bool) }).Invoke(new object[] { this.StrictTyping });
+ if (!hasNextX || !hasNextY)
+ return (hasNextX == hasNextY);
- MethodInfo methodInfo = comparerType.GetMethod("Equals", new Type[] { itemType, itemType });
+ if (!(this.Strict ? innerComparerStrict : innerComparer).Equals(enumeratorX.Current, enumeratorY.Current))
+ return false;
+ }
+ }
- // leveraging delegate contravariance to store in generalized form
- methodCache[itemType] = equalsMethod = Delegate.CreateDelegate(
- typeof(Func<,,>).MakeGenericType(itemType, itemType, typeof(bool)),
- comparer,
- methodInfo,
- true);
- }
+ // Last case, rely on Object.Equals
+ return Object.Equals(x, y);
+ }
- return (bool)equalsMethod.Method.Invoke(equalsMethod.Target, new object[] { x, y });
- }
+ public int GetHashCode(T obj)
+ {
+ throw new NotImplementedException();
+ }
- public int GetHashCode(T obj)
+ public int Compare(T x, T y)
{
- return EqualityComparer<T>.Default.GetHashCode(obj);
+ return this.Equals(x, y) ? 0 : 1;
}
-
- #endregion IEqualityComparer<T> Members
}
#endregion AssertEqualityComparer<T>

0 comments on commit bb3fe07

Please sign in to comment.