Пример #1
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.Framework.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.Framework.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(8 == testOutput.Count(), "Output count is not 8. \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.Equal("TestDiscovery.Response", host.Output[host.Output.Count - 1].MessageType);
        }
Пример #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(15, 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.Equal("TestExecution.Response", host.Output[host.Output.Count - 1].MessageType);
        }
Пример #3
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.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();
            }
        }
Пример #4
0
        public async Task RunTest_ByUniqueName_ProtocolVersion_UnknownVersion()
        {
            // Arrange
            var host = new TestHostWrapper(_testProject);
            host.ProtocolVersion = 2;

            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);
            host.ProtocolVersion = 2;
            await host.StartAsync();

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

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

            Assert.Equal(1, host.ProtocolVersion);

            Assert.Equal(4, host.Output.Count);
            Assert.Single(host.Output, m => m.MessageType == "ProtocolVersion");
            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);
        }