Exemplo n.º 1
0
        private void SetupForExecutionThreadApartmentStateTests(PlatformApartmentState apartmentState)
        {
            this.mockThread = new Mock <IThread>();

            this.runTestsInstance = new TestableBaseRunTests(
                $@"<RunSettings>
                  <RunConfiguration>
                     <ExecutionThreadApartmentState>{apartmentState}</ExecutionThreadApartmentState>
                   </RunConfiguration>
                </RunSettings>",
                testExecutionContext,
                null,
                this.mockTestRunEventsHandler.Object,
                this.mockTestPlatformEventSource.Object,
                null,
                this.mockThread.Object,
                this.mockRequestData.Object);
            TestPluginCacheTests.SetupMockExtensions(new string[] { typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location }, () => { });
            var assemblyLocation        = typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location;
            var executorUriExtensionMap = new List <Tuple <Uri, string> >
            {
                new Tuple <Uri, string>(new Uri(BaseRunTestsExecutorUri), assemblyLocation)
            };

            this.runTestsInstance.GetExecutorUriExtensionMapCallback = (fh, rc) => { return(executorUriExtensionMap); };
        }
Exemplo n.º 2
0
        public void TestInit()
        {
            this.testExecutionContext = new TestExecutionContext(
                frequencyOfRunStatsChangeEvent: 100,
                runStatsChangeEventTimeout: TimeSpan.MaxValue,
                inIsolation: false,
                keepAlive: false,
                isDataCollectionEnabled: false,
                areTestCaseLevelEventsRequired: false,
                hasTestRun: false,
                isDebug: false,
                testCaseFilter: string.Empty,
                filterOptions: null);
            this.mockTestRunEventsHandler = new Mock <ITestRunEventsHandler>();

            this.mockTestPlatformEventSource = new Mock <ITestPlatformEventSource>();

            this.mockRequestData       = new Mock <IRequestData>();
            this.mockMetricsCollection = new Mock <IMetricsCollection>();
            this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object);

            this.runTestsInstance = new TestableBaseRunTests(
                null,
                testExecutionContext,
                null,
                this.mockTestRunEventsHandler.Object,
                this.mockTestPlatformEventSource.Object,
                this.mockRequestData.Object);

            TestPluginCacheTests.SetupMockExtensions(new string[] { typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location }, () => { });
        }
Exemplo n.º 3
0
        private void SetUpTestRunEvents(string package = null, bool setupHandleTestRunComplete = true)
        {
            if (setupHandleTestRunComplete)
            {
                this.SetupHandleTestRunComplete();
            }
            else
            {
                this.SetupHandleTestRunStatsChange();
            }

            this.SetupDataSerializer();

            this.runTestsInstance = this.runTestsInstance = new TestableBaseRunTests(
                this.mockRequestData.Object,
                package,
                null,
                this.testExecutionContext,
                null,
                this.mockTestRunEventsHandler.Object,
                this.mockTestPlatformEventSource.Object,
                null,
                new PlatformThread(),
                this.mockDataSerializer.Object);

            var assemblyLocation        = typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location;
            var executorUriExtensionMap = new List <Tuple <Uri, string> >
            {
                new Tuple <Uri, string>(new Uri(BadBaseRunTestsExecutorUri), assemblyLocation),
                new Tuple <Uri, string>(new Uri(BaseRunTestsExecutorUri), assemblyLocation)
            };

            // Setup mocks.
            this.SetupExecutorCallback(executorUriExtensionMap);
        }
Exemplo n.º 4
0
        public void TestInit()
        {
            this.testExecutionContext = new TestExecutionContext(
                frequencyOfRunStatsChangeEvent: 100,
                runStatsChangeEventTimeout: TimeSpan.MaxValue,
                inIsolation: false,
                keepAlive: false,
                isDataCollectionEnabled: false,
                areTestCaseLevelEventsRequired: false,
                hasTestRun: false,
                isDebug: false,
                testCaseFilter: string.Empty);
            this.mockTestRunEventsHandler = new Mock <ITestRunEventsHandler>();

            this.mockTestPlatformEventSource = new Mock <ITestPlatformEventSource>();

            this.runTestsInstance = new TestableBaseRunTests(
                null,
                testExecutionContext,
                null,
                this.mockTestRunEventsHandler.Object,
                this.mockTestPlatformEventSource.Object);
        }
Exemplo n.º 5
0
        public void RunTestsShouldUpdateTestCasesWithPackageWhenCacheIsHitIfProvided()
        {
            var package = "x.apprecipe";

            this.testExecutionContext.FrequencyOfRunStatsChangeEvent = 2;
            TestRunChangedEventArgs receivedRunStatusArgs = null;

            this.runTestsInstance = new TestableBaseRunTests(
                null,
                package,
                testExecutionContext,
                null,
                this.mockTestRunEventsHandler.Object,
                this.mockTestPlatformEventSource.Object,
                this.mockRequestData.Object);

            var assemblyLocation        = typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location;
            var executorUriExtensionMap = new List <Tuple <Uri, string> >
            {
                new Tuple <Uri, string>(new Uri(BadBaseRunTestsExecutorUri), assemblyLocation),
                new Tuple <Uri, string>(new Uri(BaseRunTestsExecutorUri), assemblyLocation)
            };

            // Setup mocks.
            this.runTestsInstance.GetExecutorUriExtensionMapCallback = (fh, rc) => { return(executorUriExtensionMap); };
            this.runTestsInstance.InvokeExecutorCallback             =
                (executor, executorUriExtensionTuple, runContext, frameworkHandle) =>
            {
                var testCase       = new TestCase("x.y.z1", new Uri("uri://dummy"), "x.dll");
                var inProgTestCase = new TestCase("x.y.z2", new Uri("uri://dummy"), "x.dll");
                var testResult     = new Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult(testCase);
                this.runTestsInstance.GetTestRunCache.OnTestStarted(inProgTestCase);
                this.runTestsInstance.GetTestRunCache.OnNewTestResult(testResult);
            };
            this.mockTestRunEventsHandler.Setup(treh => treh.HandleTestRunStatsChange(It.IsAny <TestRunChangedEventArgs>()))
            .Callback((TestRunChangedEventArgs stats) =>
            {
                receivedRunStatusArgs = stats;
            });

            // Act.
            this.runTestsInstance.RunTests();

            // Test run changed event assertions
            Assert.IsNotNull(receivedRunStatusArgs.NewTestResults);
            Assert.IsTrue(receivedRunStatusArgs.NewTestResults.Count() > 0);

            Assert.IsNotNull(receivedRunStatusArgs.ActiveTests);
            Assert.AreEqual(receivedRunStatusArgs.ActiveTests.Count(), 1);

            // verify TC.Source is updated with package
            foreach (var tr in receivedRunStatusArgs.NewTestResults)
            {
                Assert.AreEqual(tr.TestCase.Source, package);
            }

            foreach (var tc in receivedRunStatusArgs.ActiveTests)
            {
                Assert.AreEqual(tc.Source, package);
            }
        }