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(); }
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(); }