summaryrefslogtreecommitdiff
path: root/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactMessageBus.cs
blob: 6d01889efb4dfb86dd39190dcce1d8b97c3434eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixBuildTools.TestSupport.XunitExtensions
{
    using System.Linq;
    using Xunit.Abstractions;
    using Xunit.Sdk;

    public class SkippableFactMessageBus : IMessageBus
    {
        private IMessageBus InnerBus { get; }

        public SkippableFactMessageBus(IMessageBus innerBus)
        {
            this.InnerBus = innerBus;
        }

        public int DynamicallySkippedTestCount { get; private set; }

        public void Dispose()
        {
        }

        public bool QueueMessage(IMessageSinkMessage message)
        {
            if (message is ITestFailed testFailed)
            {
                var exceptionType = testFailed.ExceptionTypes.FirstOrDefault();
                if (exceptionType == typeof(SkipTestException).FullName)
                {
                    ++this.DynamicallySkippedTestCount;
                    return this.InnerBus.QueueMessage(new TestSkipped(testFailed.Test, testFailed.Messages.FirstOrDefault()));
                }
            }

            // Nothing we care about, send it on its way
            return this.InnerBus.QueueMessage(message);
        }
    }
}