예제 #1
0
        /// <summary>
        /// Helper to enqueue a new method dispatcher.
        /// </summary>
        /// <param name="method">The method reflection object.</param>
        private void EnqueueMethodDispatcher(MethodInfo method)
        {
            object o = ClassInstances.GetInstance(method.ReflectedType);

            if (o == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Object of type {0} could not be instantiated.", method.ReflectedType.ToString()));
            }

            // CustomTest was known in the first release as "SilverlightTest"
            // These are tests that are not compatible with the full framework
            // as the properties, methods and other features exposed are custom
            // to this harness.
            CustomFrameworkUnitTest customTest = o as CustomFrameworkUnitTest;

            if (customTest != null)
            {
                TestHarness.PrepareCustomTestInstance(customTest);
            }
            IWorkItem task = new UnitTestMethodContainer(TestHarness, o, method, null, TestGranularity.TestScenario);

            Enqueue(task);
        }
예제 #2
0
        /// <summary>
        /// First invoke, plan for the method's execution.
        /// </summary>
        protected override void FirstInvoke()
        {
            // [Ignore]
            if (Provider.HasCapability(UnitTestProviderCapabilities.MethodCanIgnore) && _testMethod.Ignore)
            {
                LogWriter.Ignore(TestGranularity.TestScenario, _testMethod.Name, _testMethod);
                return;
            }

            _testMethod.DecorateInstance(_instance);
            _testMethod.WriteLine += delegate(object sender, StringEventArgs e)
            {
                LogWriter.DebugWriteLine(e.Value);
            };

            // Log Start
            Enqueue(LogStartMessage);

            // [Bug] attributes that are not fixed modify test method logic
            bool known_issue = false;

            foreach (BugAttribute bug in ReflectionUtility.GetAttributes(_testMethod.Method, typeof(BugAttribute)))
            {
                if (bug == null)
                {
                    continue;
                }

                if (!bug.Fixed)
                {
                    if (bug.Platforms != null)
                    {
                        foreach (PlatformID id in bug.Platforms)
                        {
                            if (id == Environment.OSVersion.Platform)
                            {
                                _bugAttributePresent = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        _bugAttributePresent = true;
                    }

#if SILVERLIGHT
                    if (_bugAttributePresent && bug.RuntimeVersion != 0)
                    {
                        if (bug.RuntimeVersion != Int32.Parse(Deployment.Current.RuntimeVersion.Split('.')[0]))
                        {
                            _bugAttributePresent = false;
                        }
                    }
#endif

                    if (_bugAttributePresent)
                    {
                        Enqueue(() => LogWriter.KnownIssue(bug.Description));
                        break;
                    }
                }
            }

            // [TestInitialize]
            if (_testClass.TestInitializeMethod != null)
            {
                EnqueueMethodDispatcher(_testClass.TestInitializeMethod);
            }

            // Track the approximate starting time - actual start time is >= 1 dispatcher interval
            Enqueue(() => _started = DateTime.Now);

            // [TestMethod] - actual test scenario
            UnitTestMethodContainer mthd = new UnitTestMethodContainer(TestHarness, _instance, _testMethod.Method, _testMethod, TestGranularity.TestScenario);
            mthd.UnhandledException += new EventHandler <UnhandledExceptionEventArgs>(UnhandledMethodException);
            mthd.Complete           += new EventHandler(CompleteMethod);
            Enqueue(mthd);

            // [TestCleanup]
            if (_testClass.TestCleanupMethod != null)
            {
                EnqueueMethodDispatcher(_testClass.TestCleanupMethod);
            }

            // Log End
            Enqueue(LogEndMessage);

            // Silverlight-specific calls
            FirstInvokeOptional();
        }
예제 #3
0
        /// <summary>
        /// Create a new method container to enclose a reflected method for execution.
        /// </summary>
        /// <param name="method">The method reflection object.</param>
        private void EnqueueMethodDispatcher(MethodInfo method)
        {
            IWorkItem task = new UnitTestMethodContainer(TestHarness, _instance, method, null, TestGranularity.TestScenario);

            Enqueue(task);
        }