/// <summary>
 /// Constructor for a test method manager, which handles executing a single test method 
 /// for a unit test provider.
 /// </summary>
 /// <param name="testHarness">The unit test harness object.</param>
 /// <param name="testClass">The test class metadata object.</param>
 /// <param name="testMethod">The test method metadata object.</param>
 /// <param name="instance">The test class instance.</param>
 /// <param name="provider">The unit test provider.</param>
 public TestMethodManager(UnitTestHarness testHarness, ITestClass testClass, ITestMethod testMethod, object instance, IUnitTestProvider provider)
     : base(testHarness, provider)
 {
     _testClass = testClass;
     _testMethod = testMethod;
     _instance = instance;
 }
Exemple #2
0
 /// <summary>
 /// Initializes dispatcher-stack attaching method container work item.
 /// </summary>
 /// <param name="testHarness">Test harness.</param>
 /// <param name="instance">Test instance.</param>
 /// <param name="method">Method reflection object.</param>
 /// <param name="testMethod">Test method metadata.</param>
 /// <param name="granularity">Granularity of test.</param>
 public UnitTestMethodContainer(ITestHarness testHarness, object instance, MethodInfo method, ITestMethod testMethod, TestGranularity granularity)
     : base(instance, method, testMethod)
 {
     _granularity = granularity;
     _harness = testHarness as UnitTestHarness;
     _testMethod = testMethod;
 }
Exemple #3
0
 /// <summary>
 /// Create a new assembly manager, takes in the harness, provider 
 /// reference and actual IAssembly object.
 /// </summary>
 /// <param name="runFilter">The test run filter object.</param>
 /// <param name="testHarness">Harness object.</param>
 /// <param name="provider">The unit test metadata provider.</param>
 /// <param name="testAssembly">The test assembly metadata object.</param>
 public AssemblyManager(TestRunFilter runFilter, UnitTestHarness testHarness, IUnitTestProvider provider, IAssembly testAssembly) : base(testHarness, provider)
 {
     _filter = runFilter;
     _assembly = testAssembly;
     _testClasses = new CompositeWorkItem();
     ClassInstances = new TestClassInstanceDictionary();
 }
Exemple #4
0
 /// <summary>
 /// A container type that handles an entire test class throughout the 
 /// test run.
 /// </summary>
 /// <param name="filter">Test run filter object.</param>
 /// <param name="testHarness">The unit test harness.</param>
 /// <param name="testClass">The test class metadata interface.</param>
 /// <param name="instance">The object instance.</param>
 /// <param name="provider">The unit test provider.</param>
 public TestClassManager(TestRunFilter filter, UnitTestHarness testHarness, ITestClass testClass, object instance, IUnitTestProvider provider) : base(testHarness, provider)
 {
     _filter = filter;
     _testClass = testClass;
     _testExecutionQueue = new CompositeWorkItem();
     _instance = instance;
 }
Exemple #5
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var harness  = new UnitTestHarness();
            var settings = new UnitTestSettings();

            settings.TestHarness = harness;
            harness.Settings     = settings;
            harness.Initialize();

            harness.TestRunStarting += (senderx, ex) =>
            {
                var provider = new TestProvider();
                var filter   = new TagTestRunFilter(settings, harness, settings.TagExpression);

                var features = FeatureFactory.GetFeatures(typeof(App).Assembly);
                foreach (var feature in features)
                {
                    provider.RegisterFeature(feature);
                    var ass = provider.GetUnitTestAssembly(harness, feature.Assembly);
                    harness.EnqueueTestAssembly(ass, filter);
                }
            };

            this.RootVisual = UnitTestSystem.CreateTestPage(settings);
        }
        public static void RunTests(Application app)
        {
            UnitTestSettings settings = UnitTestSystem.CreateDefaultSettings();

            settings.StartRunImmediately     = SuppressTagExpressionEditor();
            settings.ShowTagExpressionEditor = !SuppressTagExpressionEditor();
            settings.TestHarness             = new AgTestHarness();
            TestHarness = (UnitTestHarness)settings.TestHarness;
            settings.TestAssemblies.Clear();
            settings.TestAssemblies.Add(Assembly.GetCallingAssembly());
            if (IsGUI())
            {
                string categories = (string)HtmlPage.Window.Eval("window.external.GetIgnoreCategories();");
                IgnoredCategories.AddRange(categories.Split(';'));
                settings.LogProviders.Clear();
                settings.LogProviders.Add(new SilverlightTestGUILog());
                TestHarness.TestHarnessCompleted += TestHarnessCompleted;
            }
            else
            {
                IgnoredCategories.Add("TODO");
            }

            UnitTestProviders.Providers.Add(new BaseUnitTestProvider());
            app.RootVisual = CreateRootVisual(settings);
        }
