Exemplo n.º 1
0
        public void EnvSetNull()
        {
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-c:" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.LoadConfiguration(arguments1);
        }
Exemplo n.º 2
0
        public void EnvSetPipeline()
        {
            lock (TestBase.Locker)
            {
                if (File.Exists(Env.GlobalAppConfigPath))
                {
                    File.Delete(Env.GlobalAppConfigPath);
                }
                File.Copy("app.global.config", Env.GlobalAppConfigPath);

                var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-e:DBCONFIG=GLOBAL" };
                var arguments1 = Startup.AnalyzeArguments(args1);
                Startup.SetEnviroment(arguments1);

                Env.Reload();

                MySqlEntityPipeline pipeline = new MySqlEntityPipeline();
                var a = pipeline.ConnectionStringSettings;
                Assert.Equal("Database='mysql';Data Source=192.168.90.100;User ID=user20170913;Password=KenTYDrZJOeUEvlP3NE&$pouzrk6gXD#;Port=53306;SslMode=None", a.ConnectionString);
                Assert.Equal("127.0.0.1:6379,serviceName=DotnetSpider,keepAlive=8,allowAdmin=True,connectTimeout=10000,abortConnect=True,connectRetry=20", Env.RedisConnectString);

                AppDomain.CurrentDomain.SetData("CONFIG", "");
                AppDomain.CurrentDomain.SetData("DBCONFIG", "");
            }
        }
Exemplo n.º 3
0
        public void EnvSetGloablAppMissingPipeline()
        {
            try
            {
                if (File.Exists(Env.GlobalAppConfigPath))
                {
                    File.Delete(Env.GlobalAppConfigPath);
                }
                var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-e:DBCONFIG=GLOBAL" };
                var arguments1 = Startup.AnalyzeArguments(args1);


                Assert.Throws <SpiderException>(() =>
                {
                    Startup.SetEnviroment(arguments1);

                    Env.Reload();

                    MySqlEntityPipeline pipeline = new MySqlEntityPipeline();
                    var a = pipeline.ConnectionStringSettings;
                });
            }
            finally
            {
                AppDomain.CurrentDomain.SetData("CONFIG", "");
                AppDomain.CurrentDomain.SetData("DBCONFIG", "");
            }
        }
Exemplo n.º 4
0
        public void DetectCorrectSpiderCount()
        {
            var args        = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid", "-a:" };
            var arguments   = Startup.AnalyzeArguments(args);
            var spiderTypes = Startup.DetectSpiders();

            Assert.Equal(2, spiderTypes.Count);
        }
Exemplo n.º 5
0
        public void SetGuidIdentity()
        {
            var args        = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid", "-a:" };
            var arguments   = Startup.AnalyzeArguments(args);
            var spiderTypes = Startup.DetectSpiders();
            var spider      = (TestSpider)Startup.CreateSpiderInstance("DotnetSpider.Core.Test.TestSpider", arguments, spiderTypes);

            Guid.Parse(spider.Identity);
        }
Exemplo n.º 6
0
        public void SetIdentity()
        {
            var args        = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:WHAT", "-a:" };
            var arguments   = Startup.AnalyzeArguments(args);
            var spiderTypes = Startup.DetectSpiders();
            var spider      = (TestSpider)Startup.CreateSpiderInstance("DotnetSpider.Core.Test.TestSpider", arguments, spiderTypes);

            Assert.Equal("WHAT", spider.Identity);
        }
Exemplo n.º 7
0
        public void SetReportArgument()
        {
            var args        = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-n:What", "-i:guid", "-a:report" };
            var arguments   = Startup.AnalyzeArguments(args);
            var spiderTypes = Startup.DetectSpiders();
            var spider      = (TestSpider)Startup.CreateSpiderInstance("DotnetSpider.Core.Test.TestSpider", arguments, spiderTypes);

            Assert.Equal(1000, spider.EmptySleepTime);
        }
Exemplo n.º 8
0
        public void SetSpiderName()
        {
            var args        = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-n:What", "-i:guid", "-a:" };
            var arguments   = Startup.AnalyzeArguments(args);
            var spiderTypes = Startup.DetectSpiders();
            var spider      = (TestSpider)Startup.CreateSpiderInstance("DotnetSpider.Core.Test.TestSpider", arguments, spiderTypes);

            Assert.Equal("What", spider.Name);
        }
