Ejemplo n.º 1
0
        public void GetXmlConfigEndpoint_WithEmptyEndpointTest()
        {
            string xml = $@"
<configuration> 
    <system.serviceModel>
        <services>
            <service name=""{typeof(SomeService).FullName}"">
                  <endpoint address=""expectedAddress""
                          name=""expectedEndpointName""
                          binding=""netTcpBinding""                       
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    Assert.Throws <EndpointNotFoundException>(() => GetXmlConfigEndpointByEndpointName(settingHolder, string.Empty));
                }
            }
        }
Ejemplo n.º 2
0
        public void ResolveBinding_WithUnknownBindingTest()
        {
            string xml = $@"
<configuration> 
    <system.serviceModel>
        <services>
            <service name=""{typeof(SomeService).FullName}"">
                  <endpoint address=""expectedAddress""
                          name=""expectedEndpointName""
                          binding=""netTcpBinding""                       
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    Assert.Throws <BindingNotFoundException>(() => settingHolder.ResolveBinding(nameof(NetTcpBinding), "unknown"));
                }
            }
        }
Ejemplo n.º 3
0
        public ConfigurationManagerServiceModelOptions(IServiceProvider builder, string path)
        {
            _holder = builder.GetRequiredService <IConfigurationHolder>();

            _section = new Lazy <ServiceModelSectionGroup>(() =>
            {
                var assembly = Assembly.GetEntryAssembly();
                var basePath = string.IsNullOrEmpty(assembly?.Location) ? AppContext.BaseDirectory : Path.GetDirectoryName(assembly.Location);

                // hack - in .net core 2.1 on linux directory not correct(on unit tests),
                // for example:
                // /home/vsts/.nuget/packages/microsoft.testplatform.testhost/16.7.1/lib/netcoreapp2.1/
                var isNetCore21 = RuntimeInformation.FrameworkDescription.Contains(".NET Core 4.6");
                if (isNetCore21 && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    basePath = AppContext.BaseDirectory;
                }

                var configMap = new ExeConfigurationFileMap(Path.Combine(basePath, "CoreWCF.machine.config"))
                {
                    ExeConfigFilename = path
                };
                System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
                var section = ServiceModelSectionGroup.GetSectionGroup(configuration);

                if (section is null)
                {
                    throw new ServiceModelConfigurationException("Section not found");
                }

                return(section);
            }, true);
        }
Ejemplo n.º 4
0
        public void CreateDefaultBindingTest()
        {
            string expectedAddress      = "net.tcp://*****:*****@"
<configuration> 
    <system.serviceModel>
        <services>
            <service name=""{expectedServiceName}"">
                  <endpoint address=""{expectedAddress}""
                          name=""{expectedEndpointName}""
                          binding=""netTcpBinding""                       
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);
                    IXmlConfigEndpoint   endpoint      = GetXmlConfigEndpointByEndpointName(settingHolder, expectedEndpointName);
                    Assert.Equal(expectedServiceName, endpoint.Service.FullName);
                    Assert.IsType <NetTcpBinding>(endpoint.Binding);
                    Assert.Equal("NetTcpBinding", endpoint.Binding.Name);
                }
            }
        }
Ejemplo n.º 5
0
        protected static IConfigurationHolder GetConfigurationHolder(ServiceProvider provider)
        {
            IConfigureOptions <ServiceModelOptions> options = provider.GetRequiredService <IConfigureOptions <ServiceModelOptions> >();

            options.Configure(new ServiceModelOptions());
            IConfigurationHolder settingHolder = provider.GetService <IConfigurationHolder>();

            return(settingHolder);
        }
Ejemplo n.º 6
0
        public void MultipleServiceTestWithSecurityMode()
        {
            string expectedServiceName              = typeof(SomeService).FullName;
            string expectedContractName             = typeof(ISomeService).FullName;
            string expectedNetTCPAddress            = "net.tcp://*****:*****@"
<configuration> 
    <system.serviceModel>
        <bindings>         
            <netTcpBinding>
                <binding name=""testBinding"">
                 <security mode=""None"" />
                 </binding>
            </netTcpBinding>
         <basicHttpBinding>
        <binding name=""Basic"">
          <security mode=""TransportWithMessageCredential"">
             <message clientCredentialType=""Certificate""/>
            </security >
          </binding >
        </basicHttpBinding >
          </bindings> 
        <services>            
            <service name=""{expectedServiceName}"">
                <endpoint address=""{expectedNetTCPAddress}""
                          binding=""netTcpBinding""
                          bindingConfiguration=""testBinding""
                          contract=""{expectedContractName}"" />
                <endpoint address=""{expectedBasicHttpAddress}""
                          name=""{expectedEndpointNameForBasicHttp}""
                          binding=""netTcpBinding""
                          bindingConfiguration=""testBinding""
                          contract=""{expectedContractName}"" />
            </service>
        </services>                             
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);
                    IXmlConfigEndpoint   endpoint      = GetXmlConfigEndpointByEndpointName(settingHolder, expectedEndpointNameForBasicHttp);
                    Assert.Equal(expectedServiceName, endpoint.Service.FullName);
                    Assert.Equal(expectedContractName, endpoint.Contract.FullName);
                    Assert.Equal(expectedBasicHttpAddress, endpoint.Address.AbsoluteUri);

                    endpoint = GetXmlConfigEndpointByEndpointName(settingHolder, string.Empty);
                    Assert.Equal(expectedServiceName, endpoint.Service.FullName);
                    Assert.Equal(expectedContractName, endpoint.Contract.FullName);
                    Assert.Equal(expectedNetTCPAddress, endpoint.Address.AbsoluteUri);
                }
            }
        }
