public async Task Run_for_a_while_using_WebSocket() { // Begin: README example var bayeuxClient = new BayeuxClient( new WebSocketTransportOptions() { Uri = new Uri("ws://localhost:8080/bayeux/"), }); // End: README example bayeuxClient.EventReceived += (e, args) => Debug.WriteLine($"Event received on channel {args.Channel} with data\n{args.Data}"); bayeuxClient.ConnectionStateChanged += (e, args) => Debug.WriteLine($"Bayeux connection state changed to {args.ConnectionState}"); await bayeuxClient.AddSubscriptionsAsync("/**"); await bayeuxClient.StartAsync(); using (bayeuxClient) { await Delay(60); } }
public async Task Run_for_a_while_using_HTTP() { // Begin: README example var httpClient = new HttpClient(); var bayeuxClient = new BayeuxClient( new HttpLongPollingTransportOptions() { HttpClient = httpClient, Uri = "http://localhost:8080/bayeux/", }); bayeuxClient.EventReceived += (e, args) => Debug.WriteLine($"Event received on channel {args.Channel} with data\n{args.Data}"); bayeuxClient.ConnectionStateChanged += (e, args) => Debug.WriteLine($"Bayeux connection state changed to {args.ConnectionState}"); await bayeuxClient.AddSubscriptionsAsync("/**"); await bayeuxClient.StartAsync(); // End: README example using (bayeuxClient) { await Delay(60); } }
public async Task AddSubscriptions_succeeds_when_not_connected() { var mock = new Mock <HttpMessageHandler>(); var bayeuxClient = new BayeuxClient(new HttpLongPollingTransportOptions() { HttpClient = new HttpClient(mock.Object), Uri = "none" }); await bayeuxClient.AddSubscriptionsAsync("dummy"); }
public async Task Automatic_subscription() { var mock = new Mock <HttpMessageHandler>(); var mockProtected = mock.Protected().As <IHttpMessageHandlerProtected>(); int subscriptionCount = 0; mockProtected .Setup(h => h.SendAsync(MatchSubscriptionRequest(), It.IsAny <CancellationToken>())) .Returns(() => Task.Run(() => subscriptionCount++) .ContinueWith(t => BuildBayeuxResponse(successfulSubscriptionResponse))); mockProtected .Setup(h => h.SendAsync(MatchHandshakeRequest(), It.IsAny <CancellationToken>())) .ReturnsAsync(BuildBayeuxResponse(successfulHandshakeResponse)); mockProtected .Setup(h => h.SendAsync(MatchConnectRequest(), It.IsAny <CancellationToken>())) .Returns(() => Task.Delay(TimeSpan.FromSeconds(5)) .ContinueWith(t => BuildBayeuxResponse(successfulConnectResponse))); var bayeuxClient = new BayeuxClient( new HttpLongPollingTransportOptions() { HttpClient = new HttpClient(mock.Object), Uri = Url }, reconnectDelays: new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2) }); using (bayeuxClient) { await bayeuxClient.AddSubscriptionsAsync("/mychannel"); bayeuxClient.StartAsync(); await Task.Delay(TimeSpan.FromSeconds(2)); } Assert.AreEqual(1, subscriptionCount); }