diff --git a/test/Microsoft.TestCommon/DictionaryEqualityComparer.cs b/test/Microsoft.TestCommon/DictionaryEqualityComparer.cs deleted file mode 100644 index 76b2e85747..0000000000 --- a/test/Microsoft.TestCommon/DictionaryEqualityComparer.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.TestCommon -{ - public class DictionaryEqualityComparer : IEqualityComparer> - { - public bool Equals(IDictionary x, IDictionary y) - { - if (x.Count != y.Count) - { - return false; - } - - foreach (string key in x.Keys) - { - object xVal = x[key]; - object yVal; - if (!y.TryGetValue(key, out yVal)) - { - return false; - } - - if (xVal == null) - { - if (yVal == null) - { - continue; - } - - return false; - } - - if (!xVal.Equals(yVal)) - { - return false; - } - } - - return true; - } - - public int GetHashCode(IDictionary obj) - { - return 1; - } - } -} diff --git a/test/Microsoft.TestCommon/EnumHelperTestBase.cs b/test/Microsoft.TestCommon/EnumHelperTestBase.cs deleted file mode 100644 index d066cf309c..0000000000 --- a/test/Microsoft.TestCommon/EnumHelperTestBase.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.TestCommon -{ - public abstract class EnumHelperTestBase where TEnum : IComparable, IFormattable, IConvertible - { - private Func _isDefined; - private Action _validate; - private TEnum _undefined; - - /// - /// Helper to verify that we validate enums correctly when passed as arguments etc. - /// - /// A Func used to validate that a value is defined. - /// A Func used to validate that a value is definded of throw an exception. - /// An undefined value. - protected EnumHelperTestBase(Func isDefined, Action validate, TEnum undefined) - { - _isDefined = isDefined; - _validate = validate; - _undefined = undefined; - } - - [Fact] - public void IsDefined_ReturnsTrueForDefinedValues() - { - Array values = Enum.GetValues(typeof(TEnum)); - foreach (object value in values) - { - if (ValueExistsForFramework((TEnum)value)) - { - Assert.True(_isDefined((TEnum)value)); - } - else - { - Assert.False(_isDefined((TEnum)value)); - } - } - } - - [Fact] - public void IsDefined_ReturnsFalseForUndefinedValues() - { - Assert.False(_isDefined(_undefined)); - } - - [Fact] - public void Validate_DoesNotThrowForDefinedValues() - { - Array values = Enum.GetValues(typeof(TEnum)); - foreach (object value in values) - { - if (ValueExistsForFramework((TEnum)value)) - { - _validate((TEnum)value, "parameter"); - } - } - } - - [Fact] - public void Validate_ThrowsForUndefinedValues() - { - AssertForUndefinedValue( - () => _validate(_undefined, "parameter"), - "parameter", - (int)Convert.ChangeType(_undefined, typeof(int)), - typeof(TEnum), - allowDerivedExceptions: false); - } - - /// - /// Override this if InvalidEnumArgument is not supported in the targetted platform - /// - /// A delegate to the code to be tested - /// The name of the parameter that should throw the exception - /// The expected invalid value that should appear in the message - /// The type of the enumeration - /// Pass true to allow exceptions which derive from TException; pass false, otherwise - protected virtual void AssertForUndefinedValue(Action testCode, string parameterName, int invalidValue, Type enumType, bool allowDerivedExceptions = false) - { - Assert.ThrowsInvalidEnumArgument( - testCode, - parameterName, - invalidValue, - enumType, - allowDerivedExceptions); - } - - /// - /// Override this to determine if a given enum value for an enum exists in a given framework - /// - /// - /// Wheter the value exists - protected virtual bool ValueExistsForFramework(TEnum value) - { - return true; - } - } -} diff --git a/test/Microsoft.TestCommon/ForceGCAttribute.cs b/test/Microsoft.TestCommon/ForceGCAttribute.cs deleted file mode 100644 index 03bc46c85e..0000000000 --- a/test/Microsoft.TestCommon/ForceGCAttribute.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Reflection; - -namespace Microsoft.TestCommon -{ - public class ForceGCAttribute : Xunit.BeforeAfterTestAttribute - { - public override void After(MethodInfo methodUnderTest) - { - GC.Collect(99); - GC.Collect(99); - GC.Collect(99); - } - } -} diff --git a/test/Microsoft.TestCommon/MatrixTheoryDataSet.cs b/test/Microsoft.TestCommon/MatrixTheoryDataSet.cs deleted file mode 100644 index 8b304eee5e..0000000000 --- a/test/Microsoft.TestCommon/MatrixTheoryDataSet.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Linq; - -namespace Microsoft.TestCommon -{ - public class MatrixTheoryDataSet : TheoryDataSet - { - public MatrixTheoryDataSet(IEnumerable data1, IEnumerable data2) - { - Contract.Assert(data1 != null && data1.Any()); - Contract.Assert(data2 != null && data2.Any()); - - foreach (T1 t1 in data1) - { - foreach (T2 t2 in data2) - { - Add(t1, t2); - } - } - } - } -} diff --git a/test/Microsoft.TestCommon/MemberHelper.cs b/test/Microsoft.TestCommon/MemberHelper.cs deleted file mode 100644 index 56dadb16cd..0000000000 --- a/test/Microsoft.TestCommon/MemberHelper.cs +++ /dev/null @@ -1,383 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; -using Microsoft.TestCommon; - -namespace System.Web.TestUtil -{ - public static class MemberHelper - { - private static ConstructorInfo GetConstructorInfo(object instance, Type[] parameterTypes) - { - if (instance == null) - { - throw new ArgumentNullException("instance"); - } - ConstructorInfo constructorInfo = instance.GetType().GetConstructor(parameterTypes); - if (constructorInfo == null) - { - throw new ArgumentException(String.Format( - "A matching constructor on type '{0}' could not be found.", - instance.GetType().FullName)); - } - return constructorInfo; - } - - private static EventInfo GetEventInfo(object instance, string eventName) - { - if (instance == null) - { - throw new ArgumentNullException("instance"); - } - if (String.IsNullOrEmpty(eventName)) - { - throw new ArgumentException("An event must be specified.", "eventName"); - } - EventInfo eventInfo = instance.GetType().GetEvent(eventName); - if (eventInfo == null) - { - throw new ArgumentException(String.Format( - "An event named '{0}' on type '{1}' could not be found.", - eventName, instance.GetType().FullName)); - } - return eventInfo; - } - - private static MethodInfo GetMethodInfo(object instance, string methodName, Type[] types = null, MethodAttributes attrs = MethodAttributes.Public) - { - if (instance == null) - { - throw new ArgumentNullException("instance"); - } - if (String.IsNullOrEmpty(methodName)) - { - throw new ArgumentException("A method must be specified.", "methodName"); - } - - MethodInfo methodInfo; - if (types != null) - { - methodInfo = instance.GetType().GetMethod(methodName, - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, - null, - types, - null); - } - else - { - methodInfo = instance.GetType().GetMethod(methodName, - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - } - - if (methodInfo == null) - { - throw new ArgumentException(String.Format( - "A method named '{0}' on type '{1}' could not be found.", - methodName, instance.GetType().FullName)); - } - - if ((methodInfo.Attributes & attrs) != attrs) - { - throw new ArgumentException(String.Format( - "Method '{0}' on type '{1}' with attributes '{2}' does not match the attributes '{3}'.", - methodName, instance.GetType().FullName, methodInfo.Attributes, attrs)); - } - - return methodInfo; - } - - private static PropertyInfo GetPropertyInfo(object instance, string propertyName) - { - if (instance == null) - { - throw new ArgumentNullException("instance"); - } - if (String.IsNullOrEmpty(propertyName)) - { - throw new ArgumentException("A property must be specified.", "propertyName"); - } - PropertyInfo propInfo = instance.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - if (propInfo == null) - { - throw new ArgumentException(String.Format( - "A property named '{0}' on type '{1}' could not be found.", - propertyName, instance.GetType().FullName)); - } - return propInfo; - } - - private static void TestAttribute(MemberInfo memberInfo, TAttribute attributeValue) - where TAttribute : Attribute - { - object[] attrs = memberInfo.GetCustomAttributes(typeof(TAttribute), true); - - if (attributeValue == null) - { - Assert.True(attrs.Length == 0, "Member should not have an attribute of type " + typeof(TAttribute)); - } - else - { - Assert.True(attrs != null && attrs.Length > 0, - "Member does not have an attribute of type " + typeof(TAttribute)); - Assert.Equal(attributeValue, attrs[0]); - } - } - - public static void TestBooleanProperty(object instance, string propertyName, bool initialValue, bool testDefaultValue) - { - // Assert initial value - TestGetPropertyValue(instance, propertyName, initialValue); - - if (testDefaultValue) - { - // Assert DefaultValue attribute matches inital value - TestDefaultValue(instance, propertyName); - } - - TestPropertyValue(instance, propertyName, true); - TestPropertyValue(instance, propertyName, false); - } - - public static void TestDefaultValue(object instance, string propertyName) - { - PropertyInfo propInfo = GetPropertyInfo(instance, propertyName); - - object initialValue = propInfo.GetValue(instance, null); - TestAttribute(propInfo, new DefaultValueAttribute(initialValue)); - } - - public static void TestEvent(object instance, string eventName, TEventArgs eventArgs) where TEventArgs : EventArgs - { - EventInfo eventInfo = GetEventInfo(instance, eventName); - - // Assert category "Action" - TestAttribute(eventInfo, new CategoryAttribute("Action")); - - // Call protected method with no event handlers, assert no error - MethodInfo methodInfo = GetMethodInfo(instance, "On" + eventName, attrs: MethodAttributes.Family | MethodAttributes.Virtual); - methodInfo.Invoke(instance, new object[] { eventArgs }); - - // Attach handler, call method, assert fires once - List eventHandlerArgs = new List(); - EventHandler handler = new EventHandler(delegate(object sender, TEventArgs t) - { - eventHandlerArgs.Add(sender); - eventHandlerArgs.Add(t); - }); - eventInfo.AddEventHandler(instance, handler); - methodInfo.Invoke(instance, new object[] { eventArgs }); - Assert.Equal(new[] { instance, eventArgs }, eventHandlerArgs.ToArray()); - - // Detach handler, call method, assert not fired - eventHandlerArgs = new List(); - eventInfo.RemoveEventHandler(instance, handler); - methodInfo.Invoke(instance, new object[] { eventArgs }); - Assert.Empty(eventHandlerArgs); - } - - public static void TestGetPropertyValue(object instance, string propertyName, object valueToCheck) - { - PropertyInfo propInfo = GetPropertyInfo(instance, propertyName); - object value = propInfo.GetValue(instance, null); - Assert.Equal(valueToCheck, value); - } - - public static void TestEnumProperty(object instance, string propertyName, TEnumValue initialValue, bool testDefaultValue) - { - // Assert initial value - TestGetPropertyValue(instance, propertyName, initialValue); - - if (testDefaultValue) - { - // Assert DefaultValue attribute matches inital value - TestDefaultValue(instance, propertyName); - } - - PropertyInfo propInfo = GetPropertyInfo(instance, propertyName); - - // Values are sorted numerically - TEnumValue[] values = (TEnumValue[])Enum.GetValues(propInfo.PropertyType); - - // Assert get/set works for all valid enum values - foreach (TEnumValue value in values) - { - TestPropertyValue(instance, propertyName, value); - } - - // Assert ArgumentOutOfRangeException is thrown for value one less than smallest - // enum value, and one more than largest enum value - var targetException = Assert.Throws(() => propInfo.SetValue(instance, Convert.ToInt32(values[0]) - 1, null)); - Assert.IsType(targetException.InnerException); - - targetException = Assert.Throws(() => propInfo.SetValue(instance, Convert.ToInt32(values[values.Length - 1]) + 1, null)); - Assert.IsType(targetException.InnerException); - } - - public static void TestInt32Property(object instance, string propertyName, int value1, int value2) - { - TestPropertyValue(instance, propertyName, value1); - TestPropertyValue(instance, propertyName, value2); - } - - public static void TestPropertyWithDefaultInstance(object instance, string propertyName, object valueToSet) - { - PropertyInfo propInfo = GetPropertyInfo(instance, propertyName); - - // Set to explicit property - propInfo.SetValue(instance, valueToSet, null); - object value = propInfo.GetValue(instance, null); - Assert.Equal(valueToSet, value); - - // Set to null - propInfo.SetValue(instance, null, null); - value = propInfo.GetValue(instance, null); - Assert.IsAssignableFrom(propInfo.PropertyType, value); - } - - public static void TestPropertyWithDefaultInstance(object instance, string propertyName, object valueToSet, object defaultValue) - { - PropertyInfo propInfo = GetPropertyInfo(instance, propertyName); - - // Set to explicit property - propInfo.SetValue(instance, valueToSet, null); - object value = propInfo.GetValue(instance, null); - Assert.Same(valueToSet, value); - - // Set to null - propInfo.SetValue(instance, null, null); - value = propInfo.GetValue(instance, null); - Assert.Equal(defaultValue, value); - } - - public static void TestPropertyValue(object instance, string propertyName, object value) - { - TestPropertyValue(instance, propertyName, value, value); - } - - public static void TestPropertyValue(object instance, string propertyName, object valueToSet, object valueToCheck) - { - PropertyInfo propInfo = GetPropertyInfo(instance, propertyName); - propInfo.SetValue(instance, valueToSet, null); - object value = propInfo.GetValue(instance, null); - Assert.Equal(valueToCheck, value); - } - - public static void TestStringParams(object instance, Type[] constructorParameterTypes, object[] parameters) - { - ConstructorInfo ctor = GetConstructorInfo(instance, constructorParameterTypes); - TestStringParams(ctor, instance, parameters); - } - - public static void TestStringParams(object instance, string methodName, object[] parameters) - { - TestStringParams(instance, methodName, null, parameters); - } - - public static void TestStringParams(object instance, string methodName, Type[] types, object[] parameters) - { - MethodInfo method = GetMethodInfo(instance, methodName, types); - TestStringParams(method, instance, parameters); - } - - private static void TestStringParams(MethodBase method, object instance, object[] parameters) - { - ParameterInfo[] parameterInfos = method.GetParameters(); - foreach (ParameterInfo parameterInfo in parameterInfos) - { - if (parameterInfo.ParameterType == typeof(String)) - { - object originalParameter = parameters[parameterInfo.Position]; - - parameters[parameterInfo.Position] = null; - Assert.ThrowsArgumentNullOrEmpty( - delegate() - { - try - { - method.Invoke(instance, parameters); - } - catch (TargetInvocationException e) - { - throw e.InnerException; - } - }, - parameterInfo.Name); - - parameters[parameterInfo.Position] = String.Empty; - Assert.ThrowsArgumentNullOrEmpty( - delegate() - { - try - { - method.Invoke(instance, parameters); - } - catch (TargetInvocationException e) - { - throw e.InnerException; - } - }, - parameterInfo.Name); - - parameters[parameterInfo.Position] = originalParameter; - } - } - } - - public static void TestStringProperty(object instance, string propertyName, string initialValue, - bool testDefaultValueAttribute = false, bool allowNullAndEmpty = true, - string nullAndEmptyReturnValue = "") - { - // Assert initial value - TestGetPropertyValue(instance, propertyName, initialValue); - - if (testDefaultValueAttribute) - { - // Assert DefaultValue attribute matches inital value - TestDefaultValue(instance, propertyName); - } - - if (allowNullAndEmpty) - { - // Assert get/set works for null - TestPropertyValue(instance, propertyName, null, nullAndEmptyReturnValue); - - // Assert get/set works for String.Empty - TestPropertyValue(instance, propertyName, String.Empty, nullAndEmptyReturnValue); - } - else - { - Assert.ThrowsArgumentNullOrEmpty( - delegate() - { - try - { - TestPropertyValue(instance, propertyName, null); - } - catch (TargetInvocationException e) - { - throw e.InnerException; - } - }, - "value"); - Assert.ThrowsArgumentNullOrEmpty( - delegate() - { - try - { - TestPropertyValue(instance, propertyName, String.Empty); - } - catch (TargetInvocationException e) - { - throw e.InnerException; - } - }, - "value"); - } - - // Assert get/set works for arbitrary value - TestPropertyValue(instance, propertyName, "TestValue"); - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj b/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj index e484abe659..dfcafb63ab 100644 --- a/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj +++ b/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj @@ -34,68 +34,34 @@ - + - - - - - - - + + + + + - + + Code + - Code - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/CommonUnitTestDataSets.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/CommonUnitTestDataSets.cs deleted file mode 100644 index d56a619620..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/CommonUnitTestDataSets.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections.ObjectModel; -using Microsoft.TestCommon.Types; - -namespace Microsoft.TestCommon -{ - public class CommonUnitTestDataSets - { - public static ValueTypeTestData Chars { get { return TestData.CharTestData; } } - public static ValueTypeTestData Ints { get { return TestData.IntTestData; } } - public static ValueTypeTestData Uints { get { return TestData.UintTestData; } } - public static ValueTypeTestData Shorts { get { return TestData.ShortTestData; } } - public static ValueTypeTestData Ushorts { get { return TestData.UshortTestData; } } - public static ValueTypeTestData Longs { get { return TestData.LongTestData; } } - public static ValueTypeTestData Ulongs { get { return TestData.UlongTestData; } } - public static ValueTypeTestData Bytes { get { return TestData.ByteTestData; } } - public static ValueTypeTestData SBytes { get { return TestData.SByteTestData; } } - public static ValueTypeTestData Bools { get { return TestData.BoolTestData; } } - public static ValueTypeTestData Doubles { get { return TestData.DoubleTestData; } } - public static ValueTypeTestData Floats { get { return TestData.FloatTestData; } } - public static ValueTypeTestData DateTimes { get { return TestData.DateTimeTestData; } } - public static ValueTypeTestData Decimals { get { return TestData.DecimalTestData; } } - public static ValueTypeTestData TimeSpans { get { return TestData.TimeSpanTestData; } } - public static ValueTypeTestData Guids { get { return TestData.GuidTestData; } } - public static ValueTypeTestData DateTimeOffsets { get { return TestData.DateTimeOffsetTestData; } } - public static ValueTypeTestData SimpleEnums { get { return TestData.SimpleEnumTestData; } } - public static ValueTypeTestData LongEnums { get { return TestData.LongEnumTestData; } } - public static ValueTypeTestData FlagsEnums { get { return TestData.FlagsEnumTestData; } } - public static TestData EmptyStrings { get { return TestData.EmptyStrings; } } - public static RefTypeTestData Strings { get { return TestData.StringTestData; } } - public static TestData NonNullEmptyStrings { get { return TestData.NonNullEmptyStrings; } } - public static RefTypeTestData ISerializableTypes { get { return TestData.ISerializableTypeTestData; } } - public static ReadOnlyCollection ValueTypeTestDataCollection { get { return TestData.ValueTypeTestDataCollection; } } - public static ReadOnlyCollection RefTypeTestDataCollection { get { return TestData.RefTypeTestDataCollection; } } - public static ReadOnlyCollection ValueAndRefTypeTestDataCollection { get { return TestData.ValueAndRefTypeTestDataCollection; } } - public static ReadOnlyCollection RepresentativeValueAndRefTypeTestDataCollection { get { return TestData.RepresentativeValueAndRefTypeTestDataCollection; } } - } -} \ No newline at end of file diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/RefTypeTestData.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/RefTypeTestData.cs deleted file mode 100644 index 49fdd7a269..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/RefTypeTestData.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.TestCommon -{ - public class RefTypeTestData : TestData where T : class - { - private Func> testDataProvider; - private Func> derivedTypeTestDataProvider; - private Func> knownTypeTestDataProvider; - - public RefTypeTestData(Func> testDataProvider) - { - if (testDataProvider == null) - { - throw new ArgumentNullException("testDataProvider"); - } - - this.testDataProvider = testDataProvider; - this.RegisterTestDataVariation(TestDataVariations.WithNull, this.Type, GetNullTestData); - } - - public RefTypeTestData( - Func> testDataProvider, - Func> derivedTypeTestDataProvider, - Func> knownTypeTestDataProvider) - : this(testDataProvider) - { - this.derivedTypeTestDataProvider = derivedTypeTestDataProvider; - if (this.derivedTypeTestDataProvider != null) - { - this.RegisterTestDataVariation(TestDataVariations.AsDerivedType, this.Type, this.GetTestDataAsDerivedType); - } - - this.knownTypeTestDataProvider = knownTypeTestDataProvider; - if (this.knownTypeTestDataProvider != null) - { - this.RegisterTestDataVariation(TestDataVariations.AsKnownType, this.Type, this.GetTestDataAsDerivedKnownType); - } - } - - public T GetNullTestData() - { - return null; - } - - public IEnumerable GetTestDataAsDerivedType() - { - if (this.derivedTypeTestDataProvider != null) - { - return this.derivedTypeTestDataProvider(); - } - - return Enumerable.Empty(); - } - - public IEnumerable GetTestDataAsDerivedKnownType() - { - if (this.knownTypeTestDataProvider != null) - { - return this.knownTypeTestDataProvider(); - } - - return Enumerable.Empty(); - } - - protected override IEnumerable GetTypedTestData() - { - return this.testDataProvider(); - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestData.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestData.cs deleted file mode 100644 index 141a755080..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestData.cs +++ /dev/null @@ -1,463 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Microsoft.TestCommon.Types; - -namespace Microsoft.TestCommon -{ - /// - /// A base class for test data. A instance is associated with a given type, and the instance can - /// provide instances of the given type to use as data in tests. The same instance can also provide instances - /// of types related to the given type, such as a of the type. See the enum for all the - /// variations of test data that a instance can provide. - /// - public abstract class TestData - { - /// - /// Common for a . - /// - public static readonly ValueTypeTestData CharTestData = new ValueTypeTestData('a', Char.MinValue, Char.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData IntTestData = new ValueTypeTestData(-1, 0, 1, Int32.MinValue, Int32.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData UintTestData = new ValueTypeTestData(0, 1, UInt32.MinValue, UInt32.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData ShortTestData = new ValueTypeTestData(-1, 0, 1, Int16.MinValue, Int16.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData UshortTestData = new ValueTypeTestData(0, 1, UInt16.MinValue, UInt16.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData LongTestData = new ValueTypeTestData(-1, 0, 1, Int64.MinValue, Int64.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData UlongTestData = new ValueTypeTestData(0, 1, UInt64.MinValue, UInt64.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData ByteTestData = new ValueTypeTestData(0, 1, Byte.MinValue, Byte.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData SByteTestData = new ValueTypeTestData(-1, 0, 1, SByte.MinValue, SByte.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData BoolTestData = new ValueTypeTestData(true, false); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData DoubleTestData = new ValueTypeTestData( - -1.0, - 0.0, - 1.0, - double.MinValue, - double.MaxValue, - double.PositiveInfinity, - double.NegativeInfinity); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData FloatTestData = new ValueTypeTestData( - -1.0f, - 0.0f, - 1.0f, - float.MinValue, - float.MaxValue, - float.PositiveInfinity, - float.NegativeInfinity); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData DecimalTestData = new ValueTypeTestData( - -1M, - 0M, - 1M, - decimal.MinValue, - decimal.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData DateTimeTestData = new ValueTypeTestData( - DateTime.Now, - DateTime.UtcNow, - DateTime.MaxValue, - DateTime.MinValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData TimeSpanTestData = new ValueTypeTestData( - TimeSpan.MinValue, - TimeSpan.MaxValue); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData GuidTestData = new ValueTypeTestData( - Guid.NewGuid(), - Guid.Empty); - - /// - /// Common for a . - /// - public static readonly ValueTypeTestData DateTimeOffsetTestData = new ValueTypeTestData( - DateTimeOffset.MaxValue, - DateTimeOffset.MinValue, - new DateTimeOffset(DateTime.Now)); - - /// - /// Common for an enum. - /// - public static readonly ValueTypeTestData SimpleEnumTestData = new ValueTypeTestData( - SimpleEnum.First, - SimpleEnum.Second, - SimpleEnum.Third); - - /// - /// Common for an enum implemented with a . - /// - public static readonly ValueTypeTestData LongEnumTestData = new ValueTypeTestData( - LongEnum.FirstLong, - LongEnum.SecondLong, - LongEnum.ThirdLong); - - /// - /// Common for an enum decorated with a . - /// - public static readonly ValueTypeTestData FlagsEnumTestData = new ValueTypeTestData( - FlagsEnum.One, - FlagsEnum.Two, - FlagsEnum.Four); - - /// - /// Expected permutations of non supported file paths. - /// - public static readonly TestData NotSupportedFilePaths = new RefTypeTestData(() => new List() { - "cc:\\a\\b", - }); - - /// - /// Expected permutations of invalid file paths. - /// - public static readonly TestData InvalidNonNullFilePaths = new RefTypeTestData(() => new List() { - String.Empty, - "", - " ", - " ", - "\t\t \n ", - "c:\\ab", - "c:\\a\"b", - "c:\\a\tb", - "c:\\a|b", - "c:\\a\bb", - "c:\\a\0b", - }); - - /// - /// All expected permutations of an empty string. - /// - public static readonly TestData NonNullEmptyStrings = new RefTypeTestData(() => new List() { String.Empty, "", " ", "\t\r\n" }); - - /// - /// All expected permutations of an empty string. - /// - public static readonly TestData EmptyStrings = new RefTypeTestData(() => new List() { null, String.Empty, "", " ", "\t\r\n" }); - - /// - /// Common for a . - /// - public static readonly RefTypeTestData StringTestData = new RefTypeTestData(() => new List() { - "", - " ", // one space - " ", // multiple spaces - " data ", // leading and trailing whitespace - "\t\t \n ", - "Some String!"}); - - /// - /// Common for a class that implements . - /// - public static readonly RefTypeTestData ISerializableTypeTestData = new RefTypeTestData( - ISerializableType.GetTestData); - - /// - /// A read-only collection of value type test data. - /// - public static readonly ReadOnlyCollection ValueTypeTestDataCollection = new ReadOnlyCollection(new TestData[] { - CharTestData, - IntTestData, - UintTestData, - ShortTestData, - UshortTestData, - LongTestData, - UlongTestData, - ByteTestData, - SByteTestData, - BoolTestData, - DoubleTestData, - FloatTestData, - DecimalTestData, - TimeSpanTestData, - GuidTestData, - DateTimeOffsetTestData, - SimpleEnumTestData, - LongEnumTestData, - FlagsEnumTestData}); - - /// - /// A read-only collection of reference type test data. - /// - public static readonly ReadOnlyCollection RefTypeTestDataCollection = new ReadOnlyCollection(new TestData[] { - StringTestData, - ISerializableTypeTestData}); - - /// - /// A read-only collection of value and reference type test data. - /// - public static readonly ReadOnlyCollection ValueAndRefTypeTestDataCollection = new ReadOnlyCollection( - ValueTypeTestDataCollection.Concat(RefTypeTestDataCollection).ToList()); - - /// - /// A read-only collection of representative values and reference type test data. - /// Uses where exhaustive coverage is not required. - /// - public static readonly ReadOnlyCollection RepresentativeValueAndRefTypeTestDataCollection = new ReadOnlyCollection(new TestData[] { - IntTestData, - BoolTestData, - SimpleEnumTestData, - StringTestData, - }); - - private Dictionary registeredTestDataVariations; - - - /// - /// Initializes a new instance of the class. - /// - /// The type associated with the instance. - protected TestData(Type type) - { - if (type.ContainsGenericParameters) - { - throw new InvalidOperationException("Only closed generic types are supported."); - } - - this.Type = type; - this.registeredTestDataVariations = new Dictionary(); - } - - /// - /// Gets the type associated with the instance. - /// - public Type Type { get; private set; } - - - /// - /// Gets the supported test data variations. - /// - /// - public IEnumerable GetSupportedTestDataVariations() - { - return this.registeredTestDataVariations.Keys; - } - - /// - /// Gets the related type for the given test data variation or returns null if the instance - /// doesn't support the given variation. - /// - /// The test data variation with which to create the related . - /// The related for the as given by the test data variation. - /// - /// For example, if the given was created for test data and the varation parameter - /// was then the returned type would be . - /// - public Type GetAsTypeOrNull(TestDataVariations variation) - { - TestDataVariationProvider testDataVariation = null; - if (this.registeredTestDataVariations.TryGetValue(variation, out testDataVariation)) - { - return testDataVariation.Type; - } - - return null; - } - - /// - /// Gets test data for the given test data variation or returns null if the instance - /// doesn't support the given variation. - /// - /// The test data variation with which to create the related test data. - /// Test data of the type specified by the method. - public object GetAsTestDataOrNull(TestDataVariations variation) - { - TestDataVariationProvider testDataVariation = null; - if (this.registeredTestDataVariations.TryGetValue(variation, out testDataVariation)) - { - return testDataVariation.TestDataProvider(); - } - - return null; - } - - - /// - /// Allows derived classes to register a that will - /// provide test data for a given variation. - /// - /// The variation with which to register the r. - /// The type of the test data created by the - /// A that will provide test data. - protected void RegisterTestDataVariation(TestDataVariations variation, Type type, Func testDataProvider) - { - this.registeredTestDataVariations.Add(variation, new TestDataVariationProvider(type, testDataProvider)); - } - - private class TestDataVariationProvider - { - public TestDataVariationProvider(Type type, Func testDataProvider) - { - this.Type = type; - this.TestDataProvider = testDataProvider; - } - - - public Func TestDataProvider { get; private set; } - - public Type Type { get; private set; } - } - } - - - /// - /// A generic base class for test data. - /// - /// The type associated with the test data. - public abstract class TestData : TestData, IEnumerable - { - private static readonly Type OpenIEnumerableType = typeof(IEnumerable<>); - private static readonly Type OpenListType = typeof(List<>); - private static readonly Type OpenIQueryableType = typeof(IQueryable<>); - private static readonly Type OpenDictionaryType = typeof(Dictionary<,>); - private static readonly Type OpenTestDataHolderType = typeof(TestDataHolder<>); - private int dictionaryKey; - - /// - /// Initializes a new instance of the class. - /// - protected TestData() - : base(typeof(T)) - { - Type[] typeParams = new Type[] { this.Type }; - Type[] dictionaryTypeParams = new Type[] { typeof(string), this.Type }; - - Type arrayType = this.Type.MakeArrayType(); - Type listType = OpenListType.MakeGenericType(typeParams); - Type iEnumerableType = OpenIEnumerableType.MakeGenericType(typeParams); - Type iQueryableType = OpenIQueryableType.MakeGenericType(typeParams); - Type dictionaryType = OpenDictionaryType.MakeGenericType(dictionaryTypeParams); - Type testDataHolderType = OpenTestDataHolderType.MakeGenericType(typeParams); - - this.RegisterTestDataVariation(TestDataVariations.AsInstance, this.Type, () => GetTypedTestData()); - this.RegisterTestDataVariation(TestDataVariations.AsArray, arrayType, GetTestDataAsArray); - this.RegisterTestDataVariation(TestDataVariations.AsIEnumerable, iEnumerableType, GetTestDataAsIEnumerable); - this.RegisterTestDataVariation(TestDataVariations.AsIQueryable, iQueryableType, GetTestDataAsIQueryable); - this.RegisterTestDataVariation(TestDataVariations.AsList, listType, GetTestDataAsList); - this.RegisterTestDataVariation(TestDataVariations.AsDictionary, dictionaryType, GetTestDataAsDictionary); - this.RegisterTestDataVariation(TestDataVariations.AsClassMember, testDataHolderType, GetTestDataInHolder); - } - - public IEnumerator GetEnumerator() - { - return (IEnumerator)this.GetTypedTestData().ToList().GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return (IEnumerator)this.GetTypedTestData().ToList().GetEnumerator(); - } - - /// - /// Gets the test data as an array. - /// - /// An array of test data of the given type. - public T[] GetTestDataAsArray() - { - return this.GetTypedTestData().ToArray(); - } - - /// - /// Gets the test data as a . - /// - /// A of test data of the given type. - public List GetTestDataAsList() - { - return this.GetTypedTestData().ToList(); - } - - /// - /// Gets the test data as an . - /// - /// An of test data of the given type. - public IEnumerable GetTestDataAsIEnumerable() - { - return this.GetTypedTestData().AsEnumerable(); - } - - /// - /// Gets the test data as an . - /// - /// An of test data of the given type. - public IQueryable GetTestDataAsIQueryable() - { - return this.GetTypedTestData().AsQueryable(); - } - - public Dictionary GetTestDataAsDictionary() - { - // Some TestData collections contain duplicates e.g. UintTestData contains both 0 and UInt32.MinValue. - // Therefore use dictionaryKey, not _unused.ToString(). Reset key to keep dictionaries consistent if used - // multiple times. - dictionaryKey = 0; - return this.GetTypedTestData().ToDictionary(_unused => (dictionaryKey++).ToString()); - } - - public IEnumerable> GetTestDataInHolder() - { - return this.GetTypedTestData().Select(value => new TestDataHolder { V1 = value, }); - } - - /// - /// Must be implemented by derived types to return test data of the given type. - /// - /// Test data of the given type. - protected abstract IEnumerable GetTypedTestData(); - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestDataHolder.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestDataHolder.cs deleted file mode 100644 index 90e98f60ed..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestDataHolder.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Globalization; - -namespace Microsoft.TestCommon -{ - /// - /// Equatable class wrapping a single instance of type . Equatable to ease test assertions. - /// - /// The to wrap. - public class TestDataHolder : IEquatable> - { - public T V1 { get; set; } - - bool IEquatable>.Equals(TestDataHolder other) - { - if (other == null) - { - return false; - } - - return Object.Equals(V1, other.V1); - } - - public override bool Equals(object obj) - { - TestDataHolder that = obj as TestDataHolder; - return ((IEquatable>)this).Equals(that); - } - - public override int GetHashCode() - { - if (typeof(ValueType).IsAssignableFrom(typeof(T)) || V1 != null) - { - return V1.GetHashCode(); - } - else - { - return 0; - } - } - - public override string ToString() - { - return String.Format(CultureInfo.InvariantCulture, "{{ V1: '{0}' }}", V1); - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestDataVariations.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestDataVariations.cs deleted file mode 100644 index 40a538a1a5..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/TestDataVariations.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.TestCommon -{ - /// - /// An flags enum that can be used to indicate different variations of a given - /// instance. - /// - [Flags] - public enum TestDataVariations - { - /// - /// An individual instance of a given type. - /// - AsInstance = 0x1, - - /// - /// An individual instance of a type that derives from a given type. - /// - AsDerivedType = 0x2, - - /// - /// An individual instance of a given type that has a property value - /// that is a known type of the declared property type. - /// - AsKnownType = 0x4, - - /// - /// A instance of a given type. Only applies to - /// instances of . - /// - AsNullable = 0x8, - - /// - /// An instance of a of a given type. - /// - AsList = 0x10, - - /// - /// An instance of a array of the type. - /// - AsArray = 0x20, - - /// - /// An instance of an of a given type. - /// - AsIEnumerable = 0x40, - - /// - /// An instance of an of a given type. - /// - AsIQueryable = 0x80, - - /// - /// An instance of a DataContract type in which a given type is a member. - /// - AsDataMember = 0x100, - - /// - /// An instance of a type in which a given type is decorated with a - /// . - /// - AsXmlElementProperty = 0x200, - - /// - /// An instance of a of a given - /// type. - /// - AsDictionary = 0x400, - - /// - /// Add a null instance of the given type to the data set. This variation is - /// not included in or other variation masks. - /// - WithNull = 0x800, - - /// - /// Individual instances of containing the given . This - /// variation is not included in or other variation masks. - /// - AsClassMember = 0x1000, - - /// - /// All of the flags for single instance variations of a given type. - /// - AllSingleInstances = AsInstance | AsDerivedType | AsKnownType | AsNullable, - - /// - /// All of the flags for collection variations of a given type. - /// - AllCollections = AsList | AsArray | AsIEnumerable | AsIQueryable | AsDictionary, - - /// - /// All of the flags for variations in which a given type is a property on another type. - /// - AllProperties = AsDataMember | AsXmlElementProperty, - - /// - /// All of the flags for interface collection variations of a given type. - /// - AllInterfaces = AsIEnumerable | AsIQueryable, - - /// - /// All of the flags except for the interface collection variations of a given type. - /// - AllNonInterfaces = All & ~AllInterfaces, - - /// - /// All of the flags for all of the variations of a given type. - /// - All = AllSingleInstances | AllCollections | AllProperties - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/ValueTypeTestData.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/ValueTypeTestData.cs deleted file mode 100644 index f4cd3e5ad9..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/DataSets/ValueTypeTestData.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.TestCommon -{ - public class ValueTypeTestData : TestData where T : struct - { - private static readonly Type OpenNullableType = typeof(Nullable<>); - private T[] testData; - - public ValueTypeTestData(params T[] testData) - : base() - { - this.testData = testData; - - Type[] typeParams = new Type[] { this.Type }; - this.RegisterTestDataVariation(TestDataVariations.WithNull, OpenNullableType.MakeGenericType(typeParams), GetNullTestData); - this.RegisterTestDataVariation(TestDataVariations.AsNullable, OpenNullableType.MakeGenericType(typeParams), GetTestDataAsNullable); - } - - public object GetNullTestData() - { - return null; - } - - public IEnumerable> GetTestDataAsNullable() - { - return this.GetTypedTestData().Select(d => new Nullable(d)); - } - - protected override IEnumerable GetTypedTestData() - { - return this.testData; - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/RuntimeEnvironment.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/RuntimeEnvironment.cs deleted file mode 100644 index b0cd0eccf9..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/RuntimeEnvironment.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using Microsoft.Win32; - -namespace Microsoft.TestCommon -{ - public static class RuntimeEnvironment - { - private const string NetFx40FullSubKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"; - private const string Version = "Version"; - - static RuntimeEnvironment() - { - object runtimeVersion = Registry.LocalMachine.OpenSubKey(RuntimeEnvironment.NetFx40FullSubKey).GetValue(RuntimeEnvironment.Version); - string versionFor40String = runtimeVersion as string; - if (versionFor40String != null) - { - VersionFor40 = new Version(versionFor40String); - } - } - - private static Version VersionFor40; - - public static bool IsVersion45Installed - { - get - { - return VersionFor40.Major > 4 || (VersionFor40.Major == 4 && VersionFor40.Minor >= 5); - } - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/TestDataSetAttribute.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/TestDataSetAttribute.cs deleted file mode 100644 index 1fa8b8c749..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/TestDataSetAttribute.cs +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Microsoft.TestCommon -{ - public class TestDataSetAttribute : DataAttribute - { - public Type DeclaringType { get; set; } - - public string PropertyName { get; set; } - - public TestDataVariations TestDataVariations { get; set; } - - private IEnumerable> ExtraDataSets { get; set; } - - public TestDataSetAttribute(Type declaringType, string propertyName, TestDataVariations testDataVariations = TestCommon.TestDataVariations.All) - { - DeclaringType = declaringType; - PropertyName = propertyName; - TestDataVariations = testDataVariations; - ExtraDataSets = new List>(); - } - - public TestDataSetAttribute(Type declaringType, string propertyName, - Type declaringType1, string propertyName1, - TestDataVariations testDataVariations = TestCommon.TestDataVariations.All) - : this(declaringType, propertyName, testDataVariations) - { - ExtraDataSets = new List> { Tuple.Create(declaringType1, propertyName1) }; - } - - public TestDataSetAttribute(Type declaringType, string propertyName, - Type declaringType1, string propertyName1, - Type declaringType2, string propertyName2, - TestDataVariations testDataVariations = TestCommon.TestDataVariations.All) - : this(declaringType, propertyName, testDataVariations) - { - ExtraDataSets = new List> { Tuple.Create(declaringType1, propertyName1), Tuple.Create(declaringType2, propertyName2) }; - } - - public TestDataSetAttribute(Type declaringType, string propertyName, - Type declaringType1, string propertyName1, - Type declaringType2, string propertyName2, - Type declaringType3, string propertyName3, - TestDataVariations testDataVariations = TestCommon.TestDataVariations.All) - : this(declaringType, propertyName, testDataVariations) - { - ExtraDataSets = new List> { Tuple.Create(declaringType1, propertyName1), Tuple.Create(declaringType2, propertyName2), Tuple.Create(declaringType3, propertyName3) }; - } - - public TestDataSetAttribute(Type declaringType, string propertyName, - Type declaringType1, string propertyName1, - Type declaringType2, string propertyName2, - Type declaringType3, string propertyName3, - Type declaringType4, string propertyName4, - TestDataVariations testDataVariations = TestCommon.TestDataVariations.All) - : this(declaringType, propertyName, testDataVariations) - { - ExtraDataSets = new List> - { - Tuple.Create(declaringType1, propertyName1), Tuple.Create(declaringType2, propertyName2), - Tuple.Create(declaringType3, propertyName3), Tuple.Create(declaringType4, propertyName4) - }; - } - - public override IEnumerable GetData(MethodInfo methodUnderTest, Type[] parameterTypes) - { - IEnumerable baseDataSet = GetBaseDataSet(DeclaringType, PropertyName, TestDataVariations); - IEnumerable> extraDataSets = GetExtraDataSets(); - - IEnumerable> finalDataSets = (new[] { baseDataSet }).Concat(extraDataSets); - - var datasets = CrossProduct(finalDataSets); - - return datasets; - } - - private static IEnumerable CrossProduct(IEnumerable> datasets) - { - if (datasets.Count() == 1) - { - foreach (var dataset in datasets.First()) - { - yield return dataset; - } - } - else - { - IEnumerable datasetLeft = datasets.First(); - IEnumerable datasetRight = CrossProduct(datasets.Skip(1)); - - foreach (var dataLeft in datasetLeft) - { - foreach (var dataRight in datasetRight) - { - yield return dataLeft.Concat(dataRight).ToArray(); - } - } - } - } - - // The base data set(first one) can either be a TestDataSet or a TestDataSetCollection - private static IEnumerable GetBaseDataSet(Type declaringType, string propertyName, TestDataVariations variations) - { - return TryGetDataSetFromTestDataCollection(declaringType, propertyName, variations) ?? GetDataSet(declaringType, propertyName); - } - - private IEnumerable> GetExtraDataSets() - { - foreach (var tuple in ExtraDataSets) - { - yield return GetDataSet(tuple.Item1, tuple.Item2); - } - } - - private static object GetTestDataPropertyValue(Type declaringType, string propertyName) - { - PropertyInfo property = declaringType.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public); - - if (property == null) - { - throw new ArgumentException(String.Format("Could not find public static property {0} on {1}", propertyName, declaringType.FullName)); - } - else - { - return property.GetValue(null, null); - } - } - - private static IEnumerable GetDataSet(Type declaringType, string propertyName) - { - object propertyValue = GetTestDataPropertyValue(declaringType, propertyName); - - // box the dataset items if the property is not a RefTypeTestData - IEnumerable value = (propertyValue as IEnumerable) ?? (propertyValue as IEnumerable).Cast(); - if (value == null) - { - throw new InvalidOperationException(String.Format("{0}.{1} is either null or does not implement IEnumerable", declaringType.FullName, propertyName)); - } - - IEnumerable dataset = value as IEnumerable; - if (dataset != null) - { - return dataset; - } - else - { - return value.Select((data) => new object[] { data }); - } - } - - private static IEnumerable TryGetDataSetFromTestDataCollection(Type declaringType, string propertyName, TestDataVariations variations) - { - object propertyValue = GetTestDataPropertyValue(declaringType, propertyName); - - IEnumerable testDataCollection = propertyValue as IEnumerable; - - return testDataCollection == null ? null : GetDataSetFromTestDataCollection(testDataCollection, variations); - } - - private static IEnumerable GetDataSetFromTestDataCollection(IEnumerable testDataCollection, TestDataVariations variations) - { - foreach (TestData testdataInstance in testDataCollection) - { - foreach (TestDataVariations variation in testdataInstance.GetSupportedTestDataVariations()) - { - if ((variation & variations) == variation) - { - Type variationType = testdataInstance.GetAsTypeOrNull(variation); - object testData = testdataInstance.GetAsTestDataOrNull(variation); - if (AsSingleInstances(variation)) - { - foreach (object obj in (IEnumerable)testData) - { - yield return new object[] { variationType, obj }; - } - } - else - { - yield return new object[] { variationType, testData }; - } - } - } - } - } - - private static bool AsSingleInstances(TestDataVariations variation) - { - return variation == TestDataVariations.AsInstance || - variation == TestDataVariations.AsNullable || - variation == TestDataVariations.AsDerivedType || - variation == TestDataVariations.AsKnownType || - variation == TestDataVariations.AsDataMember || - variation == TestDataVariations.AsClassMember || - variation == TestDataVariations.AsXmlElementProperty; - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ByteEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ByteEnum.cs deleted file mode 100644 index c1d4c7b89a..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ByteEnum.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum ByteEnum : byte - { - FirstByte, - SecondByte, - ThirdByte - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/FlagsEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/FlagsEnum.cs deleted file mode 100644 index d1b48a2fda..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/FlagsEnum.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.TestCommon.Types -{ - [Flags] - public enum FlagsEnum - { - One = 0x1, - Two = 0x2, - Four = 0x4 - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/INameAndIdContainer.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/INameAndIdContainer.cs deleted file mode 100644 index 53d58b677e..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/INameAndIdContainer.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - /// - /// Tagging interface to assist comparing instances of these types. - /// - public interface INameAndIdContainer - { - string Name { get; set; } - - int Id { get; set; } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ISerializableType.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ISerializableType.cs deleted file mode 100644 index 7fd7956b1d..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ISerializableType.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace Microsoft.TestCommon.Types -{ - [Serializable] - public class ISerializableType : ISerializable, INameAndIdContainer - { - private int id; - private string name; - - public ISerializableType() - { - } - - public ISerializableType(int id, string name) - { - this.id = id; - this.name = name; - } - - public ISerializableType(SerializationInfo information, StreamingContext context) - { - this.id = information.GetInt32("Id"); - this.name = information.GetString("Name"); - } - - public int Id - { - get - { - return this.id; - } - - set - { - this.IdSet = true; - this.id = value; - } - } - - public string Name - { - get - { - return this.name; - } - - set - { - this.NameSet = true; - this.name = value; - } - - } - - public bool IdSet { get; private set; } - - public bool NameSet { get; private set; } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("Id", this.Id); - info.AddValue("Name", this.Name); - } - - public static IEnumerable GetTestData() - { - return new ISerializableType[] { new ISerializableType(), new ISerializableType(1, "SomeName") }; - } - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/LongEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/LongEnum.cs deleted file mode 100644 index d27b40ac9a..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/LongEnum.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum LongEnum : long - { - FirstLong, - SecondLong, - ThirdLong, - FourthLong - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/SByteEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/SByteEnum.cs deleted file mode 100644 index 1afb32c1cb..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/SByteEnum.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum SByteEnum : sbyte - { - FirstSByte, - SecondSByte, - ThirdSByte - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ShortEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ShortEnum.cs deleted file mode 100644 index d74576a73c..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/ShortEnum.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum ShortEnum : short - { - FirstShort, - SecondShort, - ThirdShort - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/SimpleEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/SimpleEnum.cs deleted file mode 100644 index b740c8f207..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/SimpleEnum.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum SimpleEnum - { - First, - Second, - Third, - Fourth - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/UIntEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/UIntEnum.cs deleted file mode 100644 index 8804f23096..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/UIntEnum.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum UIntEnum : uint - { - FirstUInt, - SecondUInt, - ThirdUInt - } -} diff --git a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/UShortEnum.cs b/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/UShortEnum.cs deleted file mode 100644 index 53be0b9e27..0000000000 --- a/test/Microsoft.TestCommon/Microsoft/TestCommon/Types/UShortEnum.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -namespace Microsoft.TestCommon.Types -{ - public enum UShortEnum : ushort - { - FirstUShort, - SecondUShort, - ThirdUShort - } -} diff --git a/test/Microsoft.TestCommon/PortReserver.cs b/test/Microsoft.TestCommon/PortReserver.cs deleted file mode 100644 index 3cc9968af4..0000000000 --- a/test/Microsoft.TestCommon/PortReserver.cs +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Net; -using System.Net.NetworkInformation; -using System.Threading; - -namespace Microsoft.TestCommon -{ - /// - /// This class allocates ports while ensuring that: - /// 1. Ports that are permanentaly taken (or taken for the duration of the test) are not being attempted to be used. - /// 2. Ports are not shared across different tests (but you can allocate two different ports in the same test). - /// - /// Gotcha: If another application grabs a port during the test, we have a race condition. - /// - [DebuggerDisplay("Port: {PortNumber}, Port count for this app domain: {_appDomainOwnedPorts.Count}")] - public class PortReserver : IDisposable - { - private Mutex _portMutex; - - // We use this list to hold on to all the ports used because the Mutex will be blown through on the same thread. - // Theoretically we can do a thread local hashset, but that makes dispose thread dependant, or requires more complicated concurrency checks. - // Since practically there is no perf issue or concern here, this keeps the code the simplest possible. - private static HashSet _appDomainOwnedPorts = new HashSet(); - - public int PortNumber - { - get; - private set; - } - - public PortReserver(int basePort = 50231) - { - if (basePort <= 0) - { - throw new InvalidOperationException(); - } - - // Grab a cross appdomain/cross process/cross thread lock, to ensure only one port is reserved at a time. - using (Mutex mutex = GetGlobalMutex()) - { - try - { - int port = basePort - 1; - - while (true) - { - port++; - - if (port > 65535) - { - throw new InvalidOperationException("Exceeded port range"); - } - - // AppDomainOwnedPorts check enables reserving two ports from the same thread in sequence. - // ListUsedTCPPort prevents port contention with other apps. - if (_appDomainOwnedPorts.Contains(port) || - ListUsedTCPPort().Any(endPoint => endPoint.Port == port)) - { - continue; - } - - string mutexName = "WebStack-Port-" + port.ToString(CultureInfo.InvariantCulture); // Create a well known mutex - _portMutex = new Mutex(initiallyOwned: false, name: mutexName); - - // If no one else is using this port grab it. - if (_portMutex.WaitOne(millisecondsTimeout: 0)) - { - break; - } - - // dispose this mutex since the port it represents is not available. - _portMutex.Dispose(); - _portMutex = null; - } - - PortNumber = port; - _appDomainOwnedPorts.Add(port); - } - finally - { - mutex.ReleaseMutex(); - } - } - } - - public string BaseUri - { - get - { - return String.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", PortNumber); - } - } - - public void Dispose() - { - if (PortNumber == -1) - { - // Object already disposed - return; - } - - using (Mutex mutex = GetGlobalMutex()) - { - _portMutex.Dispose(); - _appDomainOwnedPorts.Remove(PortNumber); - PortNumber = -1; - } - } - - private static Mutex GetGlobalMutex() - { - Mutex mutex = new Mutex(initiallyOwned: false, name: "WebStack-RandomPortAcquisition"); - if (!mutex.WaitOne(30000)) - { - throw new InvalidOperationException(); - } - - return mutex; - } - - private static IPEndPoint[] ListUsedTCPPort() - { - var usedPort = new HashSet(); - IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); - - return ipGlobalProperties.GetActiveTcpListeners(); - } - } -} diff --git a/test/Microsoft.TestCommon/PreAppStartTestHelper.cs b/test/Microsoft.TestCommon/PreAppStartTestHelper.cs deleted file mode 100644 index 47638d36f1..0000000000 --- a/test/Microsoft.TestCommon/PreAppStartTestHelper.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.ComponentModel; -using System.Reflection; -using Microsoft.TestCommon; - -namespace System.Web.WebPages.TestUtils -{ - public static class PreAppStartTestHelper - { - public static void TestPreAppStartClass(Type preAppStartType) - { - string typeMessage = String.Format("The type '{0}' must be static, public, and named 'PreApplicationStartCode'.", preAppStartType.FullName); - Assert.True(preAppStartType.IsSealed && preAppStartType.IsAbstract && preAppStartType.IsPublic && preAppStartType.Name == "PreApplicationStartCode", typeMessage); - - string editorBrowsableMessage = String.Format("The only attribute on type '{0}' must be [EditorBrowsable(EditorBrowsableState.Never)].", preAppStartType.FullName); - object[] attrs = preAppStartType.GetCustomAttributes(typeof(EditorBrowsableAttribute), true); - Assert.True(attrs.Length == 1 && ((EditorBrowsableAttribute)attrs[0]).State == EditorBrowsableState.Never, editorBrowsableMessage); - - string startMethodMessage = String.Format("The only public member on type '{0}' must be a method called Start().", preAppStartType.FullName); - MemberInfo[] publicMembers = preAppStartType.GetMembers(BindingFlags.Public | BindingFlags.Static); - Assert.True(publicMembers.Length == 1, startMethodMessage); - Assert.True(publicMembers[0].MemberType == MemberTypes.Method, startMethodMessage); - Assert.True(publicMembers[0].Name == "Start", startMethodMessage); - } - } -} diff --git a/test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs b/test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs deleted file mode 100644 index 1c1dd1d85f..0000000000 --- a/test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Threading; - -namespace Microsoft.TestCommon -{ - /// - /// Preserves the current . Use this attribute on - /// tests which modify the current . - /// - public class PreserveSyncContextAttribute : Xunit.BeforeAfterTestAttribute - { - private SynchronizationContext _syncContext; - - public override void Before(System.Reflection.MethodInfo methodUnderTest) - { - _syncContext = SynchronizationContext.Current; - } - - public override void After(System.Reflection.MethodInfo methodUnderTest) - { - SynchronizationContext.SetSynchronizationContext(_syncContext); - } - } -} diff --git a/test/Microsoft.TestCommon/RestoreThreadPrincipalAttribute.cs b/test/Microsoft.TestCommon/RestoreThreadPrincipalAttribute.cs deleted file mode 100644 index 1f08dc6fb3..0000000000 --- a/test/Microsoft.TestCommon/RestoreThreadPrincipalAttribute.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Reflection; -using System.Security.Principal; -using System.Threading; - -namespace Microsoft.TestCommon -{ - public class RestoreThreadPrincipalAttribute : Xunit.BeforeAfterTestAttribute - { - private IPrincipal _originalPrincipal; - - public override void Before(MethodInfo methodUnderTest) - { - _originalPrincipal = Thread.CurrentPrincipal; - - AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.NoPrincipal); - - Thread.CurrentPrincipal = null; - } - - public override void After(MethodInfo methodUnderTest) - { - Thread.CurrentPrincipal = _originalPrincipal; - - AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal); - } - } -} diff --git a/test/Microsoft.TestCommon/StringAssertException.cs b/test/Microsoft.TestCommon/StringAssertException.cs deleted file mode 100644 index 441fc6fc65..0000000000 --- a/test/Microsoft.TestCommon/StringAssertException.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Xunit.Sdk; - -namespace Microsoft.TestCommon -{ - // An early copy of the new string assert exception from xUnit.net 2.0 (temporarily, until it RTMs) - - [Serializable] - internal class StringEqualException : AssertException - { - private static Dictionary _encodings = new Dictionary { { '\r', "\\r" }, { '\n', "\\n" }, { '\t', "\\t" }, { '\0', "\\0" } }; - private string _message; - - public StringEqualException(string expected, string actual, int expectedIndex, int actualIndex) - : base("Assert.Equal() failure") - { - Actual = actual; - ActualIndex = actualIndex; - Expected = expected; - ExpectedIndex = expectedIndex; - } - - public string Actual { get; private set; } - - public int ActualIndex { get; private set; } - - public string Expected { get; private set; } - - public int ExpectedIndex { get; private set; } - - public override string Message - { - get - { - if (_message == null) - _message = CreateMessage(); - - return _message; - } - } - - private string CreateMessage() - { - Tuple printedExpected = ShortenAndEncode(Expected, ExpectedIndex, '↓'); - Tuple printedActual = ShortenAndEncode(Actual, ActualIndex, '↑'); - - return String.Format( - CultureInfo.CurrentCulture, - "{1}{0} {2}{0}Expected: {3}{0}Actual: {4}{0} {5}", - Environment.NewLine, - base.Message, - printedExpected.Item2, - printedExpected.Item1, - printedActual.Item1, - printedActual.Item2 - ); - } - - private Tuple ShortenAndEncode(string value, int position, char pointer) - { - int start = Math.Max(position - 20, 0); - int end = Math.Min(position + 41, value.Length); - StringBuilder printedValue = new StringBuilder(100); - StringBuilder printedPointer = new StringBuilder(100); - - if (start > 0) - { - printedValue.Append("···"); - printedPointer.Append(" "); - } - - for (int idx = start; idx < end; ++idx) - { - char c = value[idx]; - string encoding; - int paddingLength = 1; - - if (_encodings.TryGetValue(c, out encoding)) - { - printedValue.Append(encoding); - paddingLength = encoding.Length; - } - else - { - printedValue.Append(c); - } - - if (idx < position) - { - printedPointer.Append(' ', paddingLength); - } - else if (idx == position) - { - printedPointer.AppendFormat("{0} (pos {1})", pointer, position); - } - } - - if (end < value.Length) - { - printedValue.Append("···"); - } - - return new Tuple(printedValue.ToString(), printedPointer.ToString()); - } - - protected override bool ExcludeStackFrame(string stackFrame) - { - return base.ExcludeStackFrame(stackFrame) - || stackFrame.StartsWith("at Microsoft.TestCommon.Assert.", StringComparison.OrdinalIgnoreCase); - } - } -} diff --git a/test/Microsoft.TestCommon/StringAssertions.cs b/test/Microsoft.TestCommon/StringAssertions.cs deleted file mode 100644 index f84f7f647d..0000000000 --- a/test/Microsoft.TestCommon/StringAssertions.cs +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.TestCommon -{ - // An early copy of the new string assert from xUnit.net 2.0 (temporarily, until it RTMs) - - public partial class Assert - { - private const string NullDisplayValue = "(null)"; - - /// - /// Verifies that two strings are equivalent. - /// - /// The expected string value. - /// The actual string value. - /// If set to true, ignores cases differences. The invariant culture is used. - /// If set to true, treats \r\n, \r, and \n as equivalent. - /// If set to true, treats spaces and tabs (in any non-zero quantity) as equivalent. - /// Thrown when the strings are not equivalent. - public static void Equal(string expected, string actual, bool ignoreCase = false, bool ignoreLineEndingDifferences = false, bool ignoreWhiteSpaceDifferences = false) - { - // Start out assuming the one of the values is null - int expectedIndex = -1; - int actualIndex = -1; - int expectedLength = 0; - int actualLength = 0; - - if (expected == null) - { - if (actual == null) - { - return; - } - - expected = NullDisplayValue; - } - else if (actual == null) - { - actual = NullDisplayValue; - } - else - { - // Walk the string, keeping separate indices since we can skip variable amounts of - // data based on ignoreLineEndingDifferences and ignoreWhiteSpaceDifferences. - expectedIndex = 0; - actualIndex = 0; - expectedLength = expected.Length; - actualLength = actual.Length; - - while (expectedIndex < expectedLength && actualIndex < actualLength) - { - char expectedChar = expected[expectedIndex]; - char actualChar = actual[actualIndex]; - - if (ignoreLineEndingDifferences && IsLineEnding(expectedChar) && IsLineEnding(actualChar)) - { - expectedIndex = SkipLineEnding(expected, expectedIndex); - actualIndex = SkipLineEnding(actual, actualIndex); - } - else if (ignoreWhiteSpaceDifferences && IsWhiteSpace(expectedChar) && IsWhiteSpace(actualChar)) - { - expectedIndex = SkipWhitespace(expected, expectedIndex); - actualIndex = SkipWhitespace(actual, actualIndex); - } - else - { - if (ignoreCase) - { - expectedChar = Char.ToUpperInvariant(expectedChar); - actualChar = Char.ToUpperInvariant(actualChar); - } - - if (expectedChar != actualChar) - { - break; - } - - expectedIndex++; - actualIndex++; - } - } - } - - if (expectedIndex < expectedLength || actualIndex < actualLength) - { - throw new StringEqualException(expected, actual, expectedIndex, actualIndex); - } - } - - private static bool IsLineEnding(char c) - { - return c == '\r' || c == '\n'; - } - - private static bool IsWhiteSpace(char c) - { - return c == ' ' || c == '\t'; - } - - private static int SkipLineEnding(string value, int index) - { - if (value[index] == '\r') - { - ++index; - } - if (index < value.Length && value[index] == '\n') - { - ++index; - } - - return index; - } - - private static int SkipWhitespace(string value, int index) - { - while (index < value.Length) - { - switch (value[index]) - { - case ' ': - case '\t': - index++; - break; - - default: - return index; - } - } - - return index; - } - } -} diff --git a/test/Microsoft.TestCommon/TaskExtensions.cs b/test/Microsoft.TestCommon/TaskExtensions.cs deleted file mode 100644 index eeb441970d..0000000000 --- a/test/Microsoft.TestCommon/TaskExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; -using Microsoft.TestCommon; - -// No namespace so that these extensions are available for all test classes - -public static class TaskExtensions -{ - /// - /// Waits until the given task finishes executing and completes in any of the 3 states. - /// - /// A task - public static void WaitUntilCompleted(this Task task) - { - if (task == null) throw new ArgumentNullException("task"); - task.ContinueWith(prev => - { - if (prev.IsFaulted) - { - // Observe the exception in the faulted case to avoid an unobserved exception leaking and - // killing the thread finalizer. - var e = prev.Exception; - } - }, TaskContinuationOptions.ExecuteSynchronously).Wait(); - } - - public static void RethrowFaultedTaskException(this Task task) - { - task.WaitUntilCompleted(); - Assert.Equal(TaskStatus.Faulted, task.Status); - throw task.Exception.GetBaseException(); - } -} diff --git a/test/Microsoft.TestCommon/TestHelper.cs b/test/Microsoft.TestCommon/TestHelper.cs deleted file mode 100644 index afe7c535e9..0000000000 --- a/test/Microsoft.TestCommon/TestHelper.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Globalization; -using System.Linq; -using Microsoft.TestCommon; - -namespace System.Web.TestUtil -{ - public static class UnitTestHelper - { - public static bool EnglishBuildAndOS - { - get - { - bool englishBuild = String.Equals(CultureInfo.CurrentCulture.TwoLetterISOLanguageName, "en", - StringComparison.OrdinalIgnoreCase); - bool englishOS = String.Equals(CultureInfo.CurrentCulture.TwoLetterISOLanguageName, "en", - StringComparison.OrdinalIgnoreCase); - return englishBuild && englishOS; - } - } - - public static void AssertEqualsIgnoreWhitespace(string expected, string actual) - { - expected = new String(expected.Where(c => !Char.IsWhiteSpace(c)).ToArray()); - actual = new String(actual.Where(c => !Char.IsWhiteSpace(c)).ToArray()); - - Assert.Equal(expected, actual, StringComparer.OrdinalIgnoreCase); - } - } -} diff --git a/test/Microsoft.TestCommon/TheoryDataSet.cs b/test/Microsoft.TestCommon/TheoryDataSet.cs deleted file mode 100644 index 66c3ae2a3d..0000000000 --- a/test/Microsoft.TestCommon/TheoryDataSet.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Collections; -using System.Collections.Generic; - -namespace Microsoft.TestCommon -{ - /// - /// Helper class for generating test data for XUnit's -based tests. - /// Should be used in combination with . - /// - /// First parameter type - public class TheoryDataSet : TheoryDataSet - { - public void Add(TParam p) - { - AddItem(p); - } - } - - /// - /// Helper class for generating test data for XUnit's -based tests. - /// Should be used in combination with . - /// - /// First parameter type - /// Second parameter type - public class TheoryDataSet : TheoryDataSet - { - public void Add(TParam1 p1, TParam2 p2) - { - AddItem(p1, p2); - } - } - - /// - /// Helper class for generating test data for XUnit's -based tests. - /// Should be used in combination with . - /// - /// First parameter type - /// Second parameter type - /// Third parameter type - public class TheoryDataSet : TheoryDataSet - { - public void Add(TParam1 p1, TParam2 p2, TParam3 p3) - { - AddItem(p1, p2, p3); - } - } - - /// - /// Helper class for generating test data for XUnit's -based tests. - /// Should be used in combination with . - /// - /// First parameter type - /// Second parameter type - /// Third parameter type - /// Fourth parameter type - public class TheoryDataSet : TheoryDataSet - { - public void Add(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4) - { - AddItem(p1, p2, p3, p4); - } - } - - /// - /// Helper class for generating test data for XUnit's -based tests. - /// Should be used in combination with . - /// - /// First parameter type - /// Second parameter type - /// Third parameter type - /// Fourth parameter type - /// Fifth parameter type - public class TheoryDataSet : TheoryDataSet - { - public void Add(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5) - { - AddItem(p1, p2, p3, p4, p5); - } - } - - /// - /// Base class for TheoryDataSet classes. - /// - public abstract class TheoryDataSet : IEnumerable - { - private readonly List data = new List(); - - protected void AddItem(params object[] values) - { - data.Add(values); - } - - public IEnumerator GetEnumerator() - { - return data.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/test/Microsoft.TestCommon/ThreadPoolSyncContext.cs b/test/Microsoft.TestCommon/ThreadPoolSyncContext.cs deleted file mode 100644 index 900526e4e4..0000000000 --- a/test/Microsoft.TestCommon/ThreadPoolSyncContext.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Threading; - -namespace Microsoft.TestCommon -{ - /// - /// This is an implementation of SynchronizationContext that not only queues things on the thread pool for - /// later work, but also ensures that it sets itself back as the synchronization context (something that the - /// default implementatation of SynchronizationContext does not do). - /// - public class ThreadPoolSyncContext : SynchronizationContext - { - public override void Post(SendOrPostCallback d, object state) - { - ThreadPool.QueueUserWorkItem(_ => - { - SynchronizationContext oldContext = SynchronizationContext.Current; - SynchronizationContext.SetSynchronizationContext(this); - d.Invoke(state); - SynchronizationContext.SetSynchronizationContext(oldContext); - }, null); - } - - public override void Send(SendOrPostCallback d, object state) - { - SynchronizationContext oldContext = SynchronizationContext.Current; - SynchronizationContext.SetSynchronizationContext(this); - d.Invoke(state); - SynchronizationContext.SetSynchronizationContext(oldContext); - } - } -} diff --git a/test/Microsoft.TestCommon/TraitAttribute.cs b/test/Microsoft.TestCommon/TraitAttribute.cs deleted file mode 100644 index 19965e62f9..0000000000 --- a/test/Microsoft.TestCommon/TraitAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.TestCommon -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] - public class TraitAttribute : Xunit.TraitAttribute - { - public TraitAttribute(string name, string value) - : base(name, value) - { - } - } -} diff --git a/test/Microsoft.TestCommon/VersionTestHelper.cs b/test/Microsoft.TestCommon/VersionTestHelper.cs deleted file mode 100644 index 2b4257b5bc..0000000000 --- a/test/Microsoft.TestCommon/VersionTestHelper.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System; -using System.Reflection; - -namespace Microsoft.TestCommon -{ - public static class VersionTestHelper - { - // returns a version for an assembly by using a type from the assembly - // also verifies that type wasn't moved to another assembly. - public static Version GetVersionFromAssembly(string assemblyName, Type typeFromAssembly) - { - Assembly assembly = typeFromAssembly.Assembly; - - Assert.Equal(assemblyName, assembly.GetName().Name); - return assembly.GetName().Version; - } - } -} diff --git a/test/Microsoft.TestCommon/WebUtils.cs b/test/Microsoft.TestCommon/WebUtils.cs deleted file mode 100644 index 640dcaa952..0000000000 --- a/test/Microsoft.TestCommon/WebUtils.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.IO; -using System.Reflection; -using System.Web.UI; - -namespace System.Web.WebPages.TestUtils -{ - public static class WebUtils - { - /// - /// Creates an instance of HttpRuntime and assigns it (using magic) to the singleton instance of HttpRuntime. - /// Ensure that the returned value is disposed at the end of the test. - /// - /// Returns an IDisposable that restores the original HttpRuntime. - public static IDisposable CreateHttpRuntime(string appVPath, string appPath = null) - { - var runtime = new HttpRuntime(); - var appDomainAppVPathField = typeof(HttpRuntime).GetField("_appDomainAppVPath", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); - appDomainAppVPathField.SetValue(runtime, CreateVirtualPath(appVPath)); - - if (appPath != null) - { - var appDomainAppPathField = typeof(HttpRuntime).GetField("_appDomainAppPath", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); - appDomainAppPathField.SetValue(runtime, Path.GetFullPath(appPath)); - } - - GetTheRuntime().SetValue(null, runtime); - var appDomainIdField = typeof(HttpRuntime).GetField("_appDomainId", BindingFlags.NonPublic | BindingFlags.Instance); - appDomainIdField.SetValue(runtime, "test"); - - return new DisposableAction(RestoreHttpRuntime); - } - - internal static FieldInfo GetTheRuntime() - { - return typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static); - } - - internal static void RestoreHttpRuntime() - { - GetTheRuntime().SetValue(null, null); - } - - internal static object CreateVirtualPath(string path) - { - var vPath = typeof(Page).Assembly.GetType("System.Web.VirtualPath"); - var method = vPath.GetMethod("CreateNonRelativeTrailingSlash", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); - return method.Invoke(null, new object[] { path }); - } - - private class DisposableAction : IDisposable - { - private Action _action; - private bool _hasDisposed; - - public DisposableAction(Action action) - { - if (action == null) - { - throw new ArgumentNullException("action"); - } - _action = action; - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - // If we were disposed by the finalizer it's because the user didn't use a "using" block, so don't do anything! - if (disposing) - { - lock (this) - { - if (!_hasDisposed) - { - _hasDisposed = true; - _action(); - } - } - } - } - } - } -}