Esempio n. 1
0
            /// <summary/>
            public RunAssembly(Executor executor, object _handler)
            {
                ExecutorCallback handler = ExecutorCallback.Wrap(_handler);

                executor.RunOnSTAThreadWithPreservedWorkingDirectory(() =>
                {
                    bool @continue         = true;
                    AssemblyResult results =
                        new AssemblyResult(executor.assemblyFilename,
                                           AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

                    foreach (Type type in executor.assembly.GetExportedTypes())
                    {
                        ITestClassCommand testClassCommand = TestClassCommandFactory.Make(type);

                        if (testClassCommand != null)
                        {
                            ClassResult classResult =
                                TestClassCommandRunner.Execute(testClassCommand,
                                                               null,
                                                               command => @continue = OnTestStart(command, handler),
                                                               result => @continue  = OnTestResult(result, handler));

                            results.Add(classResult);
                        }

                        if (!@continue)
                        {
                            break;
                        }
                    }

                    OnTestResult(results, handler);
                });
            }
        public void NoTestMethodsShouldReturnNull()
        {
            Type type = typeof(StubClass);
            ITestClassCommand command = TestClassCommandFactory.Make(type);

            Assert.Null(command);
        }
        public void RunWithClassReturnsTypeToRunWith()
        {
            ITestClassCommand command = TestClassCommandFactory.Make(typeof(MyRunWithTestClass));

            Assert.IsType <MyRunWith>(command);
            Assert.Equal(typeof(MyRunWithTestClass), command.TypeUnderTest.Type);
        }
Esempio n. 4
0
        private Test TryGetTypeTest(ITypeInfo type, Test assemblyTest)
        {
            Test typeTest;

            if (!typeTests.TryGetValue(type, out typeTest))
            {
                try
                {
                    XunitTypeInfoAdapter xunitTypeInfo = new XunitTypeInfoAdapter(type);
                    ITestClassCommand    command       = TestClassCommandFactory.Make(xunitTypeInfo);
                    if (command != null)
                    {
                        typeTest = CreateTypeTest(xunitTypeInfo, command);
                    }
                }
                catch (Exception ex)
                {
                    TestModel.AddAnnotation(new Annotation(AnnotationType.Error, type, "An exception was thrown while exploring an xUnit.net test type.", ex));
                }

                if (typeTest != null)
                {
                    assemblyTest.AddChild(typeTest);
                    typeTests.Add(type, typeTest);
                }
            }

            return(typeTest);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the test class command, which implements <see cref="ITestClassCommand"/>, for a given type.
        /// </summary>
        /// <param name="typeInfo">The type under test</param>
        /// <returns>The test class command, if the class is a test class; null, otherwise</returns>
        public static ITestClassCommand Make(ITypeInfo typeInfo)
        {
            if (!TypeUtility.IsTestClass(typeInfo))
            {
                return(null);
            }

            ITestClassCommand command = null;

            if (TypeUtility.HasRunWith(typeInfo))
            {
                ITypeInfo runWithTypeInfo = TypeUtility.GetRunWith(typeInfo);
                if (runWithTypeInfo == null)
                {
                    return(null);
                }

                Type runWithCommandType = runWithTypeInfo.Type;
                if (runWithCommandType != null)
                {
                    command = (ITestClassCommand)Activator.CreateInstance(runWithCommandType);
                }
            }
            else if (TypeUtility.ContainsTestMethods(typeInfo))
            {
                command = new TestClassCommand();
            }

            if (command != null)
            {
                command.TypeUnderTest = typeInfo;
            }

            return(command);
        }
        public static IEnumerable <ITestCommand> Make(ITestClassCommand classCommand,
                                                      IMethodInfo method)
        {
            foreach (var testCommand in classCommand.EnumerateTestCommands(method))
            {
                ITestCommand wrappedCommand = testCommand;

                // Timeout (if they have one) -> Capture -> Timed -> Lifetime (if we need an instance) -> BeforeAfter

                wrappedCommand = new BeforeAfterCommand(wrappedCommand, method.MethodInfo);

                if (testCommand.ShouldCreateInstance)
                {
                    wrappedCommand = new LifetimeCommand(wrappedCommand, method);
                }

                wrappedCommand = new TimedCommand(wrappedCommand);
                wrappedCommand = new ExceptionCaptureCommand(wrappedCommand, method);

                if (wrappedCommand.Timeout > 0)
                {
                    wrappedCommand = new TimeoutCommand(wrappedCommand, wrappedCommand.Timeout, method);
                }

                yield return(wrappedCommand);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Execute the <see cref="ITestClassCommand"/>.
        /// </summary>
        /// <param name="testClassCommand">The test class command to execute</param>
        /// <param name="methods">The methods to execute; if null or empty, all methods will be executed</param>
        /// <param name="startCallback">The start run callback</param>
        /// <param name="resultCallback">The end run result callback</param>
        /// <returns>A <see cref="ClassResult"/> with the results of the test run</returns>
        public static ClassResult Execute(ITestClassCommand testClassCommand,
                                          List<IMethodInfo> methods,
                                          Predicate<ITestCommand> startCallback,
                                          Predicate<ITestResult> resultCallback)
        {
            Guard.ArgumentNotNull("testClassCommand", testClassCommand);

            if (methods == null)
                methods = new List<IMethodInfo>();

            if (methods.Count == 0)
                foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                    methods.Add(method);

            ClassResult classResult = new ClassResult(testClassCommand.TypeUnderTest.Type);
            Exception fixtureException = testClassCommand.ClassStart();
            bool @continue = true;

            if (fixtureException == null)
            {
                List<IMethodInfo> runList = new List<IMethodInfo>();
                foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                    runList.Add(method);

                while (@continue && runList.Count > 0)
                {
                    int idx = testClassCommand.ChooseNextTest(runList.AsReadOnly());
                    IMethodInfo method = runList[idx];

                    if (methods.Contains(method))
                        foreach (ITestCommand command in TestCommandFactory.Make(testClassCommand, method))
                        {
                            if (startCallback != null)
                                @continue = startCallback(command);

                            if (!@continue)
                                break;

                            MethodResult methodResult = command.Execute(testClassCommand.ObjectUnderTest);
                            classResult.Add(methodResult);

                            if (resultCallback != null)
                                @continue = resultCallback(methodResult);

                            if (!@continue)
                                break;
                        }

                    runList.RemoveAt(idx);
                }
            }

            classResult.SetException(testClassCommand.ClassFinish() ?? fixtureException);

            if (resultCallback != null)
                resultCallback(classResult);

            return classResult;
        }
        public void StubTestClassMakesTestClassCommand()
        {
            Type testClassType        = typeof(StubTestClass);
            ITestClassCommand command = TestClassCommandFactory.Make(testClassType);

            Assert.IsType <TestClassCommand>(command);
            Assert.Equal(typeof(StubTestClass), command.TypeUnderTest.Type);
        }
Esempio n. 9
0
        public TestMethod(ITestClassCommand testClassCommand, ITestCommand testCommand, IMethodInfo methodInfo)
        {
            this.testClassCommand = testClassCommand;
            this.testCommand      = testCommand;
            this.methodInfo       = methodInfo;

            HandleTraits();
        }
        private static void SetRandomizer(ITestClassCommand testClassCommand)
        {
            var classCommand = testClassCommand as TestClassCommand;

            if (classCommand != null)
            {
                classCommand.Randomizer = new NotVeryRandom();
            }
        }
Esempio n. 11
0
        public IEnumerable <IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var traceSetting        = ConfigurationManager.AppSettings["global.trace.setting"];
            var strDefaultTraceType = ConfigurationManager.AppSettings["global.trace.default"];

            Type defaultTraceType = null;

            if (!string.IsNullOrEmpty(strDefaultTraceType))
            {
                defaultTraceType = Type.GetType(strDefaultTraceType);
            }

            /// here's the process of deciding trace writer
            /// 1. if the NuwaTraceAttribute exists and the AlwaysOff property is true, then generate no run element
            /// 2. if the NuwaTraceAttribute exists and specifc a TraceWriter type, always use it.
            /// 3. if the NuwaTraceAttribute doesn't exist, check the Default Settings.
            /// 4. (incorrect path, but just case it is reached). if the NuwaTraceAttribute exists, and the
            ///    TraceWriter type is null

            var attr = ntcc.TypeUnderTest.GetFirstCustomAttribute <NuwaTraceAttribute>();

            if (attr != null)
            {
                if (attr.AlwaysOff)
                {
                    return(Enumerable.Empty <IRunElement>());
                }
                else if (attr.TraceWriter != null)
                {
                    return(new IRunElement[] { new TraceElement(attr.TraceWriter) });
                }
                else
                {
                    return(new IRunElement[] { new TraceElement(defaultTraceType) });
                }
            }
            else
            {
                if (traceSetting == "off")
                {
                    return(Enumerable.Empty <IRunElement>());
                }
                else if (traceSetting == "on")
                {
                    return(new IRunElement[] { new TraceElement(defaultTraceType) });
                }
                else
                {
                    // indicate traceSetting == "both"
                    return(new IRunElement[] { new TraceElement(null), new TraceElement(defaultTraceType) });
                }
            }
        }
 public IEnumerable<IRunElement> Perceive(ITestClassCommand ntcc)
 {
     var securityAttribute = ntcc.TypeUnderTest.GetFirstCustomAttribute<NuwaServerCertificateAttribute>();
     if (securityAttribute != null)
     {
         var elem = new SecurityOptionElement(securityAttribute.Certificate);
         return this.ToArray(elem);
     }
     else
     {
         return this.Empty();
     }
 }
Esempio n. 13
0
        public IEnumerable<IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var traceSetting = ConfigurationManager.AppSettings["global.trace.setting"];
            var strDefaultTraceType = ConfigurationManager.AppSettings["global.trace.default"];

            Type defaultTraceType = null;
            if (!string.IsNullOrEmpty(strDefaultTraceType))
            {
                defaultTraceType = Type.GetType(strDefaultTraceType);
            }

            /// here's the process of deciding trace writer
            /// 1. if the NuwaTraceAttribute exists and the AlwaysOff property is true, then generate no run element
            /// 2. if the NuwaTraceAttribute exists and specifc a TraceWriter type, always use it.
            /// 3. if the NuwaTraceAttribute doesn't exist, check the Default Settings.
            /// 4. (incorrect path, but just case it is reached). if the NuwaTraceAttribute exists, and the
            ///    TraceWriter type is null

            var attr = ntcc.TypeUnderTest.GetFirstCustomAttribute<NuwaTraceAttribute>();
            if (attr != null)
            {
                if (attr.AlwaysOff)
                {
                    return Enumerable.Empty<IRunElement>();
                }
                else if (attr.TraceWriter != null)
                {
                    return new IRunElement[] { new TraceElement(attr.TraceWriter) };
                }
                else
                {
                    return new IRunElement[] { new TraceElement(defaultTraceType) };
                }
            }
            else
            {
                if (traceSetting == "off")
                {
                    return Enumerable.Empty<IRunElement>();
                }
                else if (traceSetting == "on")
                {
                    return new IRunElement[] { new TraceElement(defaultTraceType) };
                }
                else
                {
                    // indicate traceSetting == "both"
                    return new IRunElement[] { new TraceElement(null), new TraceElement(defaultTraceType) };
                }
            }
        }
        public IEnumerable <IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var securityAttribute = ntcc.TypeUnderTest.GetFirstCustomAttribute <NuwaServerCertificateAttribute>();

            if (securityAttribute != null)
            {
                var elem = new SecurityOptionElement(securityAttribute.Certificate);
                return(this.ToArray(elem));
            }
            else
            {
                return(this.Empty());
            }
        }
        public IEnumerable<IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var attr = ntcc.TypeUnderTest.GetFirstCustomAttribute<NuwaHttpClientConfigurationAttribute>();

            if (attr != null)
            {
                yield return new ClientConfigurationElement()
                {
                    MessageLog = attr.MessageLog,
                    UseProxy = attr.UseProxy
                };
            }
            else
            {
                yield return new ClientConfigurationElement();
            }
        }
