public void ConstructWithFixtureArgsAndSetTypeArgs()
 {
     TestFixtureAttribute attr = new TestFixtureAttribute(fixtureArgs);
     attr.TypeArgs = typeArgs;
     Assert.That(attr.Arguments, Is.EqualTo(fixtureArgs));
     Assert.That(attr.TypeArgs, Is.EqualTo(typeArgs));
 }
        public void ConstructWithFixtureArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(fixtureArgs);

            Assert.That(attr.Arguments, Is.EqualTo(fixtureArgs));
            Assert.That(attr.TypeArgs.Length == 0);
        }
        public void ConstructWithJustTypeArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(typeArgs);

            Assert.That(attr.Arguments.Length == 2);
            Assert.That(attr.TypeArgs.Length == 0);
        }
 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);
 }
        public void ConstructWithoutArguments()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute();
            Assert.That(attr.Arguments.Length == 0);
#if CLR_2_0 || CLR_4_0
            Assert.That(attr.TypeArgs.Length == 0);
#endif
        }
        public void ConstructWithFixtureArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(fixtureArgs);
            Assert.That(attr.Arguments, Is.EqualTo( fixtureArgs ) );
#if CLR_2_0 || CLR_4_0
            Assert.That(attr.TypeArgs.Length == 0 );
#endif
        }
예제 #7
0
        public void CategoriesIncludesCategoryProperty()
        {
            TestFixtureAttribute tfa = new TestFixtureAttribute();

            tfa.Categories = "Panda";
            Assert.True(tfa._Categories.Contains("Panda"),
                        "Categories doesn't contain expected category 'Panda'.");
        }
예제 #8
0
        public void ConstructWithWeakTypedNullArgument()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(null);

            Assert.That(attr.Arguments, Is.Not.Null);
            Assert.That(attr.Arguments[0], Is.Null);
            Assert.That(attr.TypeArgs, Is.Not.Null);
        }
        public void ConstructWithFixtureArgsAndSetTypeArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(fixtureArgs);

            attr.TypeArgs = typeArgs;
            Assert.That(attr.Arguments, Is.EqualTo(fixtureArgs));
            Assert.That(attr.TypeArgs, Is.EqualTo(typeArgs));
        }
예제 #10
0
        /// <summary>
        /// Get TestFixtureAttributes following a somewhat obscure
        /// set of rules to eliminate spurious duplication of fixtures.
        /// 1. If there are any attributes with args, they are the only
        ///    ones returned and those without args are ignored.
        /// 2. No more than one attribute without args is ever returned.
        /// </summary>
        private TestFixtureAttribute[] GetTestFixtureAttributes(Type type)
        {
            TestFixtureAttribute[] attrs =
                (TestFixtureAttribute[])type.GetCustomAttributes(typeof(TestFixtureAttribute), true);

            // Just return - no possibility of duplication
            if (attrs.Length <= 1)
            {
                return(attrs);
            }

            int withArgs = 0;

            bool[] hasArgs = new bool[attrs.Length];

            // Count and record those attrs with arguments
            for (int i = 0; i < attrs.Length; i++)
            {
                object[] args     = attrs[i].Arguments;
                object[] typeArgs = attrs[i].TypeArgs;

                if (args.Length > 0 || typeArgs != null && typeArgs.Length > 0)
                {
                    withArgs++;
                    hasArgs[i] = true;
                }
            }

            // If all attributes have args, just return them
            if (withArgs == attrs.Length)
            {
                return(attrs);
            }

            // If all attributes are without args, just return the first found
            if (withArgs == 0)
            {
                return new TestFixtureAttribute[] { attrs[0] }
            }
            ;

            // Some of each type, so extract those with args
            int count = 0;

            TestFixtureAttribute[] result = new TestFixtureAttribute[withArgs];
            for (int i = 0; i < attrs.Length; i++)
            {
                if (hasArgs[i])
                {
                    result[count++] = attrs[i];
                }
            }

            return(result);
        }

        #endregion
    }
예제 #11
0
        public void ConstructWithFixtureArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(fixtureArgs);

            Assert.That(attr.Arguments, Is.EqualTo(fixtureArgs));
#if CLR_2_0 || CLR_4_0
            Assert.That(attr.TypeArgs == null);
