private Test BuildSingleFixture(Type type, Attribute attr) { object[] arguments = null; if (attr != null) { arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments"); #if NET_2_0 if (type.ContainsGenericParameters) { Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs"); if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new NUnitTestFixture(type, arguments); CheckTestFixtureIsValid(fixture); NUnitFramework.ApplyCommonAttributes(type, fixture); AddTestCases(type); if (this.fixture.RunState != RunState.NotRunnable && this.fixture.TestCount == 0) { this.fixture.RunState = RunState.NotRunnable; this.fixture.IgnoreReason = fixture.TestName.Name + " does not have any tests"; } return(this.fixture); }
private Test BuildSingleFixture(Type type, TestFixtureAttribute attr) { object[] array = null; if (attr != null) { array = attr.Arguments; if (type.ContainsGenericParameters) { Type[] typeArgsOut = attr.TypeArgs; if (typeArgsOut.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, array, ref typeArgsOut)) { type = TypeHelper.MakeGenericType(type, typeArgsOut); } } } fixture = new TestFixture(type, array); CheckTestFixtureIsValid(fixture); fixture.ApplyCommonAttributes(type); if (fixture.RunState == RunState.Runnable && attr != null && attr.Ignore) { fixture.RunState = RunState.Ignored; fixture.Properties.Set(PropertyNames.SkipReason, attr.IgnoreReason); } AddTestCases(type); return(fixture); }
private Test BuildSingleFixture(Type type, Attribute attr) { object[] arguments = null; IList categories = null; if (attr != null) { arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments"); categories = Reflect.GetPropertyValue(attr, "Categories") as IList; #if CLR_2_0 || CLR_4_0 if (type.ContainsGenericParameters) { Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs"); if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new NUnitTestFixture(type, arguments); CheckTestFixtureIsValid(fixture); NUnitFramework.ApplyCommonAttributes(type, fixture); if (categories != null) { foreach (string category in categories) { fixture.Categories.Add(category); } } if (fixture.RunState == RunState.Runnable && attr != null) { object objIgnore = Reflect.GetPropertyValue(attr, "Ignore"); if (objIgnore != null && (bool)objIgnore == true) { fixture.RunState = RunState.Ignored; fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason"); } } AddTestCases(type); return(this.fixture); }
private Test BuildSingleFixture(Type type, TestFixtureAttribute attr) { object[] arguments = null; if (attr != null) { arguments = (object[])attr.Arguments; #if CLR_2_0 || CLR_4_0 if (type.ContainsGenericParameters) { Type[] typeArgs = (Type[])attr.TypeArgs; if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new TestFixture(type, arguments); CheckTestFixtureIsValid(fixture); #if PORTABLE fixture.ApplyAttributesToTest(type.AsCustomAttributeProvider()); #else fixture.ApplyAttributesToTest(type); #endif if (fixture.RunState == RunState.Runnable && attr != null) { if (attr.Ignore) { fixture.RunState = RunState.Ignored; fixture.Properties.Set(PropertyNames.SkipReason, attr.IgnoreReason); } } AddTestCases(type); return(this.fixture); }
private TestFixture BuildSingleFixture(Type type, TestFixtureAttribute attr) { object[] arguments = null; if (attr != null) { arguments = (object[])attr.Arguments; if (type.ContainsGenericParameters) { Type[] typeArgs = attr.TypeArgs; if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } } this._fixture = new TestFixture(type, arguments); CheckTestFixtureIsValid(_fixture); _fixture.ApplyAttributesToTest(type); if (_fixture.RunState == RunState.Runnable && attr != null) { if (attr.Ignore) { _fixture.RunState = RunState.Ignored; _fixture.Properties.Set(PropertyNames.SkipReason, attr.Reason); } } AddTestCases(type); return(this._fixture); }
/// <summary> /// Overload of BuildFrom called by TestFixtureAttribute. Builds /// a fixture using the provided type and information in the /// properties of the attribute. /// </summary> /// <param name="type">The Type for which to construct a fixture.</param> /// <param name="attr">The attribute marking the fixture Type.</param> /// <returns></returns> public TestSuite BuildFrom(Type type, TestFixtureAttribute attr) { object[] arguments = null; if (attr != null) { arguments = attr.Arguments; #if !NETCF if (type.ContainsGenericParameters) { Type[] typeArgs = attr.TypeArgs; if (typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new TestFixture(type); if (arguments != null) { string name = fixture.Name = TypeHelper.GetDisplayName(type, arguments); string nspace = type.Namespace; fixture.FullName = nspace != null && nspace != "" ? nspace + "." + name : name; fixture.Arguments = arguments; } if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(type); AddTestCases(type); return(this.fixture); }
/// <summary> /// Overload of BuildFrom called by tests that have arguments. /// Builds a fixture using the provided type and information /// in the ITestFixtureData object. /// </summary> /// <param name="typeInfo">The TypeInfo for which to construct a fixture.</param> /// <param name="filter">Filter used to select methods as tests.</param> /// <param name="testFixtureData">An object implementing ITestFixtureData or null.</param> /// <returns></returns> public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter, ITestFixtureData testFixtureData) { Guard.ArgumentNotNull(testFixtureData, nameof(testFixtureData)); object[] arguments = testFixtureData.Arguments; if (typeInfo.ContainsGenericParameters) { Type[] typeArgs = testFixtureData.TypeArgs; if (typeArgs == null || typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(typeInfo.Type, arguments, ref typeArgs)) { typeInfo = typeInfo.MakeGenericType(typeArgs); } } var fixture = new TestFixture(typeInfo, arguments); string name = fixture.Name; if (testFixtureData.TestName != null) { fixture.Name = testFixtureData.TestName; } else { var argDisplayNames = (testFixtureData as TestParameters)?.ArgDisplayNames; if (argDisplayNames != null) { fixture.Name = typeInfo.GetDisplayName(); if (argDisplayNames.Length != 0) { fixture.Name += '(' + string.Join(", ", argDisplayNames) + ')'; } } else if (arguments != null && arguments.Length > 0) { fixture.Name = typeInfo.GetDisplayName(arguments); } } if (fixture.Name != name) // name was changed { string nspace = typeInfo.Namespace; fixture.FullName = nspace != null && nspace != "" ? nspace + "." + fixture.Name : fixture.Name; } if (fixture.RunState != RunState.NotRunnable) { fixture.RunState = testFixtureData.RunState; } foreach (string key in testFixtureData.Properties.Keys) { foreach (object val in testFixtureData.Properties[key]) { fixture.Properties.Add(key, val); } } if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); return(fixture); }
private Test BuildSingleFixture(Type type, Attribute attr) { object[] arguments = null; IList categories = null; if (attr != null) { arguments = GetArgsFromAttribute(attr); categories = Reflect.GetPropertyValue(attr, "Categories") as IList; #if CLR_2_0 || CLR_4_0 if (type.ContainsGenericParameters) { Type[] typeArgs = GetTypeArgsFromAttribute(attr); if (typeArgs == null) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new NUnitTestFixture(type, arguments); CheckTestFixtureIsValid(fixture); NUnitFramework.ApplyCommonAttributes(type, fixture); if (categories != null) { foreach (string category in categories) { fixture.Categories.Add(category); } } if (fixture.RunState == RunState.Runnable && attr != null) { object objIgnore = Reflect.GetPropertyValue(attr, "Ignore"); if (objIgnore != null && (bool)objIgnore == true) { fixture.RunState = RunState.Ignored; fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason"); } } AddTestCases(type); return(this.fixture); }
/// <summary> /// Overload of BuildFrom called by tests that have arguments. /// Builds a fixture using the provided type and information /// in the ITestFixtureData object. /// </summary> /// <param name="typeInfo">The TypeInfo for which to construct a fixture.</param> /// <param name="filter">Filter used to select methods as tests.</param> /// <param name="testFixtureData">An object implementing ITestFixtureData or null.</param> /// <returns></returns> public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter, ITestFixtureData testFixtureData) { //Guard.ArgumentNotNull(testFixtureData, nameof(testFixtureData)); if (testFixtureData is null) { throw new ArgumentNullException(nameof(testFixtureData)); } object[] arguments = testFixtureData.Arguments; if (typeInfo.ContainsGenericParameters) { Type[] typeArgs = testFixtureData.TypeArgs; if (typeArgs is null || typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(typeInfo.Type, arguments, ref typeArgs)) { typeInfo = typeInfo.MakeGenericType(typeArgs); } } // Build our custom SetUpFixture to get the NUnit runner to initialize us // even though we don't own the test assembly. var setUpFixture = _setUpFixtureBuilder.BuildFrom(typeInfo); var fixture = new TestFixture(typeInfo, arguments); SetUpRandomizedContext(setUpFixture, fixture); string name = fixture.Name; if (testFixtureData.TestName != null) { fixture.Name = testFixtureData.TestName; } else { //var argDisplayNames = (testFixtureData as NUnit.Framework.Internal.TestParameters)?.ArgDisplayNames; var testParameters = testFixtureData as NUnit.Framework.Internal.TestParameters; string[] argDisplayNames = null; if (testParameters != null) { // Hack so we can call the same internal field that NUnit does BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; FieldInfo field = typeof(NUnit.Framework.Internal.TestParameters).GetField("_argDisplayNames", bindFlags); argDisplayNames = (string[])field.GetValue(testFixtureData); } if (argDisplayNames != null) { fixture.Name = typeInfo.GetDisplayName(); if (argDisplayNames.Length != 0) { fixture.Name += '(' + string.Join(", ", argDisplayNames) + ')'; } } else if (arguments != null && arguments.Length > 0) { fixture.Name = typeInfo.GetDisplayName(arguments); } } if (fixture.Name != name) // name was changed { string nspace = typeInfo.Namespace; fixture.FullName = nspace != null && nspace != "" ? nspace + "." + fixture.Name : fixture.Name; } if (fixture.RunState != RunState.NotRunnable) { fixture.RunState = testFixtureData.RunState; } foreach (string key in testFixtureData.Properties.Keys) { foreach (object val in testFixtureData.Properties[key]) { fixture.Properties.Add(key, val); } } if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); setUpFixture.Add(fixture); return(setUpFixture); }
/// <summary> /// Overload of BuildFrom called by tests that have arguments. /// Builds a fixture using the provided type and information /// in the ITestFixtureData object. /// </summary> /// <param name="type">The Type for which to construct a fixture.</param> /// <param name="testFixtureData">An object implementing ITestFixtureData or null.</param> /// <returns></returns> public TestSuite BuildFrom(Type type, ITestFixtureData testFixtureData) { Guard.ArgumentNotNull(testFixtureData, "testFixtureData"); object[] arguments = testFixtureData.Arguments; if (type.ContainsGenericParameters) { Type[] typeArgs = testFixtureData.TypeArgs; if (typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } var fixture = new TestFixture(type); if (arguments != null && arguments.Length > 0) { string name = fixture.Name = TypeHelper.GetDisplayName(type, arguments); string nspace = type.Namespace; fixture.FullName = nspace != null && nspace != "" ? nspace + "." + name : name; fixture.Arguments = arguments; } if (fixture.RunState != RunState.NotRunnable) { fixture.RunState = testFixtureData.RunState; } foreach (string key in testFixtureData.Properties.Keys) { foreach (object val in testFixtureData.Properties[key]) { fixture.Properties.Add(key, val); } } if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(type); AddTestCasesToFixture(fixture); return(fixture); }
private Test BuildSingleFixture(Type type, TestFixtureAttribute attr) { object[] arguments = null; if (attr != null) { arguments = attr.Arguments; #if !NETCF if (type.ContainsGenericParameters) { Type[] typeArgs = attr.TypeArgs; if (typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new TestFixture(type, arguments); CheckTestFixtureIsValid(fixture); fixture.ApplyAttributesToTest(type); if (fixture.RunState == RunState.Runnable && attr != null) { if (attr.Ignore) { fixture.RunState = RunState.Ignored; fixture.Properties.Set(PropertyNames.SkipReason, attr.IgnoreReason); } } AddTestCases(type); return(this.fixture); }