Ejemplo n.º 1
0
        public void DefineUpdateEntity()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);

            try
            {
                insertPipeline.AddEntity(new EntityDefine <UpdateEntity1>());
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.Equal("Columns set as unique are not a property of your entity.", e.Message);
            }

            try
            {
                insertPipeline.AddEntity(new EntityDefine <UpdateEntity2>());
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.Equal("Columns set to update are not a property of your entity.", e.Message);
            }

            try
            {
                insertPipeline.AddEntity(new EntityDefine <UpdateEntity3>());
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.Equal("There is no column need update.", e.Message);
            }
            var metadata = new EntityDefine <UpdateEntity4>();

            insertPipeline.AddEntity(metadata);
            Assert.Single(insertPipeline.GetUpdateColumns(metadata.Name));
            Assert.Equal("Value", insertPipeline.GetUpdateColumns(metadata.Name).First());

            SqlServerEntityPipeline insertPipeline2 = new SqlServerEntityPipeline(ConnectString);
            var metadata2 = new EntityDefine <UpdateEntity5>();

            insertPipeline2.AddEntity(metadata2);
            var columns = insertPipeline2.GetUpdateColumns(metadata2.Name);

            Assert.Equal(2, columns.Length);
            Assert.Equal("Value", columns[0]);
            Assert.Equal("Key", columns[1]);
        }
Ejemplo n.º 2
0
        public void DefineUpdateEntity()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);

            try
            {
                insertPipeline.AddEntity(EntitySpider.GenerateEntityDefine(typeof(UpdateEntity1).GetTypeInfo()));
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.Equal("Columns set as primary is not a property of your entity.", e.Message);
            }

            try
            {
                insertPipeline.AddEntity(EntitySpider.GenerateEntityDefine(typeof(UpdateEntity2).GetTypeInfo()));
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.Equal("Columns set as update is not a property of your entity.", e.Message);
            }

            try
            {
                insertPipeline.AddEntity(EntitySpider.GenerateEntityDefine(typeof(UpdateEntity3).GetTypeInfo()));
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.Equal("There is no column need update.", e.Message);
            }
            var metadata = EntitySpider.GenerateEntityDefine(typeof(UpdateEntity4).GetTypeInfo());

            insertPipeline.AddEntity(EntitySpider.GenerateEntityDefine(typeof(UpdateEntity4).GetTypeInfo()));
            Assert.Single(insertPipeline.GetUpdateColumns(metadata.Name));
            Assert.Equal("Value", insertPipeline.GetUpdateColumns(metadata.Name).First());

            SqlServerEntityPipeline insertPipeline2 = new SqlServerEntityPipeline(ConnectString);
            var metadata2 = EntitySpider.GenerateEntityDefine(typeof(UpdateEntity5).GetTypeInfo());

            insertPipeline2.AddEntity(metadata2);
            Assert.Single(insertPipeline2.GetUpdateColumns(metadata2.Name));
            Assert.Equal("Value", insertPipeline2.GetUpdateColumns(metadata2.Name).First());
        }
        public void DefineUpdateEntity()
        {
            SqlServerEntityPipeline insertPipeline = new SqlServerEntityPipeline(ConnectString);

            try
            {
                insertPipeline.AddEntity(EntitySpider.GenerateEntityMetaData(typeof(UpdateEntity1).GetTypeInfo()));
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.AreEqual("Columns set as Primary is not a property of your entity.", e.Message);
            }

            try
            {
                insertPipeline.AddEntity(EntitySpider.GenerateEntityMetaData(typeof(UpdateEntity2).GetTypeInfo()));
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.AreEqual("Columns set as update is not a property of your entity.", e.Message);
            }

            try
            {
                insertPipeline.AddEntity(EntitySpider.GenerateEntityMetaData(typeof(UpdateEntity3).GetTypeInfo()));
                throw new SpiderException("TEST FAILED.");
            }
            catch (SpiderException e)
            {
                Assert.AreEqual("There is no column need update.", e.Message);
            }
            var metadata = EntitySpider.GenerateEntityMetaData(typeof(UpdateEntity4).GetTypeInfo());

            insertPipeline.AddEntity(EntitySpider.GenerateEntityMetaData(typeof(UpdateEntity4).GetTypeInfo()));
            Assert.AreEqual(1, insertPipeline.GetUpdateColumns(metadata.Name).Length);
            Assert.AreEqual("Value", insertPipeline.GetUpdateColumns(metadata.Name).First());

            SqlServerEntityPipeline insertPipeline2 = new SqlServerEntityPipeline(ConnectString);
            var metadata2 = EntitySpider.GenerateEntityMetaData(typeof(UpdateEntity5).GetTypeInfo());

            insertPipeline2.AddEntity(metadata2);
            Assert.AreEqual(1, insertPipeline2.GetUpdateColumns(metadata2.Name).Length);
            Assert.AreEqual("Value", insertPipeline2.GetUpdateColumns(metadata2.Name).First());
        }
Ejemplo n.º 4
0
        public void Update()
        {
#if !NET45
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
#endif

            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.Init();

                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
                }, spider);

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

                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
                }, spider);

                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.º 5
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.º 6
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();
        }
        public void Insert()
        {
#if NETSTANDARD
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
#endif
            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.Init();

                // Common data
                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)
                };
                var data3 = new ProductInsert {
                    Sku = "112", Category = null, Url = "http://jd.com/111", CDate = new DateTime(2016, 8, 13)
                };
                // Value is null
                insertPipeline.Process(metadata.Name, new List <dynamic> {
                    data1, data2, data3
                }, spider);

                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();
        }
Ejemplo n.º 9
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();
        }