/// <summary> /// 数据比较 /// </summary> /// <param name="oldeValue">老数据</param> /// <param name="newValue">新数据</param> /// <param name="ingnoreCase">是否忽略大小写</param> /// <returns></returns> public DataCompareResult StartCompare(string[] oldeValue, string[] newValue, bool ingnoreCase) { DataCompareResult result = new DataCompareResult(); if (oldeValue == null || oldeValue.Length == 0) { result.OnlyNewValue = newValue; return(result); } if (newValue == null || newValue.Length == 0) { result.OnlyOldValue = oldeValue; return(result); } if (ingnoreCase) { oldeValue = oldeValue.Select(s => s.ToLower()).ToArray(); newValue = newValue.Select(s => s.ToLower()).ToArray(); } List <string> oldData = new List <string>(); List <string> newData = new List <string>(); List <string> equalData = new List <string>(); foreach (string old in oldeValue) { if (newValue.Contains(old)) { equalData.Add(old); } else { oldData.Add(old); } } foreach (string item in newValue) { if (!oldeValue.Contains(item)) { newData.Add(item); } } return(new DataCompareResult() { OnlyNewValue = newData.ToArray(), OnlyOldValue = oldData.ToArray(), EqualValue = equalData.ToArray() }); }
public void SyncData_ShouldUpload() { var products = new List <Product> { new Product() { Name = "Sole - Dover, Whole, Fresh", Description = "Subcutaneous fat necrosis due to birth injury", Price = new Price() { Value = 60, Discount = 65, Currency = new Currency() { Code = "IDR" } }, ProductCategories = new List <ProductCategory> { new ProductCategory() { Category = new Category { Name = "Tools" } } }, ImageUrl = @"http://dummyimage.com/127x193.jpg/dddddd/000000", ProductShipping = new ProductShipping() { Currency = new Currency() { Code = "CNY" }, ShippingPrice = 14, ShippingMethod = new ShippingMethod { Name = "PowerShares KBW Bank Portfolio" } } }, new Product() { Name = "Pepperoni Slices", Description = "Rapidly progressive nephritic syndrome with unspecified morphologic changes", Price = new Price() { Value = 15, Discount = 80, Currency = new Currency() { Code = "BAM" } }, ProductCategories = new List <ProductCategory> { new ProductCategory() { Category = new Category { Name = "Computers" } } }, ImageUrl = @"http://dummyimage.com/225x231.jpg/cc0000/ffffff", ProductShipping = new ProductShipping() { Currency = new Currency() { Code = "MKD" }, ShippingPrice = 63, ShippingMethod = new ShippingMethod { Name = "Rapidly progressive nephritic syndrome with unspecified morphologic changes" } } }, new Product() { Name = "Raisin - Golden", Description = "Postprocedural ovarian failure", Price = new Price() { Value = 41, Discount = 11, Currency = new Currency() { Code = "RSD" } }, ProductCategories = new List <ProductCategory> { new ProductCategory() { Category = new Category { Name = "Electronics" } } }, ImageUrl = @"http://dummyimage.com/150x136.jpg/5fa2dd/ffffff", ProductShipping = new ProductShipping() { Currency = new Currency() { Code = "IRR" }, ShippingPrice = 58, ShippingMethod = new ShippingMethod { Name = "Brady Corporation" } } } }; var compareResult = new DataCompareResult { ToUpload = products }; _followingUpDataCollectorMock.Setup(fudc => fudc.CollectData()) .Returns(products); _advertisementDataComparerMock.Setup(adc => adc.Compare(products)) .Returns(compareResult); //ACT _advertisementDataSynchronizer.SyncData(); //ASSERT _advertisementItemUploaderMock.Verify(aiu => aiu.Upload(It.IsAny <BaseEntity>()), Times.Exactly(3)); }