Ejemplo n.º 1
0
        public void Update()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            ClearDb();

            using (SqlConnection conn = new SqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);
                var metadata = new EntityDefine <ProductInsert>();
                insertPipeline.AddEntity(metadata);
                insertPipeline.InitPipeline(spider);

                var data1 = new ProductInsert {
                    Sku = "110", Category = "3C", Url = "http://jd.com/110", CDate = new DateTime(2016, 8, 13)
                };
                var data2 = new ProductInsert {
                    Sku = "111", Category = "3C", Url = "http://jd.com/111", CDate = new DateTime(2016, 8, 13)
                };
                insertPipeline.Process(metadata.Name, new List <dynamic> {
                    data1, data2
                });

                SqlServerEntityPipeline updatePipeline = new SqlServerEntityPipeline(ConnectString);
                var metadat2 = new EntityDefine <ProductUpdate>();
                updatePipeline.AddEntity(metadat2);
                updatePipeline.InitPipeline(spider);

                var data3 = conn.Query <ProductUpdate>($"use test;select * from sku_{DateTime.Now.ToString("yyyy_MM_dd")} where Sku=110").First();
                data3.Category = "4C";

                updatePipeline.Process(metadat2.Name, new List <dynamic> {
                    data3
                });

                var list = conn.Query <ProductInsert>($"use test;select * from sku_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.Equal(2, list.Count);
                Assert.Equal("110", list[0].Sku);
                Assert.Equal("4C", list[0].Category);
            }

            ClearDb();
        }
Ejemplo n.º 2
0
        public void Update()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            ClearDb();

            using (SqlConnection conn = new SqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);
                var metadata = EntityDefine.Parse <ProductInsert>();
                insertPipeline.AddEntity(metadata);
                insertPipeline.InitPipeline(spider);

                DataObject data1 = new DataObject {
                    { "Sku", "110" }, { "Category", "3C" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                DataObject data2 = new DataObject {
                    { "Sku", "111" }, { "Category", "3C" }, { "Url", "http://jd.com/111" }, { "CDate", "2016-08-13" }
                };
                insertPipeline.Process(metadata.Name, new List <DataObject> {
                    data1, data2
                });

                SqlServerEntityPipeline updatePipeline = new SqlServerEntityPipeline(ConnectString);
                var metadat2 = EntityDefine.Parse <ProductUpdate>();
                updatePipeline.AddEntity(metadat2);
                updatePipeline.InitPipeline(spider);

                DataObject data3 = new DataObject {
                    { "Sku", "110" }, { "Category", "4C" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                updatePipeline.Process(metadat2.Name, new List <DataObject> {
                    data3
                });

                var list = conn.Query <ProductInsert>($"use test;select * from sku_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.Equal(2, list.Count);
                Assert.Equal("110", list[0].Sku);
                Assert.Equal("4C", list[0].Category);
            }

            ClearDb();
        }
Ejemplo n.º 3
0
        public void UpdateWhenUnionPrimaryCheckIfSameBeforeUpdate()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            ClearDb();

            using (SqlConnection conn = new SqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);
                var metadata = EntitySpider.GenerateEntityDefine(typeof(Product2).GetTypeInfo());
                insertPipeline.AddEntity(metadata);
                insertPipeline.InitPipeline(spider);

                var data1 = new DataObject {
                    { "Sku", "110" }, { "Category1", "4C" }, { "Category", "3C" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                var data2 = new DataObject {
                    { "Sku", "111" }, { "Category1", "4C" }, { "Category", "3C" }, { "Url", "http://jd.com/111" }, { "CDate", "2016-08-13" }
                };
                insertPipeline.Process(metadata.Name, new List <DataObject> {
                    data1, data2
                });

                SqlServerEntityPipeline updatePipeline = new SqlServerEntityPipeline(ConnectString, true);
                var metadata2 = EntitySpider.GenerateEntityDefine(typeof(Product2Update).GetTypeInfo());
                updatePipeline.AddEntity(EntitySpider.GenerateEntityDefine(typeof(Product2Update).GetTypeInfo()));
                updatePipeline.InitPipeline(spider);

                var data3 = new DataObject {
                    { "Sku", "110" }, { "Category1", "4C" }, { "Category", "AAAA" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                updatePipeline.Process(metadata2.Name, new List <DataObject> {
                    data3
                });

                var list = conn.Query <Product2>($"use test;select * from sku2_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.Equal(2, list.Count);
                Assert.Equal("110", list[0].Sku);
                Assert.Equal("AAAA", list[0].Category);
            }

            ClearDb();
        }
        public void Update()
        {
            ClearDb();

            using (SqlConnection conn = new SqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);
                var metadata = EntitySpider.GenerateEntityMetaData(typeof(ProductInsert).GetTypeInfo());
                insertPipeline.AddEntity(metadata);
                insertPipeline.InitPipeline(spider);

                JObject data1 = new JObject {
                    { "Sku", "110" }, { "Category", "3C" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                JObject data2 = new JObject {
                    { "Sku", "111" }, { "Category", "3C" }, { "Url", "http://jd.com/111" }, { "CDate", "2016-08-13" }
                };
                insertPipeline.Process(metadata.Name, new List <JObject> {
                    data1, data2
                });

                SqlServerEntityPipeline updatePipeline = new SqlServerEntityPipeline(ConnectString);
                var metadat2 = EntitySpider.GenerateEntityMetaData(typeof(ProductUpdate).GetTypeInfo());
                updatePipeline.AddEntity(metadat2);
                updatePipeline.InitPipeline(spider);

                JObject data3 = new JObject {
                    { "Sku", "110" }, { "Category", "4C" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                updatePipeline.Process(metadat2.Name, new List <JObject> {
                    data3
                });

                var list = conn.Query <ProductInsert>($"use test;select * from sku_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.AreEqual(2, list.Count);
                Assert.AreEqual("110", list[0].Sku);
                Assert.AreEqual("4C", list[0].Category);
            }

            ClearDb();
        }
Ejemplo n.º 5
0
        public void Insert()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            ClearDb();

            using (SqlConnection conn = new SqlConnection(ConnectString))
            {
                ISpider spider = new DefaultSpider("test", new Site());

                SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);
                var metadata = EntitySpider.GenerateEntityDefine(typeof(ProductInsert).GetTypeInfo());
                insertPipeline.AddEntity(EntitySpider.GenerateEntityDefine(typeof(ProductInsert).GetTypeInfo()));
                insertPipeline.InitPipeline(spider);

                // Common data
                var data1 = new DataObject {
                    { "Sku", "110" }, { "Category", "3C" }, { "Url", "http://jd.com/110" }, { "CDate", "2016-08-13" }
                };
                var data2 = new DataObject {
                    { "Sku", "111" }, { "Category", "3C" }, { "Url", "http://jd.com/111" }, { "CDate", "2016-08-13" }
                };
                // Value is null
                var data3 = new DataObject {
                    { "Sku", "112" }, { "Category", null }, { "Url", "http://jd.com/111" }, { "CDate", "2016-08-13" }
                };
                insertPipeline.Process(metadata.Name, new List <DataObject> {
                    data1, data2, data3
                });

                var list = conn.Query <ProductInsert>($"use test;select * from sku_{DateTime.Now.ToString("yyyy_MM_dd")}").ToList();
                Assert.Equal(3, list.Count);
                Assert.Equal("110", list[0].Sku);
                Assert.Equal("111", list[1].Sku);
                Assert.Null(list[2].Category);
            }

            ClearDb();
        }