public async Task SendRemovesSentRequestsFromQueue() { //arrange var config = new ServerConfig(new Uri("http://localhost"), Guid.NewGuid().ToString(), TimeSpan.MaxValue); var http = new MockHttpMessageHandler(); var httpClient = new HttpClient(http); var agent = new QueuedAgent(config, httpClient); var r1 = new Request { Action = "a1" }; var r2 = new Request { Action = "a2" }; var r3 = new Request { Action = "a3" }; await agent.Send(r1); await agent.Send(r2); await agent.Send(r3); //act var toSend = new[] { r1, r2 }; await agent.PostRequests(toSend); //assert var remaining = agent.GetOutstandingRequests(); Assert.DoesNotContain(r1, remaining); Assert.DoesNotContain(r2, remaining); Assert.Contains(r3, remaining); }
public async Task SenderStopsOnDispose() { //arrange var config = new ServerConfig(new Uri("http://localhost"), Guid.NewGuid().ToString(), TimeSpan.Zero); var httpClient = Substitute.For <HttpClient>(); var agent = new QueuedAgent(config, httpClient); await agent.Send(new Request()); //act agent.Dispose(); //assert Assert.False(agent.IsRunning); }
public async Task SendAddsRequestToQueue() { //arrange var config = new ServerConfig(new Uri("http://localhost"), Guid.NewGuid().ToString(), TimeSpan.MaxValue); var httpClient = Substitute.For <HttpClient>(); var agent = new QueuedAgent(config, httpClient); var request = new Request(); //act await agent.Send(request); //assert Assert.Contains(request, agent.GetOutstandingRequests()); }
public async Task RequestQueueIsClearedOnDispose() { var config = new ServerConfig(new Uri("http://localhost"), Guid.NewGuid().ToString(), TimeSpan.MaxValue); var http = new MockHttpMessageHandler(); var httpClient = new HttpClient(http); var agent = new QueuedAgent(config, httpClient); await agent.Send(new Request()); //act agent.Dispose(); //assert var leftover = agent.GetOutstandingRequests(); Assert.Empty(leftover); }