#endif
        }
        public void GetAttributeInstance_ReturnsNull_IfAttributeNotPresent()
        {
            MethodInfo    methodInfo    = GetType().GetMethod("TheTestMethod", BindingFlags.NonPublic | BindingFlags.Instance);
            ParameterInfo parameterInfo = methodInfo.GetParameters()[0];

            TestFixtureAttribute actual = ReflectionExtensions.GetAttributeInstance <TestFixtureAttribute>(parameterInfo);

            Assert.IsNull(actual);
        }
        public void ConstructWithoutArguments()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute();

            Assert.That(attr.Arguments.Length == 0);
#if NET_2_0
            Assert.That(attr.TypeArgs.Length == 0);
#endif
        }
        public void TestTestFixtureAttribute()
        {
            TestFixtureAttribute testFixture = new TestFixtureAttribute();

            Assert.IsNull(testFixture.Description);
            testFixture = new TestFixtureAttribute("Message");
            Assert.AreEqual("Message", testFixture.Description);
            testFixture.Description = "Message 2";
            Assert.AreEqual("Message 2", testFixture.Description);
        }
예제 #15
0
        public void ConstructWithJustTypeArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute()
            {
                TypeArgs = TYPE_ARGS
            };

            Assert.That(attr.Arguments.Length == 0);
            Assert.That(attr.TypeArgs, Is.EqualTo(TYPE_ARGS));
        }
예제 #16
0
        public void ConstructWithFixtureArgsAndSetTypeArgs()
        {
            TestFixtureAttribute attr = new TestFixtureAttribute(FIXTURE_ARGS)
            {
                TypeArgs = TYPE_ARGS
            };

            Assert.That(attr.Arguments, Is.EqualTo(FIXTURE_ARGS));
            Assert.That(attr.TypeArgs, Is.EqualTo(TYPE_ARGS));
        }
예제 #17
0
        static TestFixtureParameters CreateTestFixtureDataForGenericTest(Type genericType)
        {
            var data = new TestFixtureAttribute
            {
                TypeArgs = new[] { genericType }
            };
            var parameters = new TestFixtureParameters(data);

            return(parameters);
        }
예제 #18
0
        public void BaseSetup()
        {
            TestFixtureAttribute a = Attribute.GetCustomAttribute(GetType(), typeof(TestFixtureAttribute)) as TestFixtureAttribute;

            if (NeedsResourcePack && Headless)
            {
                // Disable the test automatically.
                a.Explicit = true;
                return;
            }

            // Clear state across tests.
            IoCManager.Clear();
            RegisterIoC();

            var Assemblies = new List <Assembly>(4);

            switch (Project)
            {
            case UnitTestProject.Client:
                Assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("SS14.Client"));
                break;

            case UnitTestProject.Server:
                Assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("SS14.Server"));
                break;

            default:
                throw new NotSupportedException($"Unknown testing project: {Project}");
            }

            Assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("SS14.Shared"));
            Assemblies.Add(Assembly.GetExecutingAssembly());

            IoCManager.Resolve <IReflectionManager>().LoadAssemblies(Assemblies);

            if (NeedsClientConfig)
            {
                //ConfigurationManager setup
                GetConfigurationManager = IoCManager.Resolve <IConfigurationManager>();
                GetConfigurationManager.LoadFromFile(PathHelpers.ExecutableRelativeFile("./client_config.toml"));
            }

            /*
             * if (NeedsResourcePack)
             * {
             *  GetResourceCache = IoCManager.Resolve<IResourceCache>();
             *  InitializeResources();
             * }
             */
        }
예제 #19
0
        void IterateThroughTypes(Type[] types)
        {
            foreach (Type type in types)
            {
                TestFixtureAttribute testFixtureAttr = Attribute.GetCustomAttribute(type, typeof(TestFixtureAttribute), false) as TestFixtureAttribute;

                if (testFixtureAttr != null || !requireTestFixture)
                {
                    MethodInfo[] methods = type.GetMethods();

                    foreach (MethodInfo method in methods)
                    {
                        TestAttribute     testAttr     = Attribute.GetCustomAttribute(method, typeof(TestAttribute), false) as TestAttribute;
                        SetUpAttribute    setupAttr    = Attribute.GetCustomAttribute(method, typeof(SetUpAttribute), false) as SetUpAttribute;
                        TearDownAttribute teardownAttr = Attribute.GetCustomAttribute(method, typeof(TearDownAttribute), false) as TearDownAttribute;

                        if (testAttr != null)
                        {
                            try
                            {
                                ConstructorInfo[] constructors  = type.GetConstructors();
                                object            curTestObject = null;

                                if (constructors.Length > 0)
                                {
                                    curTestObject = constructors[0].Invoke(null);
                                }

                                if (curTestObject != null)
                                {
                                    testMethods[method] = curTestObject;
                                }
                            }
                            catch
                            {
                                // Fail the test here?
                            }
                        }
                        else if (setupAttr != null)
                        {
                            setupMethods.Add(type, method);
                        }
                        else if (teardownAttr != null)
                        {
                            teardownMethods.Add(type, method);
                        }
                    }
                }
            }
        }