Exemplo n.º 9
0
 public void EnvSetNull()
 {
     lock (TestBase.Locker)
     {
         var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-e:" };
         var arguments1 = Startup.AnalyzeArguments(args1);
         Startup.SetEnviroment(arguments1);
     }
 }
Exemplo n.º 10
0
        public void EnvSet()
        {
            if (File.Exists(Env.DefaultGlobalAppConfigPath))
            {
                File.Delete(Env.DefaultGlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.DefaultGlobalAppConfigPath);
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-c:%GLOBAL%" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.LoadConfiguration(arguments1);
        }
Exemplo n.º 11
0
        public void DefaultConfig()
        {
            if (File.Exists(Env.DefaultGlobalAppConfigPath))
            {
                File.Delete(Env.DefaultGlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.DefaultGlobalAppConfigPath);
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-c:%GLOBAL%" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.LoadConfiguration(arguments1);
            Env.Reload();
            Assert.Equal("Database='mysql';Data Source=localhost;User ID=root;Port=3306;SslMode=None;", Env.DataConnectionString);
        }
Exemplo n.º 12
0
        public void DefaultConfig()
        {
            if (File.Exists(Env.DefaultGlobalAppConfigPath))
            {
                File.Delete(Env.DefaultGlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.DefaultGlobalAppConfigPath);
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-c:%GLOBAL%app.config" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.LoadConfiguration(arguments1);
            Assert.Equal("Database='mysql';Data Source=192.168.90.100;User ID=user20170913;Password=KenTYDrZJOeUEvlP3NE&$pouzrk6gXD#;Port=53306;SslMode=None", Env.DataConnectionString);
            Env.LoadConfiguration();
            Assert.Equal("Database='mysql';Data Source=localhost;User ID=root;Port=3306;SslMode=None;", Env.DataConnectionString);
        }
Exemplo n.º 13
0
        public void EnvSet()
        {
            if (File.Exists(Env.GlobalAppConfigPath))
            {
                File.Delete(Env.GlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.GlobalAppConfigPath);
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-e:DBCONFIG=GLOBAL" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.SetEnviroment(arguments1);

            Assert.Equal("GLOBAL", AppDomain.CurrentDomain.GetData(Env.EnvDbConfig)?.ToString());

            AppDomain.CurrentDomain.SetData("CONFIG", "");
            AppDomain.CurrentDomain.SetData("DBCONFIG", "");
        }
Exemplo n.º 14
0
        public void EnvSetGloablAppMissingPipeline()
        {
            if (File.Exists(Env.DefaultGlobalAppConfigPath))
            {
                File.Delete(Env.DefaultGlobalAppConfigPath);
            }
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-c:%GLOBAL%" };
            var arguments1 = Startup.AnalyzeArguments(args1);


            Assert.Throws <SpiderException>(() =>
            {
                Startup.LoadConfiguration(arguments1);

                Env.Reload();

                MySqlEntityPipeline pipeline = new MySqlEntityPipeline();
                var a = pipeline.ConnectionStringSettings;
            });
        }
Exemplo n.º 15
0
        public void DefaultConfig()
        {
            if (File.Exists(Env.GlobalAppConfigPath))
            {
                File.Delete(Env.GlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.GlobalAppConfigPath);
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-e:" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.SetEnviroment(arguments1);
            Env.Reload();
            Assert.Null(AppDomain.CurrentDomain.GetData(Env.EnvDbConfig)?.ToString());
            Assert.Null(AppDomain.CurrentDomain.GetData(Env.EnvConfig)?.ToString());

            Assert.Equal("Database='mysql';Data Source=localhost;User ID=root;Port=3306;SslMode=None;", Env.DataConnectionString);

            AppDomain.CurrentDomain.SetData("CONFIG", "");
            AppDomain.CurrentDomain.SetData("DBCONFIG", "");
        }
Exemplo n.º 16
0
        public void InsideConfig()
        {
            if (File.Exists(Env.GlobalAppConfigPath))
            {
                File.Delete(Env.GlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.GlobalAppConfigPath);
            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-e:CONFIG=app.inside.config,DBCONFIG=GLOBAL" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.SetEnviroment(arguments1);
            Env.Reload();
            Assert.Equal("GLOBAL", AppDomain.CurrentDomain.GetData(Env.EnvDbConfig)?.ToString());
            Assert.Equal("app.inside.config", AppDomain.CurrentDomain.GetData(Env.EnvConfig)?.ToString());

            Assert.Equal("Database='mysql';Data Source=192.168.90.100;User ID=user20170913;Password=KenTYDrZJOeUEvlP3NE&$pouzrk6gXD#;Port=53306;SslMode=None", Env.DataConnectionString);
            Assert.Equal("INSITE:6379,serviceName=DotnetSpider,keepAlive=8,allowAdmin=True,connectTimeout=10000,abortConnect=True,connectRetry=20", Env.RedisConnectString);

            AppDomain.CurrentDomain.SetData("CONFIG", "");
            AppDomain.CurrentDomain.SetData("DBCONFIG", "");
        }
Exemplo n.º 17
0
        public void EnvSetPipeline()
        {
            if (File.Exists(Env.DefaultGlobalAppConfigPath))
            {
                File.Delete(Env.DefaultGlobalAppConfigPath);
            }
            File.Copy(Path.Combine(AppContext.BaseDirectory, "app.global.config"), Env.DefaultGlobalAppConfigPath);

            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:", "-c:%GLOBAL%" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.LoadConfiguration(arguments1);

            MySqlEntityPipeline pipeline = new MySqlEntityPipeline();
            var a = pipeline.ConnectionStringSettings;

            Assert.Equal("Database='mysql';Data Source=192.168.90.101;User ID=user20170913;Password=KenTYDrZJOeUEvlP3NE&$pouzrk6gXD#;Port=53306;SslMode=None", a.ConnectionString);
            Assert.Equal("127.0.0.101:6379,serviceName=DotnetSpider,keepAlive=8,allowAdmin=True,connectTimeout=10000,abortConnect=True,connectRetry=20", Env.RedisConnectString);

            Env.Reload();
        }
Exemplo n.º 18
0
        public void AnalyzeUnCorrectArguments()
        {
            var args1      = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid", "-a:", "abcd" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Assert.Null(arguments1);

            var args2      = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid", "-a::::" };
            var arguments2 = Startup.AnalyzeArguments(args2);

            Assert.Null(arguments2);

            var args6      = new[] { "-s:DotnetSpider.Core.Test.TestSpider" };
            var arguments6 = Startup.AnalyzeArguments(args6);

            Assert.Null(arguments6);

            var args3      = new[] { "-ti:DotnetSpider.Core.Test.TestSpider" };
            var arguments3 = Startup.AnalyzeArguments(args3);

            Assert.Null(arguments3);
        }
Exemplo n.º 19
0
        public void EnvUnSetPipeline()
        {
            if (File.Exists(Env.GlobalAppConfigPath))
            {
                File.Delete(Env.GlobalAppConfigPath);
            }
            File.Copy("app.global.config", Env.GlobalAppConfigPath);

            var args1      = new[] { "-s:DotnetSpider.Extension.Test.Pipeline.TestSpider2", "-tid:TestSpider", "-i:guid", "-a:" };
            var arguments1 = Startup.AnalyzeArguments(args1);

            Startup.SetEnviroment(arguments1);

            Env.Reload();

            MySqlEntityPipeline pipeline = new MySqlEntityPipeline();
            var a = pipeline.ConnectionStringSettings;

            Assert.Equal("Database='mysql';Data Source=localhost;User ID=root;Port=3306;SslMode=None;", a.ConnectionString);

            AppDomain.CurrentDomain.SetData("CONFIG", "");
            AppDomain.CurrentDomain.SetData("DBCONFIG", "");
        }
Exemplo n.º 20
0
        public void AnalyzeArguments()
        {
            var args      = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid", "-a:", "-n:myname" };
            var arguments = Startup.AnalyzeArguments(args);

            Assert.Equal(5, arguments.Count);
            Assert.Equal("DotnetSpider.Core.Test.TestSpider", arguments["-s"]);
            Assert.Equal("TestSpider", arguments["-tid"]);
            Assert.Equal("guid", arguments["-i"]);
            Assert.Equal("myname", arguments["-n"]);
            Assert.Equal("", arguments["-a"]);

            var args3      = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid", "-a:    asdf" };
            var arguments3 = Startup.AnalyzeArguments(args3);

            Assert.Equal(4, arguments3.Count);
            Assert.Equal("asdf", arguments3["-a"]);

            var args4      = new[] { "-s:DotnetSpider.Core.Test.TestSpider", "-tid:TestSpider", "-i:guid" };
            var arguments4 = Startup.AnalyzeArguments(args4);

            Assert.Equal(3, arguments4.Count);
            Assert.Equal("TestSpider", arguments4["-tid"]);
        }