Esempio n. 1
0
        static HashSet <string>?GetImplementedInterfaces(IMessageSinkMessage message)
        {
            Guard.ArgumentNotNull(nameof(message), message);

            if (message is IMessageSinkMessageWithTypes messageWithTypes)
            {
                return(messageWithTypes.InterfaceTypes);
            }

#if NETFRAMEWORK
            // Can't get the list of interfaces across the remoting boundary
            if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(message))
            {
                return(null);
            }
#endif

            var result = new HashSet <string>(message.GetType().GetInterfaces().Select(i => i.FullName !), StringComparer.OrdinalIgnoreCase);

            // TODO: Hack this to include the concrete type, while we transition from v2 to v3 so that we
            // can support our new message types which aren't interfaces.
            result.Add(message.GetType().FullName !);

            return(result);
        }
Esempio n. 2
0
        HashSet <string> GetMessageTypes(IMessageSinkMessage message)
        {
            var messageType = message.GetType();
            HashSet <string> result;

            cacheLock.TryEnterReadLock(-1);

            try
            {
                interfaceCache.TryGetValue(messageType, out result);
            }
            finally
            {
                cacheLock.ExitReadLock();
            }

            if (result == null)
            {
                cacheLock.TryEnterWriteLock(-1);

                try
                {
                    result = new HashSet <string>(messageType.GetInterfaces().Select(x => x.FullName));
                    interfaceCache[messageType] = result;
                }
                finally
                {
                    cacheLock.ExitWriteLock();
                }
            }

            return(result);
        }
        HashSet<string> GetMessageTypes(IMessageSinkMessage message)
        {
            var messageType = message.GetType();
            HashSet<string> result;

            cacheLock.TryEnterReadLock(-1);

            try
            {
                interfaceCache.TryGetValue(messageType, out result);
            }
            finally
            {
                cacheLock.ExitReadLock();
            }

            if (result == null)
            {
                cacheLock.TryEnterWriteLock(-1);

                try
                {
                    result = new HashSet<string>(messageType.GetInterfaces().Select(x => x.FullName));
                    interfaceCache[messageType] = result;
                }
                finally
                {
                    cacheLock.ExitWriteLock();
                }
            }

            return result;
        }
        public void Dispose() { }    // Assume the thing we're wrapping gets disposed elsewhere

        /// <summary>
        /// Returns the implemented interface types, if known.
        /// </summary>
        /// <param name="message">The message interfaces to retrieve.</param>
        /// <returns>The hash set of interfaces, if known; <c>null</c>, otherwise.</returns>
        public static HashSet<string> GetImplementedInterfaces(IMessageSinkMessage message)
        {
            var messageWithTypes = message as IMessageSinkMessageWithTypes;
            if (messageWithTypes != null)
                return messageWithTypes.InterfaceTypes;

#if !PLATFORM_DOTNET
            // Can't get the list of interfaces across the remoting boundary
            if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(message))
                return null;
#endif

            return new HashSet<string>(message.GetType().GetInterfaces().Select(i => i.FullName), StringComparer.OrdinalIgnoreCase);
        }
        /// <summary>
        /// Adapts a v2 message to a v3 message.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown if the message is not of a known type.</exception>
        public _MessageSinkMessage Adapt(
            IMessageSinkMessage message,
            HashSet <string>?messageTypes = null)
        {
            return
                (TryConvert <IDiagnosticMessage>(message, messageTypes, AdaptDiagnosticMessage) ??

                 TryConvert <IDiscoveryCompleteMessage>(message, messageTypes, AdaptDiscoveryCompleteMessage) ??
                 TryConvert <ITestCaseDiscoveryMessage>(message, messageTypes, AdaptTestCaseDiscoveryMessage) ??

                 TryConvert <IErrorMessage>(message, messageTypes, AdaptErrorMessage) ??

                 TryConvert <ITestAssemblyCleanupFailure>(message, messageTypes, AdaptTestAssemblyCleanupFailure) ??
                 TryConvert <ITestAssemblyFinished>(message, messageTypes, AdaptTestAssemblyFinished) ??
                 TryConvert <ITestAssemblyStarting>(message, messageTypes, AdaptTestAssemblyStarting) ??

                 TryConvert <ITestCaseCleanupFailure>(message, messageTypes, AdaptTestCaseCleanupFailure) ??
                 TryConvert <ITestCaseFinished>(message, messageTypes, AdaptTestCaseFinished) ??
                 TryConvert <ITestCaseStarting>(message, messageTypes, AdaptTestCaseStarting) ??

                 TryConvert <ITestClassCleanupFailure>(message, messageTypes, AdaptTestClassCleanupFailure) ??
                 TryConvert <ITestClassFinished>(message, messageTypes, AdaptTestClassFinished) ??
                 TryConvert <ITestClassStarting>(message, messageTypes, AdaptTestClassStarting) ??

                 TryConvert <ITestCollectionCleanupFailure>(message, messageTypes, AdaptTestCollectionCleanupFailure) ??
                 TryConvert <ITestCollectionFinished>(message, messageTypes, AdaptTestCollectionFinished) ??
                 TryConvert <ITestCollectionStarting>(message, messageTypes, AdaptTestCollectionStarting) ??

                 TryConvert <ITestMethodCleanupFailure>(message, messageTypes, AdaptTestMethodCleanupFailure) ??
                 TryConvert <ITestMethodFinished>(message, messageTypes, AdaptTestMethodFinished) ??
                 TryConvert <ITestMethodStarting>(message, messageTypes, AdaptTestMethodStarting) ??

                 TryConvert <IAfterTestFinished>(message, messageTypes, AdaptAfterTestFinished) ??
                 TryConvert <IAfterTestStarting>(message, messageTypes, AdaptAfterTestStarting) ??
                 TryConvert <IBeforeTestFinished>(message, messageTypes, AdaptBeforeTestFinished) ??
                 TryConvert <IBeforeTestStarting>(message, messageTypes, AdaptBeforeTestStarting) ??
                 TryConvert <ITestClassConstructionFinished>(message, messageTypes, AdaptTestClassConstructionFinished) ??
                 TryConvert <ITestClassConstructionStarting>(message, messageTypes, AdaptTestClassConstructionStarting) ??
                 TryConvert <ITestClassDisposeFinished>(message, messageTypes, AdaptTestClassDisposeFinished) ??
                 TryConvert <ITestClassDisposeStarting>(message, messageTypes, AdaptTestClassDisposeStarting) ??
                 TryConvert <ITestCleanupFailure>(message, messageTypes, AdaptTestCleanupFailure) ??
                 TryConvert <ITestFailed>(message, messageTypes, AdaptTestFailed) ??
                 TryConvert <ITestFinished>(message, messageTypes, AdaptTestFinished) ??
                 TryConvert <ITestOutput>(message, messageTypes, AdaptTestOutput) ??
                 TryConvert <ITestPassed>(message, messageTypes, AdaptTestPassed) ??
                 TryConvert <ITestSkipped>(message, messageTypes, AdaptTestSkipped) ??
                 TryConvert <ITestStarting>(message, messageTypes, AdaptTestStarting) ??

                 throw new ArgumentException($"Unknown message type '{message.GetType().FullName}'", nameof(message)));
        }
