Ejemplo n.º 1
0
        public async Task SendWithJsonHttpContentShouldSucceed()
        {
            // Arrange
            Registrator.RegisterDocuments();
            var destination = new Identity(Guid.NewGuid().ToString(), "msging.net");

            Context.User.Returns(destination);
            var select = new Select()
            {
                Text    = "This is the header",
                Scope   = SelectScope.Immediate,
                Options = new[]
                {
                    new SelectOption
                    {
                        Text = "This is the first option"
                    },
                    new SelectOption
                    {
                        Text = "This is the second option"
                    },
                    new SelectOption
                    {
                        Text = "This is the third option"
                    }
                }
            };

            var content = DocumentSerializer.Serialize(select);


            var settings = new SendRawMessageSettings
            {
                Type       = Select.MIME_TYPE,
                RawContent = content
            };
            var target = GetTarget();

            // Act
            await target.ExecuteAsync(Context, JObject.FromObject(settings), CancellationToken);

            // Assert
            await Sender.Received(1).SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.To.ToIdentity().Equals(destination) &&
                                 m.Type == Select.MediaType &&
                                 m.Content is Select &&
                                 ((Select)m.Content).Text == select.Text &&
                                 ((Select)m.Content).Scope == SelectScope.Immediate &&
                                 ((Select)m.Content).Options.Length == select.Options.Length &&
                                 ((Select)m.Content).Options[0].Text == select.Options[0].Text &&
                                 ((Select)m.Content).Options[1].Text == select.Options[1].Text &&
                                 ((Select)m.Content).Options[2].Text == select.Options[2].Text),
                CancellationToken);
        }
Ejemplo n.º 2
0
        public async Task SetUpAsync()
        {
            Registrator.RegisterDocuments();
            ChannelNamespace   = EnvelopeId.NewId();
            ListenerUri        = new Uri("redis://localhost");
            EnvelopeSerializer = new JsonNetSerializer();
            TraceWriter        = new Mock <ITraceWriter>();
            Listener           = new RedisTransportListener(ListenerUri, EnvelopeSerializer, TraceWriter.Object, channelNamespace: ChannelNamespace);
            await Listener.StartAsync(CancellationToken);

            CancellationToken = TimeSpan.FromSeconds(5).ToCancellationToken();
        }
Ejemplo n.º 3
0
 static RedisTransportTests()
 {
     Registrator.RegisterDocuments();
 }
Ejemplo n.º 4
0
        public async Task SendWithJsonHttpContentShouldSucceed()
        {
            // Arrange
            Registrator.RegisterDocuments();
            var destination = new Identity(Guid.NewGuid().ToString(), "msging.net");

            Context.User.Returns(destination);
            var uri     = new Uri("https://myserver.com/content/id");
            var content = new Select()
            {
                Text    = "This is the header",
                Scope   = SelectScope.Immediate,
                Options = new[]
                {
                    new SelectOption
                    {
                        Text = "This is the first option"
                    },
                    new SelectOption
                    {
                        Text = "This is the second option"
                    },
                    new SelectOption
                    {
                        Text = "This is the third option"
                    }
                }
            };

            var httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(DocumentSerializer.Serialize(content))
            };

            HttpClient
            .SendAsync(Arg.Is <HttpRequestMessage>(r => r.RequestUri == uri && r.Method == HttpMethod.Get),
                       CancellationToken)
            .Returns(httpResponseMessage);
            var settings = new SendMessageFromHttpSettings
            {
                Uri  = uri,
                Type = Select.MIME_TYPE
            };
            var target = GetTarget();

            // Act
            await target.ExecuteAsync(Context, JObject.FromObject(settings), CancellationToken);

            // Assert
            await Sender.Received(1).SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.To.ToIdentity().Equals(destination) &&
                                 m.Type == Select.MediaType &&
                                 m.Content is Select &&
                                 ((Select)m.Content).Text == content.Text &&
                                 ((Select)m.Content).Scope == SelectScope.Immediate &&
                                 ((Select)m.Content).Options.Length == content.Options.Length &&
                                 ((Select)m.Content).Options[0].Text == content.Options[0].Text &&
                                 ((Select)m.Content).Options[1].Text == content.Options[1].Text &&
                                 ((Select)m.Content).Options[2].Text == content.Options[2].Text),
                CancellationToken);
        }