예제 #20
0
        public SS14UnitTest()
        {
            TestFixtureAttribute a = Attribute.GetCustomAttribute(GetType(), typeof(TestFixtureAttribute)) as TestFixtureAttribute;

            if (NeedsResourcePack && Headless)
            {
                // Disable the test automatically.
                a.Explicit = true;
                return;
            }

            // Clear state across tests.
            IoCManager.Clear();
            RegisterIoC();

            var    Assemblies  = new List <Assembly>(4);
            string AssemblyDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            switch (Project)
            {
            case UnitTestProject.Client:
                Assemblies.Add(Assembly.LoadFrom(Path.Combine(AssemblyDir, "SS14.Client.exe")));
                break;

            case UnitTestProject.Server:
                Assemblies.Add(Assembly.LoadFrom(Path.Combine(AssemblyDir, "SS14.Server.exe")));
                break;

            default:
                throw new NotSupportedException($"Unknown testing project: {Project}");
            }

            Assemblies.Add(Assembly.LoadFrom(Path.Combine(AssemblyDir, "SS14.Shared.dll")));
            Assemblies.Add(Assembly.GetExecutingAssembly());

            IoCManager.Resolve <IReflectionManager>().LoadAssemblies(Assemblies);

            if (NeedsClientConfig)
            {
                //ConfigurationManager setup
                GetConfigurationManager = IoCManager.Resolve <IConfigurationManager>();
                GetConfigurationManager.LoadFromFile(PathHelpers.AssemblyRelativeFile("./client_config.toml", Assembly.GetExecutingAssembly()));
            }

            if (NeedsResourcePack)
            {
                GetResourceManager = IoCManager.Resolve <IResourceManager>();
                InitializeResources();
            }
        }
예제 #21
0
        private static bool MatchesAttribute(TestFixtureAttribute attribute, string[] parameterNames)
        {
            if (attribute.Arguments.Length != parameterNames.Length)
            {
                return(false);
            }

            for (int i = 0; i < parameterNames.Length; i++)
            {
                if (parameterNames[i] != attribute.Arguments[i].ToString())
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #22
0
        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);
        }
예제 #23
0
        private static TestFixtureParameters CreateTestCase <
            TScriptableEvent,
            TScriptableEventListener,
            TArg
            >(TArg arg)
            where TScriptableEvent : BaseScriptableEvent <TArg>
            where TScriptableEventListener : BaseScriptableEventListener <TArg>
        {
            var attribute = new TestFixtureAttribute(arg)
            {
                TypeArgs = new[]
                {
                    typeof(TScriptableEvent),
                    typeof(TScriptableEventListener),
                    arg.GetType()
                }
            };

            return(new TestFixtureParameters(attribute));
        }
