Exemple #1
0
        public async Task Run()
        {
            var fakeHandler = new FakeHttpMessageHandler();
            var stream      = $"event: open\ndata: hello\n\nid: {_eventId}\ndata: {_json}\n\n";

            fakeHandler.QueueResponse(FakeResponse.StartsStream(StreamAction.Write(stream)));

            _eventSource = new SSEEventSource(new Uri("http://test.com"),
                                              builder => builder.MessageHandler(fakeHandler));

            _requestBuilder = new FakeStreamableRequestBuilder(new Uri("https://horizon-testnet.stellar.org"), "test",
                                                               null, _eventSource);
            var handler = new EventHandler <T>((sender, e) =>
            {
                _eventSource.Shutdown();
                _testAction(e);
            });
            var task          = _requestBuilder.Stream(handler).Connect();
            var timeoutTask   = Task.Delay(TimeSpan.FromSeconds(5.0));
            var completedTask = await Task.WhenAny(task, timeoutTask).ConfigureAwait(false);

            if (completedTask != task)
            {
                throw new Exception("Task did not complete.");
            }
        }
Exemple #2
0
        public StreamableTest(string json, Action <T> testAction)
        {
            _json       = json;
            _testAction = testAction;

            fakeStreamableRequestBuilder = new FakeStreamableRequestBuilder(new Uri("https://horizon-testnet.stellar.org"), "test", null, eventSource.Object);
        }
Exemple #3
0
 public StreamableTest(string json, Action <T> action, string eventId = null)
 {
     _json           = json.Replace("\r\n", "").Replace("\n", "");
     _testAction     = action;
     _received       = null;
     _eventSource    = null;
     _requestBuilder = null;
     _eventId        = eventId ?? "1234";
 }