Exemple #7
0
        public void Run(UnitTestSettings settings)
        {
            // Avoid having the Run method called twice
            if (_harness != null)
            {
                return;
            }

            _harness = settings.TestHarness;
            if (_harness == null)
            {
                throw new InvalidOperationException(Properties.UnitTestMessage.UnitTestSystem_Run_NoTestHarnessInSettings);
            }

            if (settings.TestService == null && !settings.TestServiceSetterCalled)
            {
                SetTestService(settings);
            }

            _harness.Settings              = settings;
            _harness.TestHarnessCompleted += (sender, args) => OnTestHarnessCompleted(args);

            if (settings.StartRunImmediately)
            {
                _harness.Run();
            }
        }
Exemple #8
0
		public static UIElement CreateTestPage (Application app)
		{
			settings = new UnitTestSettings ();
			
			app.UnhandledException += Application_UnhandledException;
			
			moonlog = new MoonLogProvider ();
			harness = new Microsoft.Silverlight.Testing.UnitTesting.Harness.UnitTestHarness ();
			settings.TestHarness = harness; 
			settings.TestAssemblies.Add (app.GetType ().Assembly);
			UnitTestSystem.PrepareCustomLogProviders (settings);
			settings.LogProviders.Add (moonlog);
			settings.RuntimeVersion = Int32.Parse (Deployment.Current.RuntimeVersion.Split('.')[0]);
            // Silverlight thinks HtmlPage.Document.DocumentUri.Query is empty
            // so lets just manually parse instead. This allows tagging to work on SL.
			if (HtmlPage.Document.DocumentUri.OriginalString.IndexOf ('?') > 0) {
				settings.TagExpression = HtmlPage.Document.DocumentUri.OriginalString.Substring (HtmlPage.Document.DocumentUri.OriginalString.IndexOf ('?') + 1);
				if (settings.TagExpression.IndexOf ('#') > 0)
					settings.TagExpression = settings.TagExpression.Remove (settings.TagExpression.IndexOf ('#'));
			}
			test_page = UnitTestSystem.CreateTestPage (settings);
			
			settings.TestHarness.TestHarnessCompleted += new EventHandler<TestHarnessCompletedEventArgs> (Harness_Completed);
			
			return test_page;
		}
Exemple #9
0
 public IAssembly GetUnitTestAssembly(UnitTestHarness testHarness, Assembly assemblyReference)
 {
     if (!this._assemblyCache.ContainsKey(assemblyReference))
     {
         this._assemblyCache[assemblyReference] = new BaseTestAssembly(this, testHarness, assemblyReference);
     }
     return(this._assemblyCache[assemblyReference]);
 }
Exemple #10
0
 /// <summary>
 /// Creates a new unit test assembly wrapper.
 /// </summary>
 /// <param name="provider">Unit test metadata provider.</param>
 /// <param name="unitTestHarness">A reference to the unit test harness.</param>
 /// <param name="assembly">Assembly reflection object.</param>
 public UnitTestFrameworkAssembly(IUnitTestProvider provider, UnitTestHarness unitTestHarness, Assembly assembly)
 {
     _provider = provider;
     _harness  = unitTestHarness;
     _assembly = assembly;
     _init     = new LazyAssemblyMethodInfo(_assembly, ProviderAttributes.AssemblyInitialize);
     _cleanup  = new LazyAssemblyMethodInfo(_assembly, ProviderAttributes.AssemblyCleanup);
 }
