Beispiel #1
0
        public FakeEnvelopeSerializer(int count)
        {
            _envelopes = Enumerable
                         .Range(0, count)
                         .Select <int, Envelope>(i =>
            {
                if (i % 5 == 0)
                {
                    return(Dummy.CreateMessage(Dummy.CreateTextContent()));
                }
                if (i % 3 == 0)
                {
                    return(Dummy.CreateCommand(Dummy.CreateAccount()));
                }
                if (i % 2 == 0)
                {
                    return(Dummy.CreateNotification(Event.Received));
                }
                return(Dummy.CreateMessage(Dummy.CreateSelect()));
            })
                         .ToArray();

            var jsonSerializer = new EnvelopeSerializer(new DocumentTypeResolver().WithMessagingDocuments());

            _serializedEnvelopes = _envelopes.Select(e => jsonSerializer.Serialize(e)).ToArray();
        }
        private void assertRoundTrips(int index)
        {
            var contentType = messageSerializers[index].ContentType;
            var envelope    = new Envelope()
            {
                Message     = theAddress,
                ContentType = contentType
            };

            theSerializer.Serialize(envelope, new ChannelNode());

            envelope.Message = theSerializer.Deserialize(envelope);

            envelope.Message.ShouldNotBeTheSameAs(theAddress);
            envelope.Message.ShouldBe(theAddress);
        }
Beispiel #3
0
        /// <inheritdoc />
        /// <exception cref="ObjectDisposedException">This instance has already been disposed.</exception>
        public override async Task SendAsync(Envelope envelope, CancellationToken cancellationToken)
        {
            ThrowIfNotConnected();

            await base.SendAsync(envelope, cancellationToken).ConfigureAwait(false);

            string serializedEnvelope = EnvelopeSerializer.Serialize(envelope);
            await TraceWriter.TraceIfEnabledAsync(serializedEnvelope, DataOperation.Send).ConfigureAwait(false);

            await _hubConnection.SendAsync(FROM_CLIENT_METHOD, serializedEnvelope, cancellationToken).ConfigureAwait(false);
        }
Beispiel #4
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">Thrown when the transport is not connected.</exception>
        public override async Task SendAsync(Envelope envelope, CancellationToken cancellationToken)
        {
            ThrowIfNotConnected();

            await base.SendAsync(envelope, cancellationToken).ConfigureAwait(false);

            string serializedEnvelope = EnvelopeSerializer.Serialize(envelope);
            await TraceWriter.TraceIfEnabledAsync(serializedEnvelope, DataOperation.Send).ConfigureAwait(false);

            var client = _hubContext.Clients.Client(_connectionId);

            await client.SendAsync(FROM_SERVER_METHOD, serializedEnvelope).ConfigureAwait(false);
        }