public void LaunchProcessWithDebuggerAttachedShouldUpdateEnvironmentVariables()
        {
            // Setup
            var mockRunEventsHandler = new Mock <ITestRunEventsHandler>();
            TestProcessStartInfo launchedStartInfo = null;

            mockRunEventsHandler.Setup(runHandler => runHandler.LaunchProcessWithDebuggerAttached(It.IsAny <TestProcessStartInfo>())).Callback
                ((TestProcessStartInfo startInfo) => { launchedStartInfo = startInfo; });
            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
            var mockTestRunCriteria   = new Mock <TestRunCriteria>(new List <string> {
                "source.dll"
            }, 10);
            var testProcessStartInfo = new TestProcessStartInfo
            {
                Arguments            = string.Empty,
                EnvironmentVariables = new Dictionary <string, string>
                {
                    { "variable1", "value1" },
                    { "variable2", "value2" }
                }
            };

            // Act.
            proxyExecutionManager.StartTestRun(mockTestRunCriteria.Object, mockRunEventsHandler.Object);
            proxyExecutionManager.LaunchProcessWithDebuggerAttached(testProcessStartInfo);

            // Verify.
            Assert.IsTrue(launchedStartInfo != null, "Failed to get the start info");
            foreach (var envVaribale in testProcessStartInfo.EnvironmentVariables)
            {
                Assert.AreEqual(envVaribale.Value, launchedStartInfo.EnvironmentVariables[envVaribale.Key], $"Expected environment variable {envVaribale.Key} : {envVaribale.Value} not found");
            }
        }
        public void HandlePartialRunCompleteShouldCreateNewProxyExecutionManagerIfDataCollectionEnabledAndCreatorWithDataCollection()
        {
            var completeArgs = new TestRunCompleteEventArgs(null, true, true, null, null, TimeSpan.Zero);

            this.mockTestHostManager       = new Mock <ITestRuntimeProvider>();
            this.mockRequestSender         = new Mock <ITestRequestSender>();
            this.mockDataCollectionManager = new Mock <IProxyDataCollectionManager>();
            var proxyDataCollectionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
            var managers = new List <Mock <ProxyExecutionManagerWithDataCollection> >();

            this.proxyManagerFunc = () =>
            {
                this.proxyManagerFuncCalled = true;
                var manager = new Mock <ProxyExecutionManagerWithDataCollection>(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
                managers.Add(manager);
                return(manager.Object);
            };
            var parallelExecutionManager = this.SetupExecutionManager(this.proxyManagerFunc, 2, setupTestCases: true);

            this.proxyManagerFuncCalled = false;
            parallelExecutionManager.HandlePartialRunComplete(proxyDataCollectionManager, completeArgs, null, null, null);
            Assert.IsTrue(this.proxyManagerFuncCalled);

            var handler = parallelExecutionManager.GetHandlerForGivenManager(managers.Last().Object);

            Assert.IsTrue(handler is ParallelDataCollectionEventsHandler);
        }
        public void HandlePartialRunCompleteShouldCreateNewProxyExecutionManagerIfDataCollectionEnabled()
        {
            var completeArgs = new TestRunCompleteEventArgs(null, true, true, null, null, TimeSpan.Zero);

            this.mockTestHostManager       = new Mock <ITestRuntimeProvider>();
            this.mockRequestSender         = new Mock <ITestRequestSender>();
            this.mockDataCollectionManager = new Mock <IProxyDataCollectionManager>();

            var proxyDataCollectionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);

            this.proxyParallelExecutionManager = new ParallelProxyExecutionManager(this.proxyManagerFunc, 2);

            var tests              = CreateTestCases();
            var testRunCriteria    = new TestRunCriteria(tests, 100);
            var processedTestCases = new List <TestCase>();

            SetupMockManagersForTestCase(processedTestCases, testRunCriteria);

            AutoResetEvent completeEvent = new AutoResetEvent(false);

            SetupHandleTestRunComplete(completeEvent);

            this.proxyParallelExecutionManager.StartTestRun(testRunCriteria, this.mockHandler.Object);
            Assert.IsTrue(completeEvent.WaitOne(taskTimeout), "Test run not completed.");
            this.proxyManagerFuncCalled = false;

            this.proxyParallelExecutionManager.HandlePartialRunComplete(proxyDataCollectionManager, completeArgs, null, null, null);

            Assert.IsTrue(this.proxyManagerFuncCalled);
        }
        public void TestHostManagerHostLaunchedTriggerShouldSendTestHostLaunchedEvent()
        {
            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);

            this.mockTestHostManager.Raise(x => x.HostLaunched += null, new HostProviderEventArgs("launched", 0, 1234));

            this.mockDataCollectionManager.Verify(x => x.TestHostLaunched(It.IsAny <int>()));
        }
