Example #1
0
        public async Task CorrelationId_IsUsedInRequestHeader(string correlationId)
        {
            using (var httpTest = new HttpTest())
            {
                // Arrange
                var baseUri = "http://localhost";
                httpTest.RespondWithJson("{}");
                var headers = new Dictionary <string, string>
                {
                    { "X-Correlation-Id", correlationId }
                };

                HttpClientConfiguration.ConfigureHttpClients(() => headers);

                // Act
                await baseUri
                .GetAsync();

                // Assert
                httpTest.CallLog.Single().Request.Headers.Single()
                .Key.Should().Be("X-Correlation-Id");
                httpTest.CallLog.Single().Request.Headers.Single()
                .Value.Single().Should().Be(correlationId);
            }
        }
Example #2
0
        public async Task CorrelationId_IsNotSpecifiedInRequest_Header()
        {
            using (var httpTest = new HttpTest())
            {
                // Arrange
                var baseUri = "http://localhost";
                httpTest.RespondWithJson("{}");
                var headers = new Dictionary <string, string>();

                HttpClientConfiguration.ConfigureHttpClients(() => headers);

                // Act
                await baseUri
                .GetAsync();

                // Assert
                httpTest.CallLog.Single().Request.Headers.Should().NotContain(
                    x => x.Key.Equals("X-Correlation-Id", StringComparison.OrdinalIgnoreCase));
            }
        }
Example #3
0
        public void FlurlHttpGlobalSettings_AreConfigured()
        {
            // Arrange
            var headers    = new Dictionary <string, string>();
            var testObject = new { Property = "value" };

            // Initial Assert
            FlurlHttp.GlobalSettings.BeforeCall.Should().BeNull();
            var initialSerializedTestObject = FlurlHttp.GlobalSettings
                                              .JsonSerializer.Serialize(testObject);

            initialSerializedTestObject.Should().Be("{\"Property\":\"value\"}");

            // Act
            HttpClientConfiguration.ConfigureHttpClients(() => headers);

            // Final Assert
            FlurlHttp.GlobalSettings.BeforeCall.Should().NotBeNull();
            var serializedTestObject = FlurlHttp.GlobalSettings
                                       .JsonSerializer.Serialize(testObject);

            serializedTestObject.Should().Be("{\"property\":\"value\"}");
        }