Exemple #11
0
 public BaseTestAssembly(IUnitTestProvider provider, UnitTestHarness testHarness, Assembly assembly)
 {
     this.provider    = provider;
     this.testHarness = testHarness;
     this.assembly    = assembly;
     this.init        = new LazyAssemblyMethodInfo(this.assembly, typeof(AssemblyInitializeAttribute));
     this.cleanup     = new LazyAssemblyMethodInfo(this.assembly, typeof(AssemblyCleanupAttribute));
 }
 public UnitTestFrameworkAssembly(IUnitTestProvider provider, UnitTestHarness unitTestHarness, Assembly assembly)
 {
     this.provider  = provider;
     harness        = unitTestHarness;
     this.assembly  = assembly;
     lazyMethodInfo = new LazyAssemblyMethodInfo(this.assembly, ProviderAttributes.AssemblyInitialize);
     cleanup        = new LazyAssemblyMethodInfo(this.assembly, ProviderAttributes.AssemblyCleanup);
 }
        /// <summary>
        /// Initializes a new instance of the DataManager type.
        /// </summary>
        /// <param name="harness">The unit test harness instance.</param>
        private DataManager(UnitTestHarness harness)
        {
            _d = new TestRunData(harness);
            _h = harness;

            _assemblyData = new Dictionary <IAssembly, TestAssemblyData>(2);
            _classData    = new Dictionary <ITestClass, TestClassData>(50);
            _methodData   = new Dictionary <ITestMethod, TestMethodData>(300);
        }
Exemple #14
0
        public IAssembly GetUnitTestAssembly(UnitTestHarness testHarness, Assembly assemblyReference)
        {
            if (assemblyCache.ContainsKey(assemblyReference))
            {
                return(assemblyCache[assemblyReference]);
            }

            assemblyCache[assemblyReference] = new UnitTestFrameworkAssembly(this, testHarness, assemblyReference);
            return(assemblyCache[assemblyReference]);
        }
Exemple #15
0
 public TestAssembly(
     IUnitTestProvider provider,
     UnitTestHarness testHarness,
     Feature feature)
 {
     _provider    = provider;
     _testHarness = testHarness;
     _feature     = feature;
     _classes     = new List <ITestClass>();
     _classes.Add(new TestClass(this, _feature));
 }
 /// <summary>
 /// Initializes a new instance of the test run results.
 /// </summary>
 /// <param name="unitTestHarness">The unit test harness.</param>
 public TestRunData(UnitTestHarness unitTestHarness)
 {
     Passed      = true;
     _assemblies = new ObservableCollection <TestAssemblyData>();
     _harness    = unitTestHarness;
     _harness.TestAssemblyStarting  += (x, xe) => IsRunning = true;
     _harness.TestAssemblyCompleted += (x, xe) =>
     {
         IsRunning = false;
         NotifyPropertyChanged("PassedAndComplete");
     };
     _harness.IsDispatcherRunningChanged += (x, xe) => NotifyPropertyChanged("IsDispatcherRunning");
 }