Ejemplo n.º 7
0
 //Limiting this logic for test purpose.
 protected static IXmlConfigEndpoint GetXmlConfigEndpointByEndpointName(IConfigurationHolder configHolder, string name)
 {
     foreach (var serviceEndPoint in configHolder.Endpoints)
     {
         if (string.Compare(serviceEndPoint.Name, name, true) == 0)
         {
             return(configHolder.GetXmlConfigEndpoint(serviceEndPoint));
         }
     }
     throw new EndpointNotFoundException();
 }
Ejemplo n.º 8
0
        public void BasicHttpBinding_WithCustomSetting()
        {
            string   expectedName = "basicHttpBindingConfig";
            long     expectedMaxReceivedMessageSize = 1073741824;
            long     expectedMaxBufferSize          = 1073741824;
            int      expectedMaxDepth       = 2147483647;
            TimeSpan expectedReceiveTimeout = TimeSpan.FromMinutes(10);
            TimeSpan expectedDefaultTimeout = TimeSpan.FromMinutes(1);
            BasicHttpSecurityMode          expectedSecurityMode = BasicHttpSecurityMode.TransportWithMessageCredential;
            BasicHttpMessageCredentialType clientCredType       = BasicHttpMessageCredentialType.Certificate;

            string xml = $@"
<configuration> 
    <system.serviceModel>         
        <bindings>         
            <basicHttpBinding>
                <binding name=""{expectedName}""
                         maxReceivedMessageSize=""{expectedMaxReceivedMessageSize}""
                         maxBufferSize=""{expectedMaxBufferSize}""
                         receiveTimeout=""00:10:00"">
                    <security mode=""{expectedSecurityMode}"">
                     <message clientCredentialType=""{clientCredType}"" />
                     </security>
                    <readerQuotas maxDepth=""{expectedMaxDepth}"" />   
                </binding >
            </basicHttpBinding>                             
        </bindings>                             
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    var actualBinding = settingHolder.ResolveBinding(nameof(BasicHttpBinding), expectedName) as BasicHttpBinding;
                    Assert.Equal(expectedName, actualBinding.Name);
                    Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                    Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.CloseTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.OpenTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.SendTimeout);
                    Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                    Assert.Equal(TransferMode.Buffered, actualBinding.TransferMode);
                    Assert.Equal(expectedSecurityMode, actualBinding.Security.Mode);
                    Assert.Equal(clientCredType, actualBinding.Security.Message.ClientCredentialType);
                    Assert.Equal(expectedMaxDepth, actualBinding.ReaderQuotas.MaxDepth);
                }
            }
        }
Ejemplo n.º 9
0
        public void NetTcpBinding_WithDefaultSetting()
        {
            string   expectedName = "netTcpBindingConfig";
            long     expectedMaxReceivedMessageSize = 65536;
            long     expectedMaxBufferSize          = 65536;
            TimeSpan expectedReceiveTimeout         = TimeSpan.FromMinutes(10);
            TimeSpan expectedDefaultTimeout         = TimeSpan.FromMinutes(1);

            string xml = $@"
<configuration> 
    <system.serviceModel>         
        <bindings>         
            <netTcpBinding>
                <binding name=""{expectedName}""/>
            </netTcpBinding>                             
        </bindings>                             
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    var actualBinding = settingHolder.ResolveBinding(nameof(NetTcpBinding), expectedName) as NetTcpBinding;
                    Assert.Equal(expectedName, actualBinding.Name);
                    Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                    Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.CloseTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.OpenTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.SendTimeout);
                    Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                    Assert.Equal(TransferMode.Buffered, actualBinding.TransferMode);
                    Assert.Equal(SecurityMode.Transport, actualBinding.Security.Mode);
                }
            }
        }
        public SpecFlowConfiguration Load(SpecFlowConfiguration specFlowConfiguration, IConfigurationHolder configurationHolder)
        {
            switch (configurationHolder.ConfigSource)
            {
            case ConfigSource.AppConfig:
                return(LoadAppConfig(specFlowConfiguration,
                                     ConfigurationSectionHandler.CreateFromXml(configurationHolder.Content)));

            case ConfigSource.Json:
                return(LoadJson(specFlowConfiguration, configurationHolder.Content));

            case ConfigSource.Default:
                return(GetDefault());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 11
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     ServiceProvider      sp          = CreateProvider();
     IConfigurationHolder configHOlde = GetConfigurationHolder(sp);
 }
Ejemplo n.º 12
0
 public static ApiVersionDataProvider GetApiVersionDataProvider(this IConfigurationHolder holder)
 {
     return(holder.DataProviders.ApiVersionDataProvider);
 }
Ejemplo n.º 13
0
 public static ProjectDataProvider GetProjectDataProvider(this IConfigurationHolder holder)
 {
     return(holder.DataProviders.ProjectDataProvider);
 }