Пример #1
0
        /// <summary>
        ///  TODO: Documentation needed for constructor
        /// </summary>
        /// <param name="typeInfo"></param>
        protected Test(ITypeInfo typeInfo)
        {
            Initialize(typeInfo.GetDisplayName());

            string nspace = typeInfo.Namespace;

            if (nspace != null && nspace != "")
            {
                FullName = nspace + "." + Name;
            }
            TypeInfo = typeInfo;
        }
Пример #2
0
 protected Test(ITypeInfo typeInfo)
     : this(pathName : typeInfo.Namespace, name : typeInfo.GetDisplayName(), typeInfo : typeInfo, method : null)
 {
 }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <summary>
        ///  TODO: Documentation needed for constructor
        /// </summary>
        /// <param name="typeInfo"></param>
        protected Test(ITypeInfo typeInfo)
        {
            Initialize(typeInfo.GetDisplayName());

            string nspace = typeInfo.Namespace;
            if (nspace != null && nspace != "")
                FullName = nspace + "." + Name;
            TypeInfo = typeInfo;
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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="testFixtureData">An object implementing ITestFixtureData or null.</param>
        /// <returns></returns>
        public TestSuite BuildFrom(ITypeInfo typeInfo, ITestFixtureData testFixtureData)
        {
            Guard.ArgumentNotNull(testFixtureData, "testFixtureData");

            object[] arguments = testFixtureData.Arguments;

            if (typeInfo.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(typeInfo.Type, arguments, ref typeArgs))
                {
                    typeInfo = typeInfo.MakeGenericType(typeArgs);
                }
            }

            var fixture = new TestFixture(typeInfo);
            
            if (arguments != null && arguments.Length > 0)
            {
                string name = fixture.Name = typeInfo.GetDisplayName(arguments);
                string nspace = typeInfo.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(typeInfo.Type.GetTypeInfo());

            AddTestCasesToFixture(fixture);

            return fixture;
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParameterizedFixtureSuite"/> class.
 /// </summary>
 /// <param name="typeInfo">The ITypeInfo for the type that represents the suite.</param>
 public ParameterizedFixtureSuite(ITypeInfo typeInfo) : base(typeInfo.Namespace, typeInfo.GetDisplayName())
 {
     _genericFixture = typeInfo.ContainsGenericParameters;
 }
 public string GetDisplayName()
 {
     return(_baseInfo.GetDisplayName());
 }