예제 #24
0
        /// <summary>
        /// Get TestFixtureAttributes following a somewhat obscure
        /// set of rules to eliminate spurious duplication of fixtures.
        /// 1. If there are any attributes with args, they are the only
        ///    ones returned and those without args are ignored.
        /// 2. No more than one attribute without args is ever returned.
        /// </summary>
        private TestFixtureAttribute[] GetTestFixtureAttributes(Type type)
        {
            TestFixtureAttribute[] attrs = 
                (TestFixtureAttribute[])type.GetCustomAttributes(typeof(TestFixtureAttribute), true);

            // Just return - no possibility of duplication
            if (attrs.Length <= 1)
                return attrs;

            int withArgs = 0;
            bool[] hasArgs = new bool[attrs.Length];

            // Count and record those attrs with arguments            
            for (int i = 0; i < attrs.Length; i++)
            {
                TestFixtureAttribute attr = attrs[i];

                if (attr.Arguments.Length > 0 || attr.TypeArgs.Length > 0)
                {
                    withArgs++;
                    hasArgs[i] = true;
                }
            }

            // If all attributes have args, just return them
            if (withArgs == attrs.Length)
                return attrs;

            // If all attributes are without args, just return the first found
            if (withArgs == 0)
                return new TestFixtureAttribute[] { attrs[0] };

            // Some of each type, so extract those with args
            int count = 0;
            TestFixtureAttribute[] result = new TestFixtureAttribute[withArgs];
            for (int i = 0; i < attrs.Length; i++)
                if (hasArgs[i])
                    result[count++] = attrs[i];

            return result;
        }
        private TestFixtureAttribute[] GetTestFixtureAttributes(Type type)
        {
            TestFixtureAttribute[] array = (TestFixtureAttribute[])type.GetCustomAttributes(typeof(TestFixtureAttribute), inherit: true);
            if (array.Length <= 1)
            {
                return(array);
            }
            int num = 0;

            bool[] array2 = new bool[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                TestFixtureAttribute testFixtureAttribute = array[i];
                if (testFixtureAttribute.Arguments.Length > 0 || testFixtureAttribute.TypeArgs.Length > 0)
                {
                    num++;
                    array2[i] = true;
                }
            }
            if (num == array.Length)
            {
                return(array);
            }
            if (num == 0)
            {
                return(new TestFixtureAttribute[1] {
                    array[0]
                });
            }
            int num2 = 0;

            TestFixtureAttribute[] array3 = new TestFixtureAttribute[num];
            for (int i = 0; i < array.Length; i++)
            {
                if (array2[i])
                {
                    array3[num2++] = array[i];
                }
            }
            return(array3);
        }
        public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter)
        {
            if (_serviceVersions.Any())
            {
                foreach (object serviceVersion in _serviceVersions)
                {
                    var syncFixture  = new TestFixtureAttribute(false, serviceVersion);
                    var asyncFixture = new TestFixtureAttribute(true, serviceVersion);

                    foreach (TestSuite testSuite in asyncFixture.BuildFrom(typeInfo, filter))
                    {
                        Process(testSuite, serviceVersion, true);
                        yield return(testSuite);
                    }

                    foreach (TestSuite testSuite in syncFixture.BuildFrom(typeInfo, filter))
                    {
                        Process(testSuite, serviceVersion, false);
                        yield return(testSuite);
                    }
                }
            }
            else
            {
                // No service versions defined
                var syncFixture  = new TestFixtureAttribute(false);
                var asyncFixture = new TestFixtureAttribute(true);

                foreach (TestSuite testSuite in asyncFixture.BuildFrom(typeInfo, filter))
                {
                    Process(testSuite, null, true);
                    yield return(testSuite);
                }

                foreach (TestSuite testSuite in syncFixture.BuildFrom(typeInfo, filter))
                {
                    Process(testSuite, null, false);
                    yield return(testSuite);
                }
            }
        }
        public void OneTimeSetUp()
        {
            var testClassType = typeof(FizzBuzzServiceTests);

            _testFixtureAttribute = testClassType.GetCustomAttribute <TestFixtureAttribute>();

            _setupMethod = testClassType.GetMethods()
                           .FirstOrDefault(m => m.GetCustomAttribute <SetUpAttribute>() != null);

            _generateFizzBuzzWithCorrectParamtersTestMethod =
                testClassType.GetMethod(GenerateFizzBuzzWithCorrectParamtersTestMethodName);

            _checkExceptionThrowingWhenFizzIsOutOfRangTestMethod =
                testClassType.GetMethod(CheckExceptionThrowingWhenFizzIsOutOfRangeMethodName);

            _checkExceptionThrowingWhenBuzzIsOutOfRangTestMethod =
                testClassType.GetMethod(CheckExceptionThrowingWhenBuzzIsOutOfRangeMethodName);

            _checkExceptionThrowingWhenLastNumberIsOutOfRangTestMethod =
                testClassType.GetMethod(CheckExceptionThrowingWhenLastNumberIsOutOfRangeMethodName);

            _testClassContent = Solution.Current.GetFileContent(@"FizzBuzz.Business.Tests\FizzBuzzServiceTests.cs");
        }