Esempio n. 6
0
        public bool OnMessageWithTypes(IMessageSinkMessage message, HashSet <string> messageTypes)
        {
            Console.WriteLine($"{message.GetType().Name} ... {message}");

            return(message.Dispatch <ITestCaseFinished>(messageTypes, HandleTestCaseFinished) &&
                   message.Dispatch <ITestCaseStarting>(messageTypes, HandleTestCaseStarting) &&
                   message.Dispatch <IErrorMessage>(messageTypes, args => Interlocked.Increment(ref errors)) &&
                   message.Dispatch <ITestAssemblyCleanupFailure>(messageTypes, args => Interlocked.Increment(ref errors)) &&
                   message.Dispatch <ITestAssemblyFinished>(messageTypes, HandleTestAssemblyFinished) &&
                   message.Dispatch <ITestCaseCleanupFailure>(messageTypes, args => Interlocked.Increment(ref errors)) &&
                   message.Dispatch <ITestClassCleanupFailure>(messageTypes, args => Interlocked.Increment(ref errors)) &&
                   message.Dispatch <ITestCleanupFailure>(messageTypes, args => Interlocked.Increment(ref errors)) &&
                   message.Dispatch <ITestCollectionCleanupFailure>(messageTypes, args => Interlocked.Increment(ref errors)) &&
                   message.Dispatch <ITestMethodCleanupFailure>(messageTypes, args => Interlocked.Increment(ref errors)));
        }
Esempio n. 7
0
        }                            // Assume the thing we're wrapping gets disposed elsewhere

        /// <summary>
        /// Returns the implemented interface types, if known.
        /// </summary>
        /// <param name="message">The message interfaces to retrieve.</param>
        /// <returns>The hash set of interfaces, if known; <c>null</c>, otherwise.</returns>
        public static HashSet <string> GetImplementedInterfaces(IMessageSinkMessage message)
        {
            if (message is IMessageSinkMessageWithTypes messageWithTypes)
            {
                return(messageWithTypes.InterfaceTypes);
            }

#if NET35 || NET452
            // Can't get the list of interfaces across the remoting boundary
            if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(message))
            {
                return(null);
            }
#endif

            return(new HashSet <string>(message.GetType().GetInterfaces().Select(i => i.FullName), StringComparer.OrdinalIgnoreCase));
        }
Esempio n. 8
0
            public bool OnMessage(IMessageSinkMessage message)
            {
                var diagnostic = message as IDiagnosticMessage;

                if (diagnostic != null)
                {
                    _tracer.TraceEvent(TraceEventType.Verbose, 0, diagnostic.Message);
                }

#if DEBUG
                try
                {
                    File.AppendAllText("xunit.vsix.log", message.GetType().FullName + Environment.NewLine);
                }
                catch (IOException) { }
#endif

                return(_innerSink.OnMessage(message));
            }
Esempio n. 9
0
 static string[] GetMessageTypes(IMessageSinkMessage message)
 => message.GetType().GetInterfaces().Select(i => i.FullName).ToArray();
Esempio n. 10
0
        static string[] GetMessageTypes(IMessageSinkMessage message)
#if NET35
        => GetInterfaceNames(message.GetType());
Esempio n. 11
0
        public bool OnMessage(IMessageSinkMessage message)
        {
            var result = _innerMessageSink.OnMessage(message);

            try
            {
                OnMessageHandled(message);
            }
            catch (Exception e)
            {
                _diagnosticMessageSink?.OnMessage(new DiagnosticMessage($"Failed to handle message {message.GetType().Name}: {e}"));
            }

            return(result);
        }