Exemplo n.º 1
0
        public void TestConfigure()
        {
            var server = new AppServer();

            var dic = new Dictionary <string, string>
            {
                { "name", "TestServer" },
                { "listeners:0:ip", "Any" },
                { "listeners:0:port", "80" },
                { "listeners:0:backLog", "100" },
                { "listeners:1:ip", "Ipv6Any" },
                { "listeners:1:port", "81" }
            };

            var builder = new ConfigurationBuilder().AddInMemoryCollection(dic);
            var config  = builder.Build();

            Assert.True(server.Configure <LinePackageInfo, LinePipelineFilter>(config));
            Assert.Equal("TestServer", server.Name);

            Assert.Equal(2, server.Listeners.Length);
            Assert.Equal(IPAddress.Any, server.Listeners[0].EndPoint.Address);
            Assert.Equal(80, server.Listeners[0].EndPoint.Port);
            Assert.Equal(IPAddress.IPv6Any, server.Listeners[1].EndPoint.Address);
            Assert.Equal(81, server.Listeners[1].EndPoint.Port);
            Assert.Equal(100, server.Listeners[0].BackLog);
            Assert.Equal(Listener.DefaultBackLog, server.Listeners[1].BackLog);
        }
Exemplo n.º 2
0
        static AppServer CreateSocketServer <TPackageInfo, TPipelineFilter>(Dictionary <string, string> configDict = null, Action <IAppSession, TPackageInfo> packageHandler = null)
            where TPackageInfo : class
            where TPipelineFilter : IPipelineFilter <TPackageInfo>, new()
        {
            if (configDict == null)
            {
                configDict = new Dictionary <string, string>
                {
                    { "name", "TestServer" },
                    { "listeners:0:ip", "Any" },
                    { "listeners:0:port", "4040" }
                };
            }

            var server = new AppServer();

            var services = new ServiceCollection();

            var builder = new ConfigurationBuilder().AddInMemoryCollection(configDict);
            var config  = builder.Build();

            services.AddSingleton(new LoggerFactory().AddConsole());
            services.AddLogging();

            RegisterServices(services);

            server.Configure <TPackageInfo, TPipelineFilter>(config, services, packageHandler);

            return(server);
        }
Exemplo n.º 3
0
        public void TestConfigureArgumentExceptions()
        {
            var server = new AppServer();

            Assert.Throws <ArgumentNullException>("config",
                                                  () => server.Configure <LinePackageInfo, LinePipelineFilter>(default(ConfigurationRoot)));
        }