public async Task ShouldReceiveMessages( [Frozen] IRequestMessageRelay relay, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { await worker.Run(cancellationToken); await relay.Received().Receive(Is(cancellationToken)); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRequestInvoker" /> class. /// </summary> /// <param name="client">Client used to send/recieve http messages.</param> /// <param name="urlBuilder">Builder used to build URLs from requests.</param> /// <param name="relay">Service used to relay messages back and forth between SQS.</param> /// <param name="bucketService">Service used to manage buckets.</param> /// <param name="bucketRepository">Repository to manage buckets.</param> /// <param name="reporter">Service used to report metrics.</param> /// <param name="logger">Logger used to log info to some destination(s).</param> public DefaultRequestInvoker( HttpMessageInvoker client, IUrlBuilder urlBuilder, IRequestMessageRelay relay, IBucketService bucketService, IBucketRepository bucketRepository, IMetricReporter reporter, ILogger <DefaultRequestInvoker> logger ) { this.client = client; this.urlBuilder = urlBuilder; this.relay = relay; this.bucketService = bucketService; this.bucketRepository = bucketRepository; this.reporter = reporter; this.logger = logger; }
public async Task ShouldStartAndStopATraceWithMessageTraceHeader( RequestMessage message, [Frozen] IRequestMessageRelay relay, [Frozen] ITracingService tracing, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { relay.Receive(Any <CancellationToken>()).Returns(new[] { message }); await worker.Run(cancellationToken); Received.InOrder(() => { tracing.Received().StartTrace(Is(message.RequestDetails.TraceHeader)); tracing.Received().AddAnnotation(Is("event"), Is("rest-call")); tracing.Received().EndTrace(); }); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultRequestWorker" /> class. /// </summary> /// <param name="timerFactory">Factory to create timers with.</param> /// <param name="transactionFactory">Factory to create transactions with.</param> /// <param name="relay">Relay service to send/receive messages through the queue.</param> /// <param name="options">Options to use for handling requests.</param> /// <param name="scopeFactory">Service to create scopes with.</param> /// <param name="tracing">Service for managing app traces.</param> /// <param name="logger">Logger used to log info to some destination(s).</param> public DefaultRequestWorker( ITimerFactory timerFactory, ITransactionFactory transactionFactory, IRequestMessageRelay relay, IOptions <RequestOptions> options, IScopeFactory scopeFactory, ITracingService tracing, ILogger <DefaultRequestWorker> logger ) { this.timerFactory = timerFactory; this.transactionFactory = transactionFactory; this.relay = relay; this.options = options.Value; this.scopeFactory = scopeFactory; this.tracing = tracing; this.logger = logger; }
public async Task ShouldRespondToTheRequest( string response, RequestMessage request, [Frozen] HttpStatusCode statusCode, [Frozen] HttpResponseMessage httpResponse, [Frozen, Substitute] HttpMessageInvoker client, [Frozen, Substitute] IRequestMessageRelay relay, [Target] DefaultRequestInvoker invoker, CancellationToken cancellationToken ) { httpResponse.Content = new StringContent(response); request.RequestDetails = new Request(ChannelEndpoint.CreateMessage) { RequestBody = null }; await invoker.Invoke(request, cancellationToken); await client.Received().SendAsync(Any <HttpRequestMessage>(), Is(cancellationToken)); await relay.Received().Respond(Is(request), Is(statusCode), Is(response), Is(cancellationToken)); }
public async Task ShouldInvokeAllReceivedMessagesThenCompleteTransactions( RequestMessage message1, RequestMessage message2, IScope scope1, IScope scope2, IRequestInvoker invoker1, IRequestInvoker invoker2, ITransaction transaction1, ITransaction transaction2, [Frozen] ITransactionFactory transactionFactory, [Frozen] IRequestMessageRelay relay, [Frozen] IScopeFactory scopeFactory, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { transactionFactory.CreateTransaction().Returns(transaction1, transaction2); scope1.GetService <IRequestInvoker>().Returns(invoker1); scope2.GetService <IRequestInvoker>().Returns(invoker2); scopeFactory.CreateScope().Returns(scope1, scope2); relay.Receive(Any <CancellationToken>()).Returns(new[] { message1, message2 }); await worker.Run(cancellationToken); Received.InOrder(async() => { transactionFactory.Received().CreateTransaction(); scopeFactory.Received().CreateScope(); scope1.Received().GetService <IRequestInvoker>(); await invoker1.Received().Invoke(Is(message1), Is(cancellationToken)); transaction1.Received().Complete(); transactionFactory.Received().CreateTransaction(); scopeFactory.Received().CreateScope(); scope2.Received().GetService <IRequestInvoker>(); await invoker2.Received().Invoke(Is(message2), Is(cancellationToken)); transaction2.Received().Complete(); }); }
public async Task ShouldFailRequestIfExceptionWasThrown( string response, RequestMessage request, [Frozen] HttpStatusCode statusCode, [Frozen] HttpResponseMessage httpResponse, [Frozen, Substitute] HttpMessageInvoker client, [Frozen, Substitute] IRequestMessageRelay relay, [Target] DefaultRequestInvoker invoker, CancellationToken cancellationToken ) { client.SendAsync(Any <HttpRequestMessage>(), Any <CancellationToken>()).Throws <Exception>(); request.RequestDetails = new Request(ChannelEndpoint.CreateMessage) { RequestBody = null }; await invoker.Invoke(request, cancellationToken); await client.Received().SendAsync(Any <HttpRequestMessage>(), Is(cancellationToken)); await relay.Received().Fail(Is(request), Is(0U), Is(cancellationToken)); }