Exemple #17
0
        void TestRunCompletedCallback(object sender, TestHarnessCompletedEventArgs e)
        {
            int             testsPassed       = 0;
            int             testsFailed       = 0;
            int             testsInconclusive = 0;
            UnitTestHarness testHarness       = sender as UnitTestHarness;

            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = isoStore.OpenFile("pubnublog.txt", FileMode.OpenOrCreate))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        foreach (ScenarioResult result in testHarness.Results)
                        {
                            writer.WriteLine(result.ToString());
                            System.Diagnostics.Debug.WriteLine(result.ToString());
                            switch (result.Result)
                            {
                            case TestOutcome.Passed:
                            case TestOutcome.Completed:
                                testsPassed++;
                                break;

                            case TestOutcome.Inconclusive:
                                testsInconclusive++;
                                break;

                            default:
                                testsFailed++;
                                // must be a failure of some kind
                                // perform some outputting
                                break;
                            }
                        }
                        writer.WriteLine("Total Tests = " + testHarness.Results.Count);
                        writer.WriteLine("Tests Passed = " + testsPassed);
                        writer.WriteLine("Tests Failed = " + testsFailed);
                        writer.WriteLine("Tests Inconclusive = " + testsInconclusive);

                        System.Diagnostics.Debug.WriteLine("Total Tests = " + testHarness.Results.Count);
                        System.Diagnostics.Debug.WriteLine("Tests Passed = " + testsPassed);
                        System.Diagnostics.Debug.WriteLine("Tests Failed = " + testsFailed);
                        System.Diagnostics.Debug.WriteLine("Tests Inconclusive = " + testsInconclusive);

                        writer.Close();
                    }
                    stream.Close();
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// Unit test harness starting message.
        /// </summary>
        /// <param name="l">Log message object.</param>
        private void UnitTestHarnessStart(LogMessage l)
        {
            _unitTestHarness = (UnitTestHarness)l[UnitTestLogDecorator.UnitTestHarness];
            string displayName           = "Unit Test Run for ";
            HtmlContainerControl harness = new HtmlDiv();

            harness.InnerHtml                  = displayName;
            harness.Padding.All                = 3;
            harness.BackgroundColor            = Color.DarkGray;
            harness.ForegroundColor            = Color.VeryLightGray;
            _mostRecentHarness                 = new HtmlSpan();
            _mostRecentHarness.ForegroundColor = Color.White;
            harness.Controls.Add(_mostRecentHarness);
            LogContainer.Controls.Add(harness);
        }
Exemple #19
0
            /// <summary>
            /// Adds the retry action link.
            /// </summary>
            /// <param name="actions">The action container.</param>
            private void AddRetryAction(HtmlControl actions)
            {
                HtmlAnchor rerun = new HtmlAnchor(
                    "Retry this test",
                    delegate(object sender, HtmlEventArgs args)
                {
                    RetryTestRunFilter retryFilter = new RetryTestRunFilter(Inspector.Result.TestClass, Inspector.Result.TestMethod);
                    UnitTestHarness ut             = UnitTestHarness;
                    if (ut != null)
                    {
                        ut.RestartRunDispatcher();
                        ut.EnqueueTestAssembly(Inspector.Result.TestClass.Assembly, retryFilter);
                    }
                });

                StyleActionLink(rerun);
                actions.Controls.Add(rerun);
            }
Exemple #20
0
        public static UIElement CreateTestPage(Application app)
        {
            settings = new UnitTestSettings();

            app.UnhandledException += Application_UnhandledException;

            moonlog = new MoonLogProvider();
            harness = new Microsoft.Silverlight.Testing.UnitTesting.Harness.UnitTestHarness();
            settings.TestHarness = harness;
            settings.TestAssemblies.Add(app.GetType().Assembly);
            UnitTestSystem.PrepareCustomLogProviders(settings);
            settings.LogProviders.Add(moonlog);
            settings.RuntimeVersion = Int32.Parse(Deployment.Current.RuntimeVersion.Split('.')[0]);
            // Silverlight thinks HtmlPage.Document.DocumentUri.Query is empty
            // so lets just manually parse instead. This allows tagging to work on SL.
            if (HtmlPage.Document.DocumentUri.OriginalString.IndexOf('?') > 0)
            {
                settings.TagExpression = HtmlPage.Document.DocumentUri.OriginalString.Substring(HtmlPage.Document.DocumentUri.OriginalString.IndexOf('?') + 1);
                if (settings.TagExpression.IndexOf('#') > 0)
                {
                    settings.TagExpression = settings.TagExpression.Remove(settings.TagExpression.IndexOf('#'));
                }

                List <string> exps = new List <string> (settings.TagExpression.Split('&'));
                for (int i = exps.Count - 1; i >= 0; i--)
                {
                    if (exps [i].StartsWith("version=") || exps [i].StartsWith("bot_mode="))
                    {
                        exps.RemoveAt(i);
                    }
                }
                settings.TagExpression = string.Join("&", exps.ToArray());
            }
            test_page = UnitTestSystem.CreateTestPage(settings);

            settings.TestHarness.TestHarnessCompleted += new EventHandler <TestHarnessCompletedEventArgs> (Harness_Completed);

            return(test_page);
        }
 public IAssembly GetUnitTestAssembly(UnitTestHarness testHarness, Assembly assemblyReference)
 {
     return(new TestAssembly(testHarness, assemblyReference, this));
 }