Esempio n. 16
0
        public IEnumerable <IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var attr = ntcc.TypeUnderTest.GetFirstCustomAttribute <NuwaHttpClientConfigurationAttribute>();

            if (attr != null)
            {
                yield return(new ClientConfigurationElement()
                {
                    MessageLog = attr.MessageLog,
                    UseProxy = attr.UseProxy
                });
            }
            else
            {
                yield return(new ClientConfigurationElement());
            }
        }
Esempio n. 17
0
            public RunTests(Executor executor, string _type, List <string> _methods, object _handler)
            {
                Guard.ArgumentNotNull("_type", _type);
                Guard.ArgumentNotNull("_methods", _methods);

                ExecutorCallback handler  = ExecutorCallback.Wrap(_handler);
                Type             realType = executor.assembly.GetType(_type);

                Guard.ArgumentValid("_type", "Type " + _type + " could not be found", realType != null);

                ITypeInfo         type             = Reflector.Wrap(realType);
                ITestClassCommand testClassCommand = TestClassCommandFactory.Make(type);

                List <IMethodInfo> methods = new List <IMethodInfo>();

                foreach (string _method in _methods)
                {
                    try
                    {
                        IMethodInfo method = type.GetMethod(_method);
                        Guard.ArgumentValid("_methods", "Could not find method " + _method + " in type " + _type, method != null);
                        methods.Add(method);
                    }
                    catch (AmbiguousMatchException)
                    {
                        throw new ArgumentException("Ambiguous method named " + _method + " in type " + _type);
                    }
                }

                if (testClassCommand == null)
                {
                    ClassResult result = new ClassResult(type.Type);
                    OnTestResult(result, handler);
                    return;
                }

                executor.RunOnSTAThreadWithPreservedWorkingDirectory(() =>
                                                                     TestClassCommandRunner.Execute(testClassCommand,
                                                                                                    methods,
                                                                                                    command => OnTestStart(command, handler),
                                                                                                    result => OnTestResult(result, handler)));
            }
