Exemplo n.º 1
0
        public async ValueTask TestAssemblyCleanupFailure()
        {
            var collectionStarting = new _TestAssemblyStarting
            {
                AssemblyUniqueID = assemblyID,
                AssemblyPath     = "assembly-file-path"
            };
            var collectionCleanupFailure = new _TestAssemblyCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };

            sink.OnMessage(collectionStarting);
            sink.OnMessage(collectionCleanupFailure);

            AssertFailure(listener, sink.TestRunState, "Test Assembly Cleanup Failure (assembly-file-path)");
        }
    public void TestAssemblyCleanupFailure()
    {
        var collectionStarting = new _TestAssemblyStarting
        {
            AssemblyUniqueID         = assemblyID,
            AssemblyName             = "assembly-name",
            AssemblyPath             = "assembly-file-path",
            ConfigFilePath           = "config-file-path",
            StartTime                = DateTimeOffset.UtcNow,
            TargetFramework          = "target-framework",
            TestEnvironment          = "test-environment",
            TestFrameworkDisplayName = "test-framework"
        };
        var collectionCleanupFailure = new _TestAssemblyCleanupFailure
        {
            AssemblyUniqueID       = assemblyID,
            ExceptionParentIndices = exceptionParentIndices,
            ExceptionTypes         = exceptionTypes,
            Messages    = messages,
            StackTraces = stackTraces
        };
        var assemblyElement = new XElement("assembly");
        var sink            = new DelegatingXmlCreationSink(innerSink, assemblyElement);

        sink.OnMessage(collectionStarting);
        sink.OnMessage(collectionCleanupFailure);

        AssertFailureElement(assemblyElement, "assembly-cleanup", "assembly-file-path");
    }
    public void AddsAssemblyStartingInformationToXml()
    {
        var assemblyStarting = new _TestAssemblyStarting
        {
            AssemblyPath             = "assembly",
            AssemblyUniqueID         = "assembly-id",
            ConfigFilePath           = "config",
            StartTime                = new DateTimeOffset(2013, 7, 6, 16, 24, 32, TimeSpan.Zero),
            TargetFramework          = "MentalFloss,Version=v21.12",
            TestEnvironment          = "256-bit MentalFloss",
            TestFrameworkDisplayName = "xUnit.net v14.42"
        };

        var assemblyElement = new XElement("assembly");
        var sink            = new DelegatingXmlCreationSink(innerSink, assemblyElement);

        sink.OnMessage(assemblyStarting);

        Assert.Equal("assembly", assemblyElement.Attribute("name") !.Value);
        Assert.Equal("MentalFloss,Version=v21.12", assemblyElement.Attribute("target-framework") !.Value);
        Assert.Equal("256-bit MentalFloss", assemblyElement.Attribute("environment") !.Value);
        Assert.Equal("xUnit.net v14.42", assemblyElement.Attribute("test-framework") !.Value);
        Assert.Equal("config", assemblyElement.Attribute("config-file") !.Value);
        Assert.Equal("2013-07-06", assemblyElement.Attribute("run-date") !.Value);
        Assert.Equal("16:24:32", assemblyElement.Attribute("run-time") !.Value);
    }
