コード例 #1
0
        public void DefaultHubProtocolResolverTestsCanCreateSupportedProtocols(IHubProtocol protocol)
        {
            var mockConnection = new Mock <HubConnectionContext>(Channel.CreateUnbounded <HubMessage>().Out, new Mock <ConnectionContext>().Object);

            Assert.IsType(
                protocol.GetType(),
                new DefaultHubProtocolResolver(Options.Create(new HubOptions())).GetProtocol(protocol.Name, mockConnection.Object));
        }
コード例 #2
0
        public void DefaultHubProtocolResolverTestsCanCreateAllProtocols(IHubProtocol protocol)
        {
            var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, AllProtocolNames));
        }
コード例 #3
0
        public void DefaultHubProtocolResolverTestsCanCreateSupportedProtocols(IHubProtocol protocol)
        {
            var mockConnection = new Mock <HubConnectionContext>(new Mock <ConnectionContext>().Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance);

            Assert.IsType(
                protocol.GetType(),
                new DefaultHubProtocolResolver(Options.Create(new HubOptions())).GetProtocol(protocol.Name, mockConnection.Object));
        }
コード例 #4
0
        public void DefaultHubProtocolResolverCreatesProtocolswhenSupoortedProtocolsIsNull(IHubProtocol protocol)
        {
            List <string> supportedProtocols = null;
            var           resolver           = new DefaultHubProtocolResolver(AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, supportedProtocols));
        }
コード例 #5
0
        public void DefaultHubProtocolResolverTestsCanCreateSupportedProtocols(IHubProtocol protocol)
        {
            var supportedProtocols = new List <string> {
                protocol.Name
            };
            var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, supportedProtocols));
        }
コード例 #6
0
        private static bool TryGetPayload(IHubProtocol protocol, InvocationMessage invocationMessage, out ReadOnlySequence <byte> payload)
        {
            var buffer = new ReadOnlySequence <byte>(protocol.GetMessageBytes(invocationMessage));

            if (protocol is JsonHubProtocol)
            {
                return(TextMessageParser.TryParseMessage(ref buffer, out payload));
            }
            else if (protocol is MessagePackHubProtocol)
            {
                return(BinaryMessageParser.TryParseMessage(ref buffer, out payload));
            }

            throw new ArgumentException($"{protocol.GetType()} is not supported");
        }
コード例 #7
0
        public void DefaultHubProtocolResolverTestsCanCreateSupportedProtocols(IHubProtocol protocol)
        {
            var connection = new Mock <ConnectionContext>();

            connection.Setup(m => m.Features).Returns(new FeatureCollection());
            var mockConnection = new Mock <HubConnectionContext>(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance)
            {
                CallBase = true
            };
            var resolver = new DefaultHubProtocolResolver(Options.Create(new HubOptions()), AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, mockConnection.Object));
        }
コード例 #8
0
        public void DefaultHubProtocolResolverCreatesProtocolswhenSupoortedProtocolsIsNull(IHubProtocol protocol)
        {
            var connection = new Mock <ConnectionContext>();

            connection.Setup(m => m.Features).Returns(new FeatureCollection());
            var mockConnection = new Mock <HubConnectionContext>(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance)
            {
                CallBase = true
            };
            List <string> supportedProtocols = null;
            var           resolver           = new DefaultHubProtocolResolver(AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, supportedProtocols, mockConnection.Object));
        }