Esempio n. 18
0
            public AssemblyTestCount(Executor executor, object _handler)
            {
                ExecutorCallback handler = ExecutorCallback.Wrap(_handler);
                int result = 0;

                foreach (Type type in executor.assembly.GetExportedTypes())
                {
                    ITestClassCommand testClassCommand = TestClassCommandFactory.Make(type);

                    if (testClassCommand != null)
                    {
                        foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                        {
                            result++;
                        }
                    }
                }

                handler.Notify(result.ToString());
            }
Esempio n. 19
0
        private static XunitTest CreateTypeTest(XunitTypeInfoAdapter typeInfo, ITestClassCommand testClassCommand)
        {
            XunitTest typeTest = new XunitTest(typeInfo.Target.Name, typeInfo.Target, typeInfo, null);

            typeTest.Kind = TestKinds.Fixture;

            foreach (XunitMethodInfoAdapter methodInfo in testClassCommand.EnumerateTestMethods())
            {
                typeTest.AddChild(CreateMethodTest(typeInfo, methodInfo));
            }

            // Add XML documentation.
            string xmlDocumentation = typeInfo.Target.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            return(typeTest);
        }
Esempio n. 20
0
        public RunFrameBuilder(ITestClassCommand testClass, IPerceiverList perceivers, AbstractRunFrameFactory runFrameFactory)
        {
            if (testClass == null)
            {
                throw new ArgumentNullException("testClass");
            }

            if (perceivers == null)
            {
                throw new ArgumentNullException("perceivers");
            }

            if (runFrameFactory == null)
            {
                throw new ArgumentNullException("runFrameFactory");
            }

            _perceivers      = perceivers;
            _testClass       = testClass;
            _runFrameFactory = runFrameFactory;
        }
