Ejemplo n.º 1
0
        public async Task RunTest_ByUniqueName()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);

            await host.StartAsync();

            await host.ListTestsAsync();

            var test = host.Output
                       .Where(m => m.MessageType == "TestDiscovery.TestFound")
                       .First()
                       .Payload.ToObject <Test>();

            host.Output.Clear();

            host = new TestHostWrapper(_testProject);
            await host.StartAsync();

            // Act
            var result = await host.RunTestsAsync(_testProject, test.FullyQualifiedName);

            // Assert
            Assert.Equal(0, result);

            Assert.Equal(3, host.Output.Count);
            Assert.Single(host.Output, m => TestStarted(m, test.DisplayName));
            Assert.Single(host.Output, m => TestPassed(m, test.DisplayName));
            Assert.Equal("TestExecution.Response", host.Output[host.Output.Count - 1].MessageType);
        }
Ejemplo n.º 2
0
        public async Task RunTest_All()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);

            await host.StartAsync();

            // Act
            var result = await host.RunTestsAsync();

            // Assert
            Assert.Equal(0, result);

            Assert.Equal(19, host.Output.Count);
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.True_is_true"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.True_is_true"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.TheoryTest1(x: 1)"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.TheoryTest1(x: 1)"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.TheoryTest1(x: 2)"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.TheoryTest1(x: 2)"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.TheoryTest1(x: 3)"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.TheoryTest1(x: 3)"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.TheoryTest2(x: 1, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.TheoryTest2(x: 1, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.TheoryTest2(x: 2, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.TheoryTest2(x: 2, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.TheoryTest2(x: 3, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.TheoryTest2(x: 3, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestStarted(m, "SampleTest.SampleAsyncTest"));
            Assert.Single(host.Output, m => TestPassed(m, "SampleTest.SampleAsyncTest"));
            Assert.Single(host.Output, m => TestStarted(m, "DerivedTest.ThisGetsInherited"));
            Assert.Single(host.Output, m => TestPassed(m, "DerivedTest.ThisGetsInherited"));

            Assert.Equal("TestExecution.Response", host.Output[host.Output.Count - 1].MessageType);
        }
Ejemplo n.º 3
0
        private void Reset()
        {
            IsRunning = false;
            ProcessId = 0;

            if (_host != null)
            {
                _host.Dispose();
                _host = null;
            }
        }
Ejemplo n.º 4
0
        private void ExecuteStartTestHost(object _)
        {
            _console.Text  = string.Empty;
            _messages.Text = string.Empty;

            var host = new TestHostWrapper(SelectedProject, DNX, Debug);

            int dthPort;

            if (!string.IsNullOrEmpty(DTHPort) && int.TryParse(DTHPort, out dthPort))
            {
                host.DTHPort = dthPort;
            }

            host.ParentProcessId        = Process.GetCurrentProcess().Id;
            host.ConsoleOutputReceived += TestHost_ConsoleOutputReceived;
            host.MessageReceived       += TestHost_MessageReceived;

            try
            {
                IsRunning = true;

                _host  = host;
                Status = "Starting TestHost...";

                var timer = Stopwatch.StartNew();
                var task  = host.StartAsync();

                task.ContinueWith((t) =>
                {
                    if (t.IsFaulted)
                    {
                        Status = "Starting TestHost failed.";
                        ShowErrorDialog(t.Exception);
                        Reset();
                    }
                    else
                    {
                        Status    = string.Format("Started: pid {0} in {1}ms.", _host.Process.Id, timer.ElapsedMilliseconds);
                        ProcessId = _host.Process.Id;
                    }
                }, _scheduler);
            }
            catch (Exception ex)
            {
                ShowErrorDialog(ex);
                Reset();
            }
        }
Ejemplo n.º 5
0
        public async Task ListTest_InheritedMethod_Symbols()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);

            await host.StartAsync();

            // Act
            var result = await host.ListTestsAsync();

            // Assert
            Assert.Equal(0, result);

            var test = GetTest(host.Output, "DerivedTest.ThisGetsInherited");

            Assert.NotNull(test);

            Assert.EndsWith("BaseTest.cs", test.CodeFilePath);
            Assert.Equal(12, test.LineNumber);
        }
Ejemplo n.º 6
0
        public async Task ListTest_AsyncMethod_Symbols()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);

            await host.StartAsync();

            // Act
            var result = await host.ListTestsAsync();

            // Assert
            Assert.Equal(0, result);

            var test = GetTest(host.Output, "SampleTest.SampleAsyncTest");

            Assert.NotNull(test);

            Assert.EndsWith("SampleTest.cs", test.CodeFilePath);
            Assert.Equal(35, test.LineNumber);
        }
