/VersionOne.ServiceHost.Tests/Utility/ListAssert.cs
C# | 308 lines | 12 code | 17 blank | 279 comment | 0 complexity | 1d069f12ef3ce9545e2570d6f124e66c MD5 | raw file
Possible License(s): GPL-2.0, MIT
- /*(c) Copyright 2009, VersionOne, Inc. All rights reserved. (c)*/
- using System;
- using System.Collections;
- using System.Collections.ObjectModel;
- using VersionOne.ServiceHost.Tests.Utility;
-
- namespace NUnit.Framework
- {
- public class ListAssert
- {
- private static readonly ITransformer _defaultconverter = new NoopTransformer();
-
- private ListAssert() { }
-
-
- // public static void Contains(object expectedItem, IEnumerable actualList, ITransformer transformer, string message, params object[] args)
- // {
- // ArrayList all = new ArrayList();
- //
- // Assert.Contains(expectedItem, new List() actualList, message); //DoAssert(new ContainsAsserter(true, expectedItem, null, actualList, transformer, message, args));
- // }
-
- // public static void Contains(object expectedItem, IEnumerable actualList, string message, params object[] args)
- // {
- // Contains(expectedItem, actualList, _defaultconverter, message, args);
- // }
- // public static void Contains(object expectedItem, IEnumerable actualList, ITransformer transformer)
- // {
- // Contains(expectedItem, actualList, transformer, null);
- // }
- // public static void Contains(object expectedItem, IEnumerable actualList)
- // {
- // Contains(expectedItem, actualList, _defaultconverter, null);
- // }
-
-
- // public static void NotContains(object expectedItem, IEnumerable actualList, ITransformer transformer, string message, params object[] args)
- // {
- // Assert.DoAssert(new ContainsAsserter(false, expectedItem, null, actualList, transformer, message, args));
- // }
- // public static void NotContains(object expectedItem, IEnumerable actualList, string message, params object[] args)
- // {
- // NotContains(expectedItem, actualList, _defaultconverter, message, args);
- // }
- // public static void NotContains(object expectedItem, IEnumerable actualList, ITransformer transformer)
- // {
- // NotContains(expectedItem, actualList, transformer, null);
- // }
- // public static void NotContains(object expectedItem, IEnumerable actualList)
- // {
- // NotContains(expectedItem, actualList, _defaultconverter, null);
- // }
-
-
- // public static void AreEqualIgnoringOrder(IList expectedItems, IEnumerable actualList, ITransformer transformer, string message, params object[] args)
- // {
- // Assert.DoAssert(new AreEqualIgnoringOrderAsserter(expectedItems, null, actualList, transformer, message, args));
- // }
- // public static void AreEqualIgnoringOrder(IList expectedItems, IEnumerable actualList, string message, params object[] args)
- // {
- // AreEqualIgnoringOrder(expectedItems, actualList, _defaultconverter, message, args);
- // }
- // public static void AreEqualIgnoringOrder(IList expectedItems, IEnumerable actualList, ITransformer transformer)
- // {
- // AreEqualIgnoringOrder(expectedItems, actualList, transformer, null);
- // }
- // public static void AreEqualIgnoringOrder(IList expectedItems, IEnumerable actualList)
- // {
- // AreEqualIgnoringOrder(expectedItems, actualList, _defaultconverter, null);
- // }
-
- // public static void AreWithinIgnoringOrder(object epsilon, IList expectedItems, IEnumerable actualList, ITransformer transformer, string message, params object[] args)
- // {
- // Assert.DoAssert(new AreEqualIgnoringOrderAsserter(expectedItems, epsilon, actualList, transformer, message, args));
- // }
- // public static void AreWithinIgnoringOrder(object epsilon, IList expectedItems, IEnumerable actualList, string message, params object[] args)
- // {
- // AreWithinIgnoringOrder(epsilon, expectedItems, actualList, _defaultconverter, message, args);
- // }
- // public static void AreWithinIgnoringOrder(object epsilon, IList expectedItems, IEnumerable actualList, ITransformer transformer)
- // {
- // AreWithinIgnoringOrder(epsilon, expectedItems, actualList, transformer, null);
- // }
- // public static void AreWithinIgnoringOrder(object epsilon, IList expectedItems, IEnumerable actualList)
- // {
- // AreWithinIgnoringOrder(epsilon, expectedItems, actualList, _defaultconverter, null);
- // }
- //
- // public static void AreEqual(IList expectedItems, IEnumerable actualList, ITransformer transformer, string message, params object[] args)
- // {
- // Assert.DoAssert(new AreEqualAsserter(expectedItems, null, actualList, transformer, message, args));
- // }
- // public static void AreEqual(IList expectedItems, IEnumerable actualList, string message, params object[] args)
- // {
- // AreEqual(expectedItems, actualList, _defaultconverter, message, args);
- // }
- // public static void AreEqual(IList expectedItems, IEnumerable actualList, ITransformer transformer)
- // {
- // AreEqual(expectedItems, actualList, transformer, null);
- // }
- // public static void AreEqual(IList expectedItems, IEnumerable actualList)
- // {
- // AreEqual(expectedItems, actualList, _defaultconverter, null);
- // }
- //
- // public static void AreWithin(object epsilon, IList expectedItems, IEnumerable actualList, ITransformer transformer, string message, params object[] args)
- // {
- // Assert.DoAssert(new AreEqualAsserter(expectedItems, epsilon, actualList, transformer, message, args));
- // }
- // public static void AreWithin(object epsilon, IList expectedItems, IEnumerable actualList, string message, params object[] args)
- // {
- // AreWithin(epsilon, expectedItems, actualList, _defaultconverter, message, args);
- // }
- // public static void AreWithin(object epsilon, IList expectedItems, IEnumerable actualList, ITransformer transformer)
- // {
- // AreWithin(epsilon, expectedItems, actualList, transformer, null);
- // }
- // public static void AreWithin(object epsilon, IList expectedItems, IEnumerable actualList)
- // {
- // AreWithin(epsilon, expectedItems, actualList, _defaultconverter, null);
- // }
-
- //
- // private abstract class ListAsserter : AbstractAsserter
- // {
- // protected IEnumerable _list;
- // protected ITransformer _converter;
- // protected object _epsilon;
- //
- // public ListAsserter(object epsilon, IEnumerable list, ITransformer transformer, string message, params object[] args)
- // : base(message, args)
- // {
- // _list = list;
- // _converter = transformer;
- // _epsilon = epsilon;
- // }
- //
- // protected bool CompareEqual(object expected, object actual)
- // {
- // if (_epsilon != null)
- // {
- // if (_epsilon is TimeSpan && expected is DateTime && actual is DateTime)
- // return Math.Abs(((DateTime)expected).Subtract((DateTime)actual).Ticks) <= ((TimeSpan)_epsilon).Ticks;
- // else if (_epsilon is double && expected is double && actual is double)
- // return Math.Abs((double)expected - (double)actual) <= (double)_epsilon;
- // else if (_epsilon is float && expected is float && actual is float)
- // return Math.Abs((float)expected - (float)actual) <= (float)_epsilon;
- // }
- // return object.Equals(expected, actual);
- // }
- // }
-
- // private class ContainsAsserter : ListAsserter
- // {
- // private bool _polarity;
- // private object _item;
- //
- // public ContainsAsserter(bool polarity, object item, object epsilon, IEnumerable list, ITransformer transformer, string message, params object[] args)
- // : base(epsilon, list, transformer, message, args)
- // {
- // _polarity = polarity;
- // _item = item;
- // }
- //
- // public override bool Test()
- // {
- // FailureMessage msg = new FailureMessage(Message, args);
- // foreach (object value in _list)
- // if (CompareEqual(_item, _converter.Transform(value)))
- // {
- // if (_polarity) return true;
- // msg.DisplayExtra(_item);
- // throw new AssertionException(msg.ToString());
- // }
- // if (!_polarity) return true;
- // msg.DisplayMissing(_item);
- // throw new AssertionException(msg.ToString());
- // }
- // }
-
- // private class AreEqualIgnoringOrderAsserter : ListAsserter
- // {
- // private IList _items;
- //
- // public AreEqualIgnoringOrderAsserter(IList items, object epsilon, IEnumerable list, ITransformer transformer, string message, params object[] args)
- // : base(epsilon, list, transformer, message, args)
- // {
- // _items = items;
- // }
- //
- // public override bool Test()
- // {
- // FailureMessage msg = new FailureMessage(Message, args);
- // bool isfail = false;
- // bool[] matched = new bool[_items.Count];
- // int count = 0;
- // foreach (object value in _list)
- // {
- // ++count;
- // object nvalue = _converter.Transform(value);
- // int foundat = Find(_items, nvalue, 0);
- // while (foundat < _items.Count && matched[foundat])
- // foundat = Find(_items, nvalue, foundat + 1);
- // if (foundat >= _items.Count)
- // {
- // msg.DisplayExtra(nvalue);
- // isfail = true;
- // }
- // else
- // matched[foundat] = true;
- // }
- // for (int i = 0; i < matched.Length; ++i)
- // {
- // if (!matched[i])
- // msg.DisplayMissing(_items[i]);
- // }
- // if (count != _items.Count)
- // {
- // isfail = true;
- // msg.DisplayLengthsDiff(_items.Count, count);
- // }
- // if (isfail)
- // throw new AssertionException(msg.ToString());
- // return true;
- // }
- //
- // private int Find(IList list, object value, int index)
- // {
- // while (index < list.Count)
- // {
- // if (CompareEqual(value, list[index]))
- // break;
- // ++index;
- // }
- // return index;
- // }
- // }
-
-
- // private class AreEqualAsserter : ListAsserter
- // {
- // private IList _items;
- //
- // public AreEqualAsserter(IList items, object epsilon, IEnumerable list, ITransformer transformer, string message, params object[] args)
- // : base(epsilon, list, transformer, message, args)
- // {
- // _items = items;
- // }
- //
- // public override bool Test()
- // {
- // FailureMessage msg = new FailureMessage(Message, args);
- // bool isfail = false;
- // int count = 0;
- // foreach (object value in _list)
- // {
- // object nvalue = _converter.Transform(value);
- // if (!isfail && count < _items.Count && !CompareEqual(_items[count], nvalue))
- // {
- // msg.DisplayMismatch(_items[count], nvalue, count);
- // isfail = true;
- // }
- // ++count;
- // }
- // if (count != _items.Count)
- // {
- // isfail = true;
- // msg.DisplayLengthsDiff(_items.Count, count);
- // }
- // if (isfail)
- // throw new AssertionException(msg.ToString());
- // return true;
- // }
- // }
-
- // private class FailureMessage : AssertionFailureMessage
- // {
- // public FailureMessage(string message, object[] args) : base(message, args) { }
- //
- // public void DisplayMismatch(object expected, object actual, int index)
- // {
- // WriteLine();
- // Write(" Mismatch at index {0}", index);
- // DisplayExpectedAndActual(expected, actual);
- // }
- //
- // public void DisplayMissing(object value)
- // {
- // WriteLine();
- // Write(" Expected: {0}", FormatObjectForDisplay(value));
- // }
- //
- // public void DisplayExtra(object value)
- // {
- // WriteLine();
- // Write(" Unexpected: {0}", FormatObjectForDisplay(value));
- // }
- //
- // public void DisplayLengthsDiff(int expected, int actual)
- // {
- // WriteLine();
- // Write(" Lengths are different:");
- // DisplayExpectedAndActual(expected, actual);
- // }
- // }
- }
-
- }