Esempio n. 21
0
        public RunFrameBuilder(ITestClassCommand testClass, IPerceiverList perceivers, AbstractRunFrameFactory runFrameFactory)
        {
            if (testClass == null)
            {
                throw new ArgumentNullException("testClass");
            }

            if (perceivers == null)
            {
                throw new ArgumentNullException("perceivers");
            }

            if (runFrameFactory == null)
            {
                throw new ArgumentNullException("runFrameFactory");
            }

            _perceivers = perceivers;
            _testClass = testClass;
            _runFrameFactory = runFrameFactory;
        }
        public static IEnumerable <ITestCommand> Make(ITestClassCommand classCommand, IMethodInfo method)
        {
            foreach (var testCommand in classCommand.EnumerateTestCommands(method))
            {
                var wrappedCommand = testCommand;

                wrappedCommand = new BeforeAfterCommand(wrappedCommand, method.MethodInfo);

                if (testCommand.ShouldCreateInstance)
                {
                    wrappedCommand = new LifetimeCommand(wrappedCommand, method);
                }

                wrappedCommand = new TimedCommand(wrappedCommand);
                wrappedCommand = new ExceptionInterceptingCommand(wrappedCommand, method);
                wrappedCommand = new ExceptionAndOutputCaptureCommand(wrappedCommand, method);

                // Note that we don't use a TimeoutCommand - we'll let the Silverlight framework handle that

                yield return(wrappedCommand);
            }
        }
        public void AllStagesOfTestLifetimeExistOnSameThread()
        {
            Type testClassType        = typeof(ThreadLifetimeSpy);
            ITestClassCommand command = TestClassCommandFactory.Make(testClassType);

            ThreadFixtureSpy.Reset();
            ThreadLifetimeSpy.Reset();

            TestClassCommandRunner.Execute(command, null, null, null);

            // The fixture data may take place on a different thread from the test, but that's
            // an acceptable limitation, as the fixture should have no knowledge of the test
            // class that it's attached to. This means that fixtures cannot use thread local
            // storage, but there's no reason for them to need that anyway, as their own data
            // remains the same throughout all the tests for a given class.

            Assert.NotEqual(-1, ThreadFixtureSpy.CtorThreadId);
            Assert.Equal(ThreadFixtureSpy.CtorThreadId, ThreadFixtureSpy.DisposeThreadId);

            Assert.NotEqual(-1, ThreadLifetimeSpy.CtorThreadId);
            Assert.Equal(ThreadLifetimeSpy.CtorThreadId, ThreadLifetimeSpy.DisposeThreadId);
            Assert.Equal(ThreadLifetimeSpy.CtorThreadId, ThreadLifetimeSpy.TestThreadId);
        }