Ejemplo n.º 7
0
        public async Task RunTest_IncludesStartAndEndTime()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);

            await host.StartAsync();

            // Act
            var result = await host.RunTestsAsync();

            // Assert
            Assert.Equal(0, result);

            var results = GetTestResults(host.Output).ToArray();

            Assert.Equal(9, results.Length);

            foreach (var testResult in results)
            {
                Assert.NotEqual(default(DateTimeOffset), testResult.StartTime);
                Assert.NotEqual(default(DateTimeOffset), testResult.EndTime);
            }
        }
Ejemplo n.º 8
0
        public async Task ListTest()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);

            await host.StartAsync();

            // Act
            var result = await host.ListTestsAsync();

            // Assert
            Assert.Equal(0, result);

            /* Following message will be sent when test is running in an environment missing DIA.
             * Should it exists, it will be extracted from the message list.
             * {
             *     "Name": "Microsoft.Dnx.TestHost.TestAdapter.SourceInformationProvider",
             *     "EventId": 0,
             *     "Level": "Warning",
             *     "Message": "Failed to create DIA DataSource. No source information will be available.\r\nSystem.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {E6756135-1E65-4D17-8576-610761398C3C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).\r\n   at Microsoft.Framework.TestHost.TestAdapter.SourceInformationProvider.EnsureInitialized() in C:\\projects\\testing\\src\\Microsoft.Dnx.TestHost\\TestAdapter\\SourceInformationProvider.cs:line 155"
             */

            var fullMessageDiagnostics = string.Format("Full output: \n{0}", string.Join("\n", host.Output));
            var testOutput             = host.Output.Where(message => message.MessageType != "Log");

            Assert.True(10 == testOutput.Count(), "Number of messages is not right. \n" + fullMessageDiagnostics);
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.True_is_true"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.TheoryTest1(x: 1)"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.TheoryTest1(x: 2)"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.TheoryTest1(x: 3)"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.TheoryTest2(x: 1, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.TheoryTest2(x: 2, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.TheoryTest2(x: 3, s: \"Hi\")"));
            Assert.Single(host.Output, m => TestFound(m, "SampleTest.SampleAsyncTest"));
            Assert.Single(host.Output, m => TestFound(m, "DerivedTest.ThisGetsInherited"));
            Assert.Equal("TestDiscovery.Response", host.Output[host.Output.Count - 1].MessageType);
        }
Ejemplo n.º 9
0
        public async Task TestHostExits_WhenParentProcessExits()
        {
            // Arrange
            var parentProcess = new Process();

            parentProcess.StartInfo.FileName    = "cmd";
            parentProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var testHost = new TestHostWrapper(_testProject);
            int testHostProcessId;

            try
            {
                parentProcess.Start();
                testHost.ParentProcessId = parentProcess.Id;

                // Act
                await testHost.StartAsync();

                testHostProcessId = testHost.Process.Id;
            }
            finally
            {
                parentProcess.Kill();
            }

            // Assert
            // By this time the test host process could have been killed and if not wait for 5 seconds
            // before doing a check again.
            var testHostProcess = GetProcessById(testHostProcessId);

            if (testHostProcess != null)
            {
                testHostProcess.WaitForExit(5 * 1000);
                testHostProcess = GetProcessById(testHostProcessId);
            }
            Assert.Null(testHostProcess);
        }