private void CheckSingleFolder2Test( string folderName , int amountProductsHasPicture , int amountProductNotHasPicture , int amountProductExistsInDb , int amountImagesHasNotProduct , bool needCheckDataBase , DALProduct dalProduct , DALSupplier dalSupplier , IFormatSerialNoPersistent ifsp , DalBase<Product> dalBaseProduct) { string folderFullPath = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\" + folderName + "\\"; SingleFolderImport checker = new SingleFolderImport(folderFullPath); BizProduct bizP = new BizProduct(); bizP.DalProduct = dalProduct; bizP.DalBase = dalBaseProduct; BizSupplier bizS = new BizSupplier(); bizS.DalSupplier = dalSupplier; bizP.DalSupplier = dalSupplier; checker.NeedCheckWithDB = needCheckDataBase; checker.Import(bizP, bizS, ifsp); IList<Product> productsHasPicture = checker.ProductsPassedDBCheck , productsNotHasPicture = checker.ProductsNotHasImage , productsExistedInDB = checker.ProductsExistedInDB; IList<FileInfo> imagesHasProduct = checker.ImagesHasProduct , imagesHasNotProduct = checker.ImagesNotHasProduct; // Assert.AreEqual("Success", FormatChecker.Check(folderContainsExcelAndImages)); Assert.AreEqual(amountProductsHasPicture, checker.ProductsPassedDBCheck.Count); Assert.AreEqual(amountProductNotHasPicture, checker.ProductsNotHasImage.Count); Assert.AreEqual(amountProductExistsInDb, checker.ProductsExistedInDB.Count); Assert.AreEqual(amountImagesHasNotProduct, checker.ImagesNotHasProduct.Count); DateTime beginSaveResult = DateTime.Now; string saveFolder = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\检测结果\\"; string saveFolderOfSupplier; if (productsHasPicture.Count > 0) saveFolderOfSupplier = bizS.GetByCode(productsHasPicture[0].SupplierCode).Name; else if (productsNotHasPicture.Count > 0) saveFolderOfSupplier = bizS.GetByCode(productsNotHasPicture[0].SupplierCode).Name; else throw new Exception(); DirectoryInfo dirOfSavedSupplier = new DirectoryInfo(saveFolder + "合格数据\\" + saveFolderOfSupplier + "\\"); if (dirOfSavedSupplier.Exists) { dirOfSavedSupplier.Delete(true); } string supplierName = string.Empty; if (productsExistedInDB.Count > 0) supplierName = bizS.GetByCode(productsExistedInDB[0].SupplierCode).Name; else if (productsHasPicture.Count > 0) supplierName = bizS.GetByCode(productsHasPicture[0].SupplierCode).Name; else if (productsNotHasPicture.Count > 0) supplierName = bizS.GetByCode(productsNotHasPicture[0].SupplierCode).Name; else { return; } supplierName = StringHelper.ReplaceInvalidChaInFileName(supplierName, string.Empty); checker.HandlerCheckResult( supplierName, saveFolder, WebProductImagesPath ); Assert.AreEqual(productsHasPicture.Count, dirOfSavedSupplier.GetImageFiles().ToArray().Length); Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginSaveResult).TotalSeconds); }
/// <summary> /// /// </summary> /// <param name="folderName">包含excel和对应产品图片的文件夹</param> /// <param name="amountProductsHasPicture_NotExitsted">可供导入的产品(没有导入过,有图片)</param> /// <param name="amountProductNotHasPicture_OrHasExisted">不合格产品(已导入,或 没图片</param> /// <param name="amountProductExistsInDb_HasExisted">不合格产品(已导入)</param> /// <param name="amountImagesHasNotProduct_OrHasExisted">没有产品信息的图片</param> /// <param name="needCheckDataBase">是否从数据库查询产品是否存在</param> /// <param name="dalProduct">供mock,判断是否存在的方法</param> /// <param name="dalSupplier">供mock,获取供应商的方法.</param> private void CheckSingleFolderTest( string folderName , int amountProductsHasPicture , int amountProductNotHasPicture , int amountProductExistsInDb , int amountImagesHasNotProduct , bool needCheckDataBase , DALProduct dalProduct , DALSupplier dalSupplier) { IList<Product> productsHasPicture, productsNotHasPicture, productsExistedInDB; IList<FileInfo> imagesHasProduct, imagesHasNotProduct; string folderFullPath = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\" + folderName + "\\"; ProductImportor checker = new ProductImportor(); checker.BizProduct.DalBase = dalProduct; checker.BizProduct.DalSupplier = dalSupplier; checker.CheckWithDatabase = needCheckDataBase; checker.CheckSingleFolder(folderFullPath , out productsHasPicture , out productsNotHasPicture , out productsExistedInDB , out imagesHasProduct , out imagesHasNotProduct); // Assert.AreEqual("Success", FormatChecker.Check(folderContainsExcelAndImages)); Assert.AreEqual(amountProductsHasPicture, productsHasPicture.Count); Assert.AreEqual(amountProductNotHasPicture, productsNotHasPicture.Count); Assert.AreEqual(amountProductExistsInDb, productsExistedInDB.Count); Assert.AreEqual(amountImagesHasNotProduct, imagesHasNotProduct.Count); DateTime beginSaveResult = DateTime.Now; string saveFolder=Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\检测结果\\"; string saveFolderOfSupplier; if (productsHasPicture.Count > 0) saveFolderOfSupplier = productsHasPicture[0].SupplierName; else if (productsNotHasPicture.Count > 0) saveFolderOfSupplier = productsNotHasPicture[0].SupplierName; else throw new Exception(); DirectoryInfo dirOfSavedSupplier = new DirectoryInfo(saveFolder + "合格数据\\" + saveFolderOfSupplier+"\\"); if (dirOfSavedSupplier.Exists) { dirOfSavedSupplier.Delete(true); } string supplierName = string.Empty; if (productsExistedInDB.Count > 0) supplierName = productsExistedInDB[0].SupplierName; else if (productsHasPicture.Count > 0) supplierName = productsHasPicture[0].SupplierName; else if (productsNotHasPicture.Count > 0) supplierName = productsNotHasPicture[0].SupplierName; else { return; } supplierName = StringHelper.ReplaceInvalidChaInFileName(supplierName, string.Empty); checker.HandlerCheckResult( supplierName, productsHasPicture , productsNotHasPicture , productsExistedInDB , imagesHasProduct , imagesHasNotProduct , saveFolder); Assert.AreEqual(productsHasPicture.Count, dirOfSavedSupplier.GetImageFiles().ToArray().Length); Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginSaveResult).TotalSeconds); }
/// <summary> /// /// </summary> /// <param name="folderName">包含excel和对应产品图片的文件夹</param> /// <param name="amountProductsHasPicture_NotExitsted">可供导入的产品(没有导入过,有图片)</param> /// <param name="amountProductNotHasPicture_OrHasExisted">不合格产品(已导入,或 没图片</param> /// <param name="amountProductExistsInDb_HasExisted">不合格产品(已导入)</param> /// <param name="amountImagesHasNotProduct_OrHasExisted">没有产品信息的图片</param> /// <param name="needCheckDataBase">是否从数据库查询产品是否存在</param> /// <param name="dalProduct">供mock,判断是否存在的方法</param> /// <param name="dalSupplier">供mock,获取供应商的方法.</param> private void CheckSingleFolderTest( string folderName , int amountProductsHasPicture , int amountProductNotHasPicture , int amountProductExistsInDb , int amountImagesHasNotProduct , bool needCheckDataBase , DALProduct dalProduct , DALSupplier dalSupplier) { IList <Product> productsHasPicture, productsNotHasPicture, productsExistedInDB; IList <FileInfo> imagesHasProduct, imagesHasNotProduct; string folderFullPath = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\" + folderName + "\\"; ProductImportor checker = new ProductImportor(); checker.BizProduct.DalBase = dalProduct; checker.BizProduct.DalSupplier = dalSupplier; checker.CheckWithDatabase = needCheckDataBase; checker.CheckSingleFolder(folderFullPath , out productsHasPicture , out productsNotHasPicture , out productsExistedInDB , out imagesHasProduct , out imagesHasNotProduct); // Assert.AreEqual("Success", FormatChecker.Check(folderContainsExcelAndImages)); Assert.AreEqual(amountProductsHasPicture, productsHasPicture.Count); Assert.AreEqual(amountProductNotHasPicture, productsNotHasPicture.Count); Assert.AreEqual(amountProductExistsInDb, productsExistedInDB.Count); Assert.AreEqual(amountImagesHasNotProduct, imagesHasNotProduct.Count); DateTime beginSaveResult = DateTime.Now; string saveFolder = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\检测结果\\"; string saveFolderOfSupplier; if (productsHasPicture.Count > 0) { saveFolderOfSupplier = productsHasPicture[0].SupplierName; } else if (productsNotHasPicture.Count > 0) { saveFolderOfSupplier = productsNotHasPicture[0].SupplierName; } else { throw new Exception(); } DirectoryInfo dirOfSavedSupplier = new DirectoryInfo(saveFolder + "合格数据\\" + saveFolderOfSupplier + "\\"); if (dirOfSavedSupplier.Exists) { dirOfSavedSupplier.Delete(true); } string supplierName = string.Empty; if (productsExistedInDB.Count > 0) { supplierName = productsExistedInDB[0].SupplierName; } else if (productsHasPicture.Count > 0) { supplierName = productsHasPicture[0].SupplierName; } else if (productsNotHasPicture.Count > 0) { supplierName = productsNotHasPicture[0].SupplierName; } else { return; } supplierName = StringHelper.ReplaceInvalidChaInFileName(supplierName, string.Empty); checker.HandlerCheckResult( supplierName, productsHasPicture , productsNotHasPicture , productsExistedInDB , imagesHasProduct , imagesHasNotProduct , saveFolder); Assert.AreEqual(productsHasPicture.Count, dirOfSavedSupplier.GetImageFiles().ToArray().Length); Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginSaveResult).TotalSeconds); }