Esempio n. 24
0
        /// <summary>
        /// Make instances of <see cref="ITestCommand"/> objects for the given class and method.
        /// </summary>
        /// <param name="classCommand">The class command</param>
        /// <param name="method">The method under test</param>
        /// <returns>The set of <see cref="ITestCommand"/> objects</returns>
        public static IEnumerable<ITestCommand> Make(ITestClassCommand classCommand,
            IMethodInfo method)
        {
            foreach (var testCommand in classCommand.EnumerateTestCommands(method))
            {
                ITestCommand wrappedCommand = testCommand;

                // Timeout (if they have one) -> Capture -> Timed -> Lifetime (if we need an instance) -> BeforeAfter

                wrappedCommand = new BeforeAfterCommand(wrappedCommand, method.MethodInfo);

                if (testCommand.ShouldCreateInstance)
                    wrappedCommand = new LifetimeCommand(wrappedCommand, method);

                wrappedCommand = new TimedCommand(wrappedCommand);
                wrappedCommand = new ExceptionAndOutputCaptureCommand(wrappedCommand, method);

                if (wrappedCommand.Timeout > 0)
                    wrappedCommand = new TimeoutCommand(wrappedCommand, wrappedCommand.Timeout, method);

                yield return wrappedCommand;
            }
        }
