public static IEndpoint AddSecureWSHttpEndpoint(this IServiceHostConfigurator configurator, Type contract, HttpEndpointAddress address, Action <WSHttpBinding> configureBinding = null) { if (configurator is null) { throw new ArgumentNullException(nameof(configurator)); } if (contract is null) { throw new ArgumentNullException(nameof(contract)); } if (address is null) { throw new ArgumentNullException(nameof(address)); } var secureAddress = new HttpEndpointAddress { Host = address.Host, IsSecure = true, Path = address.Path, Port = address.Port }; return(configurator.AddWSHttpEndpoint(contract, secureAddress, ConfigureBinding)); void ConfigureBinding(WSHttpBinding binding) { binding.UseHttps(); configureBinding?.Invoke(binding); } }
public static HttpEndpointAddress UseECS(this HttpEndpointAddress endpointAddress, IConfiguration configuration, Action <ECSContainerMetadataOptions> configureOptions = null) { if (Environment.GetEnvironmentVariable(EMG.Extensions.Configuration.ECSMetadataExtensions.ECSContainerMetadataFileKey) == null) { return(endpointAddress); } var containerMetadata = configuration.Get <ECSContainerMetadata>(); if (containerMetadata == null) { return(endpointAddress); } var options = new ECSContainerMetadataOptions(); configureOptions?.Invoke(options); var portMapping = options.PortMappingSelector(containerMetadata.PortMappings); if (portMapping == null) { return(endpointAddress); } return(EndpointAddress.ForHttp(containerMetadata.HostPrivateIPv4Address, endpointAddress.Path, portMapping.HostPort, endpointAddress.IsSecure)); }
public void UseECS_uses_selected_port_mapping(HttpEndpointAddress endpointAddress, IConfiguration configuration, PortMapping mapping) { AddFakeContainerMetadataFileKey(); var newEndpoint = ECSMetadataExtensions.UseECS(endpointAddress, configuration, options => options.PortMappingSelector = items => mapping); Assert.That(newEndpoint.Port, Is.EqualTo(mapping.HostPort)); }
public void UseECS_uses_configureOptions(HttpEndpointAddress endpointAddress, IConfiguration configuration, Action <ECSContainerMetadataOptions> configureOptions) { AddFakeContainerMetadataFileKey(); ECSMetadataExtensions.UseECS(endpointAddress, configuration, configureOptions); Mock.Get(configureOptions).Verify(p => p(It.IsAny <ECSContainerMetadataOptions>()), Times.Once()); }
public void UseECS_returns_same_address_if_port_mapping_is_null(HttpEndpointAddress endpointAddress, IConfiguration configuration) { AddFakeContainerMetadataFileKey(); var newEndpoint = ECSMetadataExtensions.UseECS(endpointAddress, configuration, options => options.PortMappingSelector = list => null); Assert.That(newEndpoint, Is.SameAs(endpointAddress)); }
public static HttpEndpointAddress UseECS(this HttpEndpointAddress endpointAddress, IConfiguration configuration) { if (Environment.GetEnvironmentVariable("ECS_CONTAINER_METADATA_FILE") == null) { return(endpointAddress); } var containerMetadata = configuration.Get <ECSContainerMetadata>(); return(EndpointAddress.ForHttp(containerMetadata.HostPrivateIPv4Address, endpointAddress.Path, containerMetadata.PortMappings[0].HostPort, endpointAddress.IsSecure)); }
public void Valid_URI_can_be_cast_to_EndpointAddress(HttpEndpointAddress testAddress) { var testUri = testAddress.ToUri(); HttpEndpointAddress address = testUri; Assert.That(address.Host, Is.EqualTo(testAddress.Host).IgnoreCase); Assert.That(address.Port, Is.EqualTo(testAddress.Port)); Assert.That(address.Path, Is.EqualTo(testAddress.Path).IgnoreCase); Assert.That(address.IsSecure, Is.EqualTo(testAddress.IsSecure)); }
public void ParseFromUri_returns_EndpointAddress(HttpEndpointAddress testAddress) { var testUri = testAddress.ToUri(); var address = HttpEndpointAddress.ParseFromUri(testUri); Assert.That(address.Host, Is.EqualTo(testAddress.Host).IgnoreCase); Assert.That(address.Port, Is.EqualTo(testAddress.Port)); Assert.That(address.Path, Is.EqualTo(testAddress.Path).IgnoreCase); Assert.That(address.IsSecure, Is.EqualTo(testAddress.IsSecure)); }
public void GetBasicHttpEndpointAddress_can_return_endpoint(ConfigurationBuilder builder, HttpEndpointAddress testAddress) { var configuration = builder.AddInMemoryCollection(new Dictionary <string, string>() { ["Host"] = testAddress.Host, ["Port"] = testAddress.Port.ToString(), ["Path"] = testAddress.Path }).Build(); Uri result = ConfigurationExtensions.GetBasicHttpEndpointAddress(configuration); Assert.That(result.Scheme, Is.EqualTo(Uri.UriSchemeHttp)); Assert.That(result.Host, Is.EqualTo(testAddress.Host).IgnoreCase); Assert.That(result.Port, Is.EqualTo(testAddress.Port)); Assert.That(result.AbsolutePath, Is.EqualTo("/" + testAddress.Path).IgnoreCase); }
public static IEndpoint AddWSHttpEndpoint(this IServiceHostConfigurator configurator, Type contract, HttpEndpointAddress address, Action <WSHttpBinding> configureBinding = null) => configurator.AddEndpoint(contract, address, configureBinding);
public void ToString_returns_formed_Uri(HttpEndpointAddress testAddress) { Assert.That(testAddress.ToString(), Is.EqualTo($"Address: {testAddress.ToUri()}")); }
public void ParseFromUri_throws_if_uri_is_null(HttpEndpointAddress _) { Assert.Throws <ArgumentNullException>(() => HttpEndpointAddress.ParseFromUri(null)); }
public void ParseFromUri_throws_if_invalid_scheme(HttpEndpointAddress testAddress, string invalidScheme) { var testUri = new UriBuilder(invalidScheme, testAddress.Host, testAddress.Port, testAddress.Path).Uri; Assert.Throws <ArgumentException>(() => HttpEndpointAddress.ParseFromUri(testUri)); }
public void UseECS_returns_same_address_if_metadata_not_found_in_configuration(HttpEndpointAddress endpointAddress, ConfigurationBuilder configurationBuilder) { AddFakeContainerMetadataFileKey(); var newEndpoint = ECSMetadataExtensions.UseECS(endpointAddress, configurationBuilder.Build()); Assert.That(newEndpoint, Is.SameAs(endpointAddress)); }
public void AddWSHttpEndpoint_forwards_to_configurator(IServiceHostConfigurator configurator, Action <WSHttpBinding> testDelegate, HttpEndpointAddress address) { configurator.AddWSHttpEndpoint(typeof(ITestService), address, testDelegate); Mock.Get(configurator).Verify(p => p.AddEndpoint <WSHttpBinding>(typeof(ITestService), address, testDelegate)); }
public void UseECS_returns_same_address_if_ECSContainerMetadataFileKey_not_available(HttpEndpointAddress endpointAddress, IConfiguration configuration) { var newEndpoint = ECSMetadataExtensions.UseECS(endpointAddress, configuration); Assert.That(newEndpoint, Is.SameAs(endpointAddress)); }
public void UseECS_returns_private_IPV4_address([Frozen] ECSContainerMetadata metadata, HttpEndpointAddress endpointAddress, IConfiguration configuration, Action <ECSContainerMetadataOptions> configureOptions) { AddFakeContainerMetadataFileKey(); var newEndpoint = ECSMetadataExtensions.UseECS(endpointAddress, configuration, configureOptions); Assert.That(newEndpoint.Host, Is.EqualTo(metadata.HostPrivateIPv4Address)); }