Exemple #22
0
 public void WriteLogFile(UnitTestHarness harness)
 {
     _writer.Finished = DateTime.Now;
     harness.WriteLogFile(TestResultsFileName, _writer.GetXmlAsString());
 }
		/// <summary>
		/// Creates a new unit test assembly wrapper.
		/// </summary>
		/// <param name="provider">Unit test metadata provider.</param>
		/// <param name="unitTestHarness">A reference to the unit test harness.</param>
		/// <param name="assembly">Assembly reflection object.</param>
        public UnitTestFrameworkAssembly(IUnitTestProvider provider, UnitTestHarness unitTestHarness, Assembly assembly)
		{
			_provider = provider;
			_harness = unitTestHarness;
			_assembly = assembly;
		}
 /// <summary>
 /// Initializes the TestPage object.
 /// </summary>
 /// <param name="harness">The test harness instance.</param>
 public TestPage(UnitTestHarness harness) : this()
 {
     harness.TestPage = this;
     _harness         = harness;
 }
 public AgTestRunFilter(UnitTestSettings settings, UnitTestHarness harness) : base(settings, harness)
 {
 }
	public RuntimeVersionTestRunFilter(UnitTestSettings settings, UnitTestHarness harness, TestRunFilter subfilter) : base(settings, harness)
        {
		this.subfilter = subfilter;
		this.runtime_version = settings.RuntimeVersion;
        }
 public RiaTestRunFilter(UnitTestSettings settings, UnitTestHarness harness, Func <ITestMethod, bool> includeTest)
     : base(settings, harness)
 {
     _includeTest = includeTest;
 }
Exemple #28
0
 /// <summary>
 /// Records a harness state for the unit test harness.
 /// </summary>
 /// <param name="harness">The unit test harness.</param>
 /// <param name="name">The harness name.</param>
 /// <param name="stage">The test stage.</param>
 public void UnitTestHarnessStage(UnitTestHarness harness, string name, TestStage stage)
 {
     LogMessage m = Create(LogMessageType.TestExecution, name);
     MarkUnitTestMessage(m);
     DecorateNameProperty(m, name);
     DecorateTestGranularity(m, TestGranularity.Harness);
     m[UnitTestLogDecorator.UnitTestHarness] = harness;
     DecorateTestStage(m, stage);
     Enqueue(m);
 }
Exemple #29
0
 public TestAssembly(UnitTestHarness testHarness, Assembly assembly, IUnitTestProvider provider)
 {
     this.testHarness = testHarness;
     this.assembly    = assembly;
     this.provider    = provider;
 }
 /// <summary>
 /// Initializes a new instance of the DataManager.
 /// </summary>
 /// <param name="harness">The unit test harness instance.</param>
 /// <returns>Returns a new instance of a DataManager class.</returns>
 public static DataManager Create(UnitTestHarness harness)
 {
     return(new DataManager(harness));
 }