Esempio n. 25
0
        public void TimeoutCommandMustUseReplacementBeginInvoke()
        {
            Type testClassType        = typeof(TestClassCommandFactoryTests.ThreadLifetimeSpy);
            ITestClassCommand command = TestClassCommandFactory.Make(testClassType);

            TestClassCommandFactoryTests.ThreadFixtureSpy.Reset();
            TestClassCommandFactoryTests.ThreadLifetimeSpy.Reset();

            try
            {
                TestClassCommandRunner.Execute(command, null, null, null);
            }
            catch (NotSupportedException e)
            {
                // If this test fails, you need to modify TimeoutCommand.Execute to use
                // working versions of delegate's BeginInvoke/EndInvoke. You should replace
                // with WorkingBeginInvoke and WorkingEndInvoke. WorkingEndInvoke's return
                // value will require casting to MethodResult.
                // The asynchronous methods on Invoke are compiler generated, and supposed
                // to be implemented by the runtime. Silverlight doesn't implement them.
                // I don't really know why.
                throw new AsyncDelegateMethodsNotSupportedException("TimeoutCommand.Execute", e);
            }
        }
Esempio n. 26
0
        public IEnumerable <IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var descriptor = new TestTypeDescriptor(ntcc.TypeUnderTest);

            var attrs = new HashSet <HostType>(
                ntcc.TypeUnderTest.GetCustomAttributes <NwHostAttribute>().Select(a => a.HostType));

            if (attrs.Count() == 0)
            {
                var defaultHostTypesSetting = NuwaGlobalConfiguration.DefaultHostTypes;
                if (!string.IsNullOrEmpty(defaultHostTypesSetting))
                {
                    var defaultHosts = new List <HostType>();
                    foreach (var type in defaultHostTypesSetting.Split(','))
                    {
                        defaultHosts.Add((HostType)Enum.Parse(typeof(HostType), type, true));
                    }
                    _defaultHosts = defaultHosts;
                }

                // fall back to default setting
                foreach (var host in _defaultHosts)
                {
                    attrs.Add(host);
                }
            }

            var retvals = new List <IRunElement>();

            if (attrs.Contains(HostType.WcfSelf))
            {
                var host = new WcfSelfHostElement(descriptor, _route, _ports);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IIS))
            {
                var host = new IISHostElement(descriptor, _route, _dirProvider);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IISExpress))
            {
                var host = new IISExpressHostElement(descriptor, _route, _dirProvider);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.AzureWebsite))
            {
                var host = new AzureWebsiteHostElement(descriptor, _route, _dirProvider);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.KatanaSelf))
            {
                var host = new KatanaSelfHostElement(descriptor, _route, _ports);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IISKatana))
            {
                var host = new IISHostElement(descriptor, _route, _dirProvider);
                host.EnableDefaultOwinWebApiConfiguration = true;
                host.EnableGlobalAsax = false;
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IISExpressKatana))
            {
                var host = new IISExpressHostElement(descriptor, _route, _dirProvider);
                host.EnableDefaultOwinWebApiConfiguration = true;
                host.EnableGlobalAsax = false;
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.AzureWebsiteKatana))
            {
                var host = new AzureWebsiteHostElement(descriptor, _route, _dirProvider);
                host.EnableDefaultOwinWebApiConfiguration = true;
                host.EnableGlobalAsax = false;
                retvals.Add(host);
            }

            return(retvals);
        }
 /// <summary>
 /// Create a new instance of the <see cref="DelegatingTestClassCommand"/> class.
 /// </summary>
 /// <param name="proxy">The inner command to delegate to.</param>
 public DelegatingTestClassCommand(ITestClassCommand proxy)
 {
     _proxy = proxy;
 }