Ejemplo n.º 5
0
        public void InitializeShouldInitializeDataCollectionProcessIfDataCollectionIsEnabled()
        {
            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockTestHostManager.Object, this.mockDataCollectionClient.Object);

            proxyExecutionManager.Initialize();

            mockDataCollectionClient.Verify(dc => dc.BeforeTestRunStart(It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>()), Times.Once);
        }
 public void TestInit()
 {
     this.mockTestHostManager       = new Mock <ITestRuntimeProvider>();
     this.mockRequestSender         = new Mock <ITestRequestSender>();
     this.testExecutionManager      = new ProxyExecutionManager(this.mockRequestSender.Object, this.mockTestHostManager.Object, this.testableClientConnectionTimeout);
     this.mockDataCollectionManager = new Mock <IProxyDataCollectionManager>();
     this.mockProcessHelper         = new Mock <IProcessHelper>();
     this.proxyExecutionManager     = new ProxyExecutionManagerWithDataCollection(this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
 }
 public void TestInit()
 {
     this.mockTestHostManager = new Mock <ITestRuntimeProvider>();
     this.mockRequestSender   = new Mock <ITestRequestSender>();
     this.mockDataSerializer  = new Mock <IDataSerializer>();
     this.mockRequestData     = new Mock <IRequestData>();
     this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(new NoOpMetricsCollection());
     this.testExecutionManager      = new ProxyExecutionManager(mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataSerializer.Object, this.testableClientConnectionTimeout);
     this.mockDataCollectionManager = new Mock <IProxyDataCollectionManager>();
     this.mockProcessHelper         = new Mock <IProcessHelper>();
     this.proxyExecutionManager     = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
 }
Ejemplo n.º 8
0
        public void InitializeShouldCallAfterTestRunIfExceptionIsThrownWhileCreatingDataCollectionProcess()
        {
            mockDataCollectionClient.Setup(dc => dc.BeforeTestRunStart(It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>())).Throws(new System.Exception("MyException"));
            mockDataCollectionClient.Setup(dc => dc.AfterTestRunEnd(It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>()));

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockTestHostManager.Object, this.mockDataCollectionClient.Object);

            proxyExecutionManager.Initialize();

            mockDataCollectionClient.Verify(dc => dc.BeforeTestRunStart(It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>()), Times.Once);
            mockDataCollectionClient.Verify(dc => dc.AfterTestRunEnd(It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>()), Times.Once);
        }
Ejemplo n.º 9
0
        public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess()
        {
            mockDataCollectionClient.Setup(dc => dc.BeforeTestRunStart(It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>())).Throws(new System.Exception("MyException"));
            mockDataCollectionClient.Setup(dc => dc.AfterTestRunEnd(It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>()));

            ProxyDataCollectionManager proxyDataCollectonManager = new ProxyDataCollectionManager(Architecture.AnyCPU, string.Empty, new DummyDataCollectionRequestSender(), new DummyDataCollectionLauncher());

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockTestHostManager.Object, proxyDataCollectonManager);

            proxyExecutionManager.Initialize();
            Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.ExceptionMessages);
            Assert.AreEqual(1, proxyExecutionManager.DataCollectionRunEventsHandler.ExceptionMessages.Count);
        }
        public void HandlePartialRunCompleteShouldCreateNewProxyExecutionManagerIfDataCollectionEnabled()
        {
            var completeArgs = new TestRunCompleteEventArgs(null, true, true, null, null, TimeSpan.Zero);

            this.mockTestHostManager       = new Mock <ITestRuntimeProvider>();
            this.mockRequestSender         = new Mock <ITestRequestSender>();
            this.mockDataCollectionManager = new Mock <IProxyDataCollectionManager>();
            var proxyDataCollectionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
            var parallelExecutionManager   = this.SetupExecutionManager(this.proxyManagerFunc, 2, setupTestCases: true);

            this.proxyManagerFuncCalled = false;
            parallelExecutionManager.HandlePartialRunComplete(proxyDataCollectionManager, completeArgs, null, null, null);
            Assert.IsTrue(this.proxyManagerFuncCalled);
        }
 public void TestInit()
 {
     this.mockTestHostManager   = new Mock <ITestRuntimeProvider>();
     this.mockRequestSender     = new Mock <ITestRequestSender>();
     this.mockDataSerializer    = new Mock <IDataSerializer>();
     this.mockRequestData       = new Mock <IRequestData>();
     this.mockMetricsCollection = new Mock <IMetricsCollection>();
     this.mockFileHelper        = new Mock <IFileHelper>();
     this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object);
     this.testExecutionManager      = new ProxyExecutionManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataSerializer.Object, this.mockFileHelper.Object);
     this.mockDataCollectionManager = new Mock <IProxyDataCollectionManager>();
     this.mockProcessHelper         = new Mock <IProcessHelper>();
     this.proxyExecutionManager     = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.mockDataCollectionManager.Object);
 }
        public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess()
        {
            var mockRequestSender = new Mock <IDataCollectionRequestSender>();

            mockRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(It.IsAny <string>(), It.IsAny <ITestMessageEventHandler>())).Throws(new Exception("MyException"));

            var mockDataCollectionLauncher = new Mock <IDataCollectionLauncher>();
            var proxyDataCollectonManager  = new ProxyDataCollectionManager(string.Empty, mockRequestSender.Object, this.mockProcessHelper.Object, mockDataCollectionLauncher.Object);

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, proxyDataCollectonManager);

            proxyExecutionManager.Initialize();
            Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.Messages);
            Assert.AreEqual(TestMessageLevel.Error, proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item1);
            Assert.AreEqual("MyException", proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2);
        }
        public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess()
        {
            var mockRequestSender = new Mock <IDataCollectionRequestSender>();
            var testSources       = new List <string>()
            {
                "abc.dll", "efg.dll"
            };

            mockRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(string.Empty, testSources, It.IsAny <ITestMessageEventHandler>())).Throws(new Exception("MyException"));
            mockRequestSender.Setup(x => x.WaitForRequestHandlerConnection(It.IsAny <int>())).Returns(true);

            var mockDataCollectionLauncher = new Mock <IDataCollectionLauncher>();
            var proxyDataCollectonManager  = new ProxyDataCollectionManager(this.mockRequestData.Object, string.Empty, testSources, mockRequestSender.Object, this.mockProcessHelper.Object, mockDataCollectionLauncher.Object);

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, proxyDataCollectonManager);

            proxyExecutionManager.Initialize(false);
            Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.Messages);
            Assert.AreEqual(TestMessageLevel.Error, proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item1);
            StringAssert.Contains(proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2, "MyException");
        }