예제 #28
0
        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);
        }
        public void Initialize()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            foreach (Type type in assembly.GetTypes())
            {
                TestFixtureAttribute fixtureAttribute = type.GetCustomAttribute <TestFixtureAttribute>();
                if (fixtureAttribute == null)
                {
                    continue;
                }

                object           fixtureInstance = Activator.CreateInstance(type);
                TestClassCommand classCommand    = new TestClassCommand(fixtureInstance);

                foreach (MethodInfo method in type.GetMethods())
                {
                    TestAttribute testAttribute = method.GetCustomAttribute <TestAttribute>();
                    if (testAttribute == null)
                    {
                        continue;
                    }

                    TestMethodCommand methodCommand = new TestMethodCommand(method)
                    {
                        Iterations     = testAttribute.Iterations,
                        PartitionCount = testAttribute.PartitionCount
                    };

                    string methodName = method.Name.Replace("Tests", string.Empty).Replace("Test", string.Empty).ToLower();
                    classCommand.AddTestMethodCommand(methodName, methodCommand);
                }

                testClassCommands.Add(type.Name.ToLower(), classCommand);
            }
        }
        /// <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);
        }
 public void TestFixtureAttributeHasDefaultCategory() {
    TestFixtureAttribute tfa = new TestFixtureAttribute();
    Assert.Equals(string.Empty, tfa.Categories);
 }
 public void CategoriesIncludesCategoryProperty() {
    TestFixtureAttribute tfa = new TestFixtureAttribute();
    tfa.Categories = "Panda";
    Assert.True(tfa._Categories.Contains("Panda"), 
       "Categories doesn't contain expected category 'Panda'.");
 }
        public void GetAttributeInstance_ReturnsNull_IfAttributeIsNotPresentOnClass()
        {
            TestFixtureAttribute actual = ReflectionExtensions.GetAttributeInstance <TestFixtureAttribute>(typeof(Cookie));

            Assert.IsNull(actual);
        }
예제 #34
0
        /// <summary>
        /// Get TestFixtureAttributes following a somewhat obscure
        /// set of rules to eliminate spurious duplication of fixtures.
        /// 1. If there are any attributes with args, they are the only
        ///    ones returned and those without args are ignored.
        /// 2. No more than one attribute without args is ever returned.
        /// </summary>
        private TestFixtureAttribute[] GetTestFixtureAttributes(Type type)
        {
            TestFixtureAttribute[] attrs = 
                (TestFixtureAttribute[])type.GetCustomAttributes(typeof(TestFixtureAttribute), true);

            // Just return - no possibility of duplication
            if (attrs.Length <= 1)
                return attrs;

            int withArgs = 0;
            bool[] hasArgs = new bool[attrs.Length];

            // Count and record those attrs with arguments            
            for (int i = 0; i < attrs.Length; i++)
            {
                TestFixtureAttribute attr = attrs[i];

                if (attr.Arguments.Length > 0 || attr.TypeArgs.Length > 0)
                {
                    withArgs++;
                    hasArgs[i] = true;
                }
            }

            // If all attributes have args, just return them
            if (withArgs == attrs.Length)
                return attrs;

            // If all attributes are without args, just return the first found
            if (withArgs == 0)
                return new TestFixtureAttribute[] { attrs[0] };

            // Some of each type, so extract those with args
            int count = 0;
            TestFixtureAttribute[] result = new TestFixtureAttribute[withArgs];
            for (int i = 0; i < attrs.Length; i++)
                if (hasArgs[i])
                    result[count++] = attrs[i];

            return result;
        }
예제 #35
0
        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);

            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;
        }
예제 #36
0
        private Test BuildMultipleFixtures(Type type, TestFixtureAttribute[] attrs)
        {
            TestSuite suite = new ParameterizedFixtureSuite(type);

            if (attrs.Length > 0)
            {
                foreach (TestFixtureAttribute attr in attrs)
                    suite.Add(BuildSingleFixture(type, attr));
            }
            else
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, NO_TYPE_ARGS_MSG);
            }

            return suite;
        }
 public void ConstructWithCombinedArgs()
 {
     TestFixtureAttribute attr = new TestFixtureAttribute(combinedArgs);
     Assert.That(attr.Arguments, Is.EqualTo(fixtureArgs));
     Assert.That(attr.TypeArgs, Is.EqualTo(typeArgs));
 }
예제 #38
0
 public void ConstructWithJustTypeArgs()
 {
     TestFixtureAttribute attr = new TestFixtureAttribute(typeArgs);
     Assert.That(attr.Arguments.Length == 2);
     Assert.That(attr.TypeArgs == null);
 }
 public void ConstructWithJustTypeArgs()
 {
     TestFixtureAttribute attr = new TestFixtureAttribute(typeArgs);
     Assert.That(attr.Arguments.Length == 0);
     Assert.That(attr.TypeArgs, Is.EqualTo(typeArgs));
 }
예제 #40
0
        public static string GetDescription(Type fixtureType)
        {
            TestFixtureAttribute attribute = GetTestFixtureAttribute(fixtureType);

            return(attribute == null ? null : attribute.Description);
        }
        /// <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;
        }
예제 #42
0
        public void TestFixtureAttributeHasDefaultCategory()
        {
            TestFixtureAttribute tfa = new TestFixtureAttribute();

            Assert.Equals(string.Empty, tfa.Categories);
        }