/// <summary> /// Build a TestSuite from type provided. /// </summary> /// <param name="type">The type of the fixture to be used</param> /// <returns>A TestSuite</returns> public Test BuildFrom(Type type) { TestSuite suite = new LegacySuite(type); if (suite.RunState == RunState.NotRunnable) { string reason = null; if (!IsValidFixtureType(type, ref reason)) { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, reason); } } PropertyInfo suiteProperty = GetSuiteProperty(type); MethodInfo method = suiteProperty.GetGetMethod(true); if (method.GetParameters().Length > 0) { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, "Suite property may not be indexed"); } // TODO: Stop checking for name else if (method.ReturnType.FullName == "NUnit.Framework.Internal.TestSuite") { TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]); foreach (Test test in s.Tests) { suite.Add(test); } } else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType)) { foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0])) { Type objType = obj as Type; if (objType != null && _defaultSuiteBuilder.CanBuildFrom(objType)) { suite.Add(_defaultSuiteBuilder.BuildFrom(objType)); } else { var fixture = _defaultSuiteBuilder.BuildFrom(obj.GetType()); if (fixture != null) { fixture.Fixture = obj; } suite.Add(fixture); } } } else { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, "Suite property must return either TestSuite or IEnumerable"); } return(suite); }
public void SuiteReturningTypes() { TestSuite suite = new LegacySuite(typeof(LegacySuiteReturningTypes)); Assert.AreEqual(RunState.Runnable, suite.RunState); Assert.AreEqual(3, suite.Tests.Count); Assert.AreEqual(11, suite.TestCount); }
// [Test] public void SetUpAndTearDownAreCalled() { TestSuite suite = new LegacySuite(typeof(LegacySuiteWithSetUpAndTearDown)); suite.Run(NullListener.NULL); LegacySuiteWithSetUpAndTearDown fixture = (LegacySuiteWithSetUpAndTearDown)suite.Fixture; Assert.AreEqual(1, fixture.setupCount); Assert.AreEqual(1, fixture.teardownCount); }
public void SetUpAndTearDownAreCalled() { setupCount = teardownCount = 0; TestSuite suite = new LegacySuite(typeof(LegacySuiteWithSetUpAndTearDown)); Assert.AreEqual(RunState.Runnable, suite.RunState); suite.Run(NullListener.NULL); Assert.AreEqual(1, setupCount); Assert.AreEqual(1, teardownCount); }
/// <summary> /// Build a TestSuite from type provided. /// </summary> /// <param name="type">The type of the fixture to be used</param> /// <returns>A TestSuite</returns> public Test BuildFrom( Type type ) { TestSuite suite = new LegacySuite( type ); if (suite.RunState == RunState.NotRunnable) { string reason = null; if (!IsValidFixtureType(type, ref reason)) { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, reason); } } PropertyInfo suiteProperty = GetSuiteProperty(type); MethodInfo method = suiteProperty.GetGetMethod(true); if (method.GetParameters().Length > 0) { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, "Suite property may not be indexed"); } // TODO: Stop checking for name else if (method.ReturnType.FullName == "NUnit.Framework.Internal.TestSuite") { TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]); foreach (Test test in s.Tests) suite.Add(test); } else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType)) { foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0])) { Type objType = obj as Type; if (objType != null && _defaultSuiteBuilder.CanBuildFrom(objType)) suite.Add(_defaultSuiteBuilder.BuildFrom(objType)); else { var fixture = _defaultSuiteBuilder.BuildFrom(obj.GetType()); if (fixture != null) fixture.Fixture = obj; suite.Add(fixture); } } } else { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, "Suite property must return either TestSuite or IEnumerable"); } return suite; }
public Test BuildFrom(Type type) { TestSuite suite = new LegacySuite(type); string reason = null; if (!IsValidFixtureType(type, ref reason)) { suite.RunState = RunState.NotRunnable; suite.IgnoreReason = reason; } PropertyInfo suiteProperty = GetSuiteProperty(type); MethodInfo method = suiteProperty.GetGetMethod(true); if (method.GetParameters().Length > 0) { suite.RunState = RunState.NotRunnable; suite.IgnoreReason = "Suite property may not be indexed"; } else if (method.ReturnType.FullName == "NUnit.Core.TestSuite") { TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]); foreach (Test test in s.Tests) { suite.Add(test); } } else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType)) { foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0])) { Type objType = obj as Type; if (objType != null && TestFixtureBuilder.CanBuildFrom(objType)) { suite.Add(TestFixtureBuilder.BuildFrom(objType)); } else { suite.Add(obj); } } } else { suite.RunState = RunState.NotRunnable; suite.IgnoreReason = "Suite property must return either TestSuite or IEnumerable"; } return(suite); }
public Test BuildFrom( Type type ) { TestSuite suite = new LegacySuite( type ); string reason = null; if (!IsValidFixtureType(type, ref reason)) { suite.RunState = RunState.NotRunnable; suite.IgnoreReason = reason; } PropertyInfo suiteProperty = GetSuiteProperty(type); MethodInfo method = suiteProperty.GetGetMethod(true); if (method.GetParameters().Length > 0) { suite.RunState = RunState.NotRunnable; suite.IgnoreReason = "Suite property may not be indexed"; } else if (method.ReturnType.FullName == "NUnit.Core.TestSuite") { TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]); foreach (Test test in s.Tests) suite.Add(test); } else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType)) { foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0])) { Type objType = obj as Type; if (objType != null && TestFixtureBuilder.CanBuildFrom(objType)) suite.Add(TestFixtureBuilder.BuildFrom(objType)); else suite.Add(obj); } } else { suite.RunState = RunState.NotRunnable; suite.IgnoreReason = "Suite property must return either TestSuite or IEnumerable"; } return suite; }
public bool CanBuildFrom(Type type) { return(LegacySuite.GetSuiteProperty(type) != null); }
public void SuitePropertyWithInvalidType() { TestSuite suite = new LegacySuite(typeof(LegacySuiteWithInvalidPropertyType)); Assert.AreEqual(RunState.NotRunnable, suite.RunState); }