Exemplo n.º 4
0
    public void SerializationExcludesNullValues()
    {
        var startTime = new DateTimeOffset(2020, 09, 26, 13, 55, 27, 212, TimeSpan.FromHours(-7));
        var msg       = new _TestAssemblyStarting
        {
            AssemblyUniqueID         = "asm-id",
            AssemblyName             = "asm-name",
            AssemblyPath             = null,
            ConfigFilePath           = null,
            StartTime                = startTime,
            TestEnvironment          = "test-env",
            TestFrameworkDisplayName = "test-framework"
        };

        var result = Encoding.UTF8.GetString(msg.ToJson());

        Assert.Equal(
            @"{" +
            @"""$type"":""_TestAssemblyStarting""," +
            @"""AssemblyName"":""asm-name""," +
            @"""AssemblyUniqueID"":""asm-id""," +
            @"""StartTime"":""2020-09-26T13:55:27.212-07:00""," +
            @"""TestEnvironment"":""test-env""," +
            @"""TestFrameworkDisplayName"":""test-framework""" +
            @"}",
            result
            );
    }
Exemplo n.º 5
0
        /// <summary>
        /// INTERNAL METHOD, FOR TESTING PURPOSES ONLY. DO NOT CALL.
        /// </summary>
        protected void Run(
            IEnumerable <Xunit1TestCase> testCases,
            _IMessageSink messageSink)
        {
            var results       = new Xunit1RunSummary();
            var environment   = $"{IntPtr.Size * 8}-bit .NET {Environment.Version}";
            var testCasesList = testCases.ToList();

            var testAssemblyStartingMessage = new _TestAssemblyStarting
            {
                AssemblyName             = testAssemblyName,
                AssemblyPath             = assemblyFileName,
                AssemblyUniqueID         = TestAssemblyUniqueID,
                ConfigFilePath           = configFileName,
                StartTime                = DateTimeOffset.Now,
                TestEnvironment          = environment,
                TestFrameworkDisplayName = TestFrameworkDisplayName,
            };

            if (messageSink.OnMessage(testAssemblyStartingMessage))
            {
                try
                {
                    if (testCasesList.Count != 0)
                    {
                        results = RunTestCollection(testCasesList, messageSink);
                    }
                }
                catch (Exception ex)
                {
                    var errorMetadata = Xunit1ExceptionUtility.ConvertToErrorMetadata(ex);
                    var errorMessage  = new _ErrorMessage
                    {
                        ExceptionParentIndices = errorMetadata.ExceptionParentIndices,
                        ExceptionTypes         = errorMetadata.ExceptionTypes,
                        Messages    = errorMetadata.Messages,
                        StackTraces = errorMetadata.StackTraces
                    };
                    messageSink.OnMessage(errorMessage);
                }
                finally
                {
                    var assemblyFinished = new _TestAssemblyFinished
                    {
                        AssemblyUniqueID = testAssemblyStartingMessage.AssemblyUniqueID,
                        ExecutionTime    = results.Time,
                        TestsFailed      = results.Failed,
                        TestsRun         = results.Total,
                        TestsSkipped     = results.Skipped
                    };

                    messageSink.OnMessage(assemblyFinished);
                }
            }
        }
    public void AssemblyStartingDoesNotIncludeNullValues()
    {
        var assemblyStarting = new _TestAssemblyStarting
        {
            AssemblyPath             = "assembly",
            AssemblyUniqueID         = "assembly-id",
            StartTime                = new DateTimeOffset(2013, 7, 6, 16, 24, 32, TimeSpan.Zero),
            TestEnvironment          = "256-bit MentalFloss",
            TestFrameworkDisplayName = "xUnit.net v14.42"
        };

        var assemblyElement = new XElement("assembly");
        var sink            = new DelegatingXmlCreationSink(innerSink, assemblyElement);

        sink.OnMessage(assemblyStarting);

        Assert.Null(assemblyElement.Attribute("config-file"));
        Assert.Null(assemblyElement.Attribute("target-framework"));
    }
        public void TestAssemblyCleanupFailure()
        {
            var assemblyStarting = new _TestAssemblyStarting
            {
                AssemblyUniqueID = assemblyID,
                AssemblyPath     = @"C:\Foo\bar.dll"
            };
            var assemblyCleanupFailure = new _TestAssemblyCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(assemblyStarting);
            handler.OnMessage(assemblyCleanupFailure);

            AssertFailureMessages(handler.Messages, @"Test Assembly Cleanup Failure (C:\Foo\bar.dll)");
        }
        public void TestAssemblyCleanupFailure()
        {
            var collectionStarting = new _TestAssemblyStarting
            {
                AssemblyUniqueID = assemblyID,
                AssemblyPath     = "assembly-file-path"
            };
            var collectionCleanupFailure = new _TestAssemblyCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var handler = TestableTeamCityReporterMessageHandler.Create();

            handler.OnMessage(collectionStarting);
            handler.OnMessage(collectionCleanupFailure);

            AssertFailureMessage(handler.Messages, "Test Assembly Cleanup Failure (assembly-file-path)");
        }