public async Task Do_PerformsHttpCallForEachOrchestration()
        {
            // Arrange
            var request = fixture.Build <Request>()
                          .With(r => r.Method, "POST")
                          .With(r => r.Host, "http://somewhere.com")
                          .Create();

            var orchestrations = fixture.Build <Orchestration>()
                                 .With(o => o.Request, request)
                                 .CreateMany(2);

            mediatorConfig = fixture.Build <MediatorConfig>()
                             .With(c => c.Orchestrations, orchestrations.ToList())
                             .Create();

            orchestratorUnderTest = new OpenHimOrchestrator(Options.Create(mediatorConfig), httpClientFactory.Object);

            // Act
            await orchestratorUnderTest.Do(bodyString, primaryResponse);

            // Assert
            httpClientFactory.Verify(f => f.CreateClient(It.IsAny <string>()), Times.Exactly(2));
            httpMessageHandler.Protected().Verify("SendAsync", Times.Once(), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>());
            httpMessageHandler2.Protected().Verify("SendAsync", Times.Once(), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>());
        }
Beispiel #2
0
        public OpenHimCoreClient(HttpClient httpClient, IOptions <MediatorConfig> mediatorConfig, ILogger <OpenHimCoreClient> logger)
        {
            _mediatorConfig = mediatorConfig.Value ?? throw new ArgumentNullException(nameof(mediatorConfig));
            _logger         = logger ?? throw new ArgumentNullException(nameof(logger));

            var openHimCoreHost = _mediatorConfig.MediatorCore.OpenHimCoreHost
                                  ?? throw new ArgumentException($"{nameof(mediatorConfig)} has no value for MediatorCore.OpenHimCoreHost");

            httpClient.BaseAddress = new Uri(openHimCoreHost);

            _openHimCoreHttpClient = httpClient;
        }
        public async Task Do_WhenOrchestrationsEmpty_ReturnsOpenHimResponseWithNullOrchestrations()
        {
            // Arrange
            mediatorConfig = fixture.Build <MediatorConfig>()
                             .With(c => c.Orchestrations, Enumerable.Empty <Orchestration>().ToList())
                             .Create();

            orchestratorUnderTest = new OpenHimOrchestrator(Options.Create(mediatorConfig), httpClientFactory.Object);

            // Act
            var actualResult = await orchestratorUnderTest.Do(bodyString, primaryResponse);

            // Assert
            Assert.That(actualResult.Orchestrations, Is.Null);
        }
        public void SetUp()
        {
            fixture = new Fixture();
            fixture.Customizations.Add(new TypeRelay(typeof(HttpContent), typeof(StringContent)));
            mediatorConfig  = fixture.Create <MediatorConfig>();
            primaryResponse = fixture.Create <Response>();

            httpMessageHandler = new Mock <HttpMessageHandler>();

            var responseMessage = fixture.Create <HttpResponseMessage>();

            httpMessageHandler.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                               ItExpr.IsAny <HttpRequestMessage>(),
                                                                               ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(responseMessage);

            var httpClient1 = new HttpClient(httpMessageHandler.Object);

            httpMessageHandler2 = new Mock <HttpMessageHandler>();

            var responseMessage2 = fixture.Create <HttpResponseMessage>();

            httpMessageHandler2.Protected().Setup <Task <HttpResponseMessage> >("SendAsync",
                                                                                ItExpr.IsAny <HttpRequestMessage>(),
                                                                                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(responseMessage2);


            var httpClient2 = new HttpClient(httpMessageHandler2.Object);

            var clientQueue = new Queue <HttpClient>(new[] { httpClient1, httpClient2 });

            httpClientFactory = new Mock <IHttpClientFactory>();
            httpClientFactory.Setup(f => f.CreateClient(It.IsAny <string>()))
            .Returns(() => clientQueue.Dequeue());

            orchestratorUnderTest = new OpenHimOrchestrator(Options.Create(mediatorConfig), httpClientFactory.Object);
        }
Beispiel #5
0
 public OpenHimOrchestrator(IOptions <MediatorConfig> mediatorConfigOptions, IHttpClientFactory clientFactory)
 {
     _mediatorConfig = mediatorConfigOptions.Value ?? throw new ArgumentException($"{nameof(mediatorConfigOptions)} does not contain a value of type {nameof(MediatorConfig)}");
     _clientFactory  = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory));
 }