Esempio n. 28
0
        private static XunitTest CreateTypeTest(XunitTypeInfoAdapter typeInfo, ITestClassCommand testClassCommand)
        {
            XunitTest typeTest = new XunitTest(typeInfo.Target.Name, typeInfo.Target, typeInfo, null);
            typeTest.Kind = TestKinds.Fixture;

            foreach (XunitMethodInfoAdapter methodInfo in testClassCommand.EnumerateTestMethods())
                typeTest.AddChild(CreateMethodTest(typeInfo, methodInfo));

            // Add XML documentation.
            string xmlDocumentation = typeInfo.Target.GetXmlDocumentation();
            if (xmlDocumentation != null)
                typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);

            return typeTest;
        }
        public static ClassResult Execute(ITestClassCommand testClassCommand,
                                          List <IMethodInfo> methods,
                                          Predicate <ITestCommand> startCallback,
                                          Predicate <ITestResult> resultCallback)
        {
            if (methods == null)
            {
                methods = new List <IMethodInfo>();
            }

            if (methods.Count == 0)
            {
                foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                {
                    methods.Add(method);
                }
            }

            ClassResult classResult      = new ClassResult(testClassCommand.TypeUnderTest.Type);
            Exception   fixtureException = testClassCommand.ClassStart();
            bool        @continue        = true;

            if (fixtureException == null)
            {
                List <IMethodInfo> runList = new List <IMethodInfo>();
                foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                {
                    runList.Add(method);
                }

                while (@continue && runList.Count > 0)
                {
                    int         idx    = testClassCommand.ChooseNextTest(runList.AsReadOnly());
                    IMethodInfo method = runList[idx];

                    if (methods.Contains(method))
                    {
                        foreach (ITestCommand command in TestCommandFactory.Make(testClassCommand, method))
                        {
                            if (startCallback != null)
                            {
                                @continue = startCallback(command);
                            }

                            if (!@continue)
                            {
                                break;
                            }

                            MethodResult methodResult = command.Execute(testClassCommand.ObjectUnderTest);
                            classResult.Add(methodResult);

                            if (resultCallback != null)
                            {
                                @continue = resultCallback(methodResult);
                            }

                            if (!@continue)
                            {
                                break;
                            }
                        }
                    }

                    runList.RemoveAt(idx);
                }
            }

            classResult.SetException(testClassCommand.ClassFinish() ?? fixtureException);

            if (resultCallback != null)
            {
                resultCallback(classResult);
            }

            return(classResult);
        }
Esempio n. 30
0
            public EnumerateTests(Executor executor, object _handler)
            {
                ExecutorCallback handler = ExecutorCallback.Wrap(_handler);

                XmlDocument doc = new XmlDocument();

                doc.LoadXml("<dummy/>");

                XmlNode assemblyNode = XmlUtility.AddElement(doc.ChildNodes[0], "assembly");

                XmlUtility.AddAttribute(assemblyNode, "name", executor.assemblyFilename);

                foreach (Type type in executor.assembly.GetExportedTypes())
                {
                    ITestClassCommand testClassCommand = TestClassCommandFactory.Make(type);

                    if (testClassCommand != null)
                    {
                        string typeName = type.FullName;

                        XmlNode classNode = XmlUtility.AddElement(assemblyNode, "class");
                        XmlUtility.AddAttribute(classNode, "name", typeName);

                        foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                        {
                            string methodName  = method.Name;
                            string displayName = null;

                            foreach (IAttributeInfo attr in method.GetCustomAttributes(typeof(FactAttribute)))
                            {
                                displayName = attr.GetPropertyValue <string>("Name");
                            }

                            XmlNode methodNode = XmlUtility.AddElement(classNode, "method");
                            XmlUtility.AddAttribute(methodNode, "name", displayName ?? typeName + "." + methodName);
                            XmlUtility.AddAttribute(methodNode, "type", typeName);
                            XmlUtility.AddAttribute(methodNode, "method", methodName);

                            string skipReason = MethodUtility.GetSkipReason(method);
                            if (skipReason != null)
                            {
                                XmlUtility.AddAttribute(methodNode, "skip", skipReason);
                            }

                            var traits = MethodUtility.GetTraits(method);
                            if (traits.Count > 0)
                            {
                                XmlNode traitsNode = XmlUtility.AddElement(methodNode, "traits");

                                traits.ForEach((name, value) =>
                                {
                                    XmlNode traitNode = XmlUtility.AddElement(traitsNode, "trait");
                                    XmlUtility.AddAttribute(traitNode, "name", name);
                                    XmlUtility.AddAttribute(traitNode, "value", value);
                                });
                            }
                        }
                    }
                }

                handler.Notify(assemblyNode.OuterXml);
            }
        public void RunWithForInvalidTestClassCommandReturnsNull()
        {
            ITestClassCommand command = TestClassCommandFactory.Make(typeof(MyInvalidRunWithTestClass));

            Assert.Null(command);
        }
        public void AbstractTestClassReturnsNull()
        {
            ITestClassCommand command = TestClassCommandFactory.Make(typeof(AbstractTestClass));

            Assert.Null(command);
        }
 private static void SetRandomizer(ITestClassCommand testClassCommand)
 {
     var classCommand = testClassCommand as TestClassCommand;
     if (classCommand != null)
         classCommand.Randomizer = new NotVeryRandom();
 }
Esempio n. 34
0
        public IEnumerable<IRunElement> Perceive(ITestClassCommand ntcc)
        {
            var descriptor = new TestTypeDescriptor(ntcc.TypeUnderTest);

            var attrs = new HashSet<HostType>(
                ntcc.TypeUnderTest.GetCustomAttributes<NwHostAttribute>().Select(a => a.HostType));

            if (attrs.Count() == 0)
            {
                var defaultHostTypesSetting = NuwaGlobalConfiguration.DefaultHostTypes;
                if (!string.IsNullOrEmpty(defaultHostTypesSetting))
                {
                    var defaultHosts = new List<HostType>();
                    foreach (var type in defaultHostTypesSetting.Split(','))
                    {
                        defaultHosts.Add((HostType)Enum.Parse(typeof(HostType), type, true));
                    }
                    _defaultHosts = defaultHosts;
                }

                // fall back to default setting
                foreach (var host in _defaultHosts)
                {
                    attrs.Add(host);
                }
            }

            var retvals = new List<IRunElement>();

            if (attrs.Contains(HostType.WcfSelf))
            {
                var host = new WcfSelfHostElement(descriptor, _route, _ports);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IIS))
            {
                var host = new IISHostElement(descriptor, _route, _dirProvider);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IISExpress))
            {
                var host = new IISExpressHostElement(descriptor, _route, _dirProvider);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.AzureWebsite))
            {
                var host = new AzureWebsiteHostElement(descriptor, _route, _dirProvider);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.KatanaSelf))
            {
                var host = new KatanaSelfHostElement(descriptor, _route, _ports);
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IISKatana))
            {
                var host = new IISHostElement(descriptor, _route, _dirProvider);
                host.EnableDefaultOwinWebApiConfiguration = true;
                host.EnableGlobalAsax = false;
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.IISExpressKatana))
            {
                var host = new IISExpressHostElement(descriptor, _route, _dirProvider);
                host.EnableDefaultOwinWebApiConfiguration = true;
                host.EnableGlobalAsax = false;
                retvals.Add(host);
            }

            if (attrs.Contains(HostType.AzureWebsiteKatana))
            {
                var host = new AzureWebsiteHostElement(descriptor, _route, _dirProvider);
                host.EnableDefaultOwinWebApiConfiguration = true;
                host.EnableGlobalAsax = false;
                retvals.Add(host);
            }

            return retvals;
        }
 public TestClassCommandTypeAdapter()
 {
     testClassCommand = TestClassCommandFactory.Make(typeof(TClassUnderTest));
 }
 /// <summary>
 /// Create a new instance of the <see cref="DelegatingTestClassCommand"/> class.
 /// </summary>
 /// <param name="proxy">The inner command to delegate to.</param>
 public DelegatingTestClassCommand(ITestClassCommand proxy)
 {
     _proxy = proxy;
 }
Esempio n. 37
0
 public static NuwaFrameworkAttribute GetNuwaFrameworkAttr(ITestClassCommand cmd)
 {
     return cmd.TypeUnderTest.GetFirstCustomAttribute<NuwaFrameworkAttribute>();
 }
Esempio n. 38
0
 public static NuwaFrameworkAttribute GetNuwaFrameworkAttr(ITestClassCommand cmd)
 {
     return(cmd.TypeUnderTest.GetFirstCustomAttribute <NuwaFrameworkAttribute>());
 }