public void CreateHttps_WithoutCertSettings_Throws()
        {
            string someEndpoint = "SomeTestEndpoint";

            SfConfigurationProviderHelper.SetPortVariable(someEndpoint, 8080);
            Assert.ThrowsException <ArgumentException>(() => WebEndpointInfo.CreateHttps(someEndpoint, string.Empty));
        }
        public async Task BuildStatelessWebService_RegisterListeners()
        {
            (string name, int port)httpListener1 = ("httpListener", 20080);
            (string name, int port)httpListener2 = ("httpsListener", 20443);

            SfConfigurationProviderHelper.SetPublishAddress();
            SfConfigurationProviderHelper.SetPortVariable(httpListener1.name, httpListener1.port);
            SfConfigurationProviderHelper.SetPortVariable(httpListener2.name, httpListener2.port);

            IHost host = new HostBuilder().BuildStatelessWebService <MockStartup>(
                "someService2",
                new WebEndpointInfo[]
            {
                new WebEndpointInfo(httpListener1.name, settingForCertificateCommonName: null),
                new WebEndpointInfo(httpListener2.name, settingForCertificateCommonName: null)
            });

            IListenerBuilder <OmexStatelessService>[] builders = host.Services.GetRequiredService <IEnumerable <IListenerBuilder <OmexStatelessService> > >().ToArray();
            Assert.AreEqual(2, builders.Length, "Two endpoints should be registered as listeners");
            Assert.IsTrue(builders.Any(b => b.Name == httpListener1.name), $"Listener builder for {httpListener1.name} not found");
            Assert.IsTrue(builders.Any(b => b.Name == httpListener2.name), $"Listener builder for {httpListener2.name} not found");

            await host.StartAsync();

            ICollection <string> addresses = host.Services.GetRequiredService <IServer>().Features.Get <IServerAddressesFeature>().Addresses;

            Assert.AreEqual(2, builders.Length, "Two addresses should be registered");
            Assert.IsTrue(addresses.Any(address => address.EndsWith($":{httpListener1.port}")), $"Address for {httpListener1.name} not found");
            Assert.IsTrue(addresses.Any(address => address.EndsWith($":{httpListener2.port}")), $"Address for {httpListener2.name} not found");
        }
        public void CreateHttp_SetsProperties()
        {
            string endpointName = "TestHttpEndpointName";
            int    port         = 8081;

            SfConfigurationProviderHelper.SetPortVariable(endpointName, port);

            WebEndpointInfo info = WebEndpointInfo.CreateHttp(endpointName);

            Assert.AreEqual(endpointName, info.Name);
            Assert.IsNull(info.SettingForCertificateCommonName);
            Assert.IsFalse(info.UseHttps);
            Assert.AreEqual(port, info.Port);
            Assert.AreEqual($"http://+:{port}", info.GetListenerUrl());             // lgtm[cs/non-https-url]
        }
        public void CreateHttps_SetsProperties()
        {
            string endpointName = "TestHttpsEndpointName";
            string settingForCertificateCommonName = "SomeCertName";
            int    port = 8083;

            SfConfigurationProviderHelper.SetPortVariable(endpointName, port);

            WebEndpointInfo info = WebEndpointInfo.CreateHttps(endpointName, settingForCertificateCommonName);

            Assert.AreEqual(endpointName, info.Name);
            Assert.AreEqual(settingForCertificateCommonName, info.SettingForCertificateCommonName);
            Assert.IsTrue(info.UseHttps);
            Assert.AreEqual(port, info.Port);
            Assert.AreEqual($"https://+:{port}", info.GetListenerUrl());
        }