/// <summary> ///A test for ShredObject ///</summary> public void ShredObjectTestHelper <T>() { ObjectShredder <T> target = new ObjectShredder <T>(); // TODO: Initialize to an appropriate value DataTable table = null; // TODO: Initialize to an appropriate value T instance = default(T); // TODO: Initialize to an appropriate value object[] expected = null; // TODO: Initialize to an appropriate value object[] actual; actual = target.ShredObject(table, instance); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> ///A test for ExtendTable ///</summary> public void ExtendTableTestHelper <T>() { ObjectShredder <T> target = new ObjectShredder <T>(); // TODO: Initialize to an appropriate value DataTable table = null; // TODO: Initialize to an appropriate value Type type = null; // TODO: Initialize to an appropriate value DataTable expected = null; // TODO: Initialize to an appropriate value DataTable actual; actual = target.ExtendTable(table, type); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///A test for ShredPrimitive ///</summary> public void ShredPrimitiveTestHelper <T>() { ObjectShredder <T> target = new ObjectShredder <T>(); // TODO: Initialize to an appropriate value IEnumerable <T> source = null; // TODO: Initialize to an appropriate value DataTable table = null; // TODO: Initialize to an appropriate value Nullable <LoadOption> options = new Nullable <LoadOption>(); // TODO: Initialize to an appropriate value DataTable expected = null; // TODO: Initialize to an appropriate value DataTable actual; actual = target.ShredPrimitive(source, table, options); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public ExcelAddressBase WriteExcelData(ExcelWorksheet ws, int dataStartRow, DataTable dataTable, Report param) { // DataTable -> List var shredder = new ObjectShredder <ProductResidueReportRow>(); var querySort = shredder.UnShred(dataTable); // вытащили различных поставщиков из набора. Сортировка - по количеству позиций в порядке убывания var suppliers = querySort.GroupBy(x => x.SupplierName) .Select(x => new { SupplierName = x.Key, PosCount = x.Count() }) .OrderByDescending(x => x.PosCount).Select(x => x.SupplierName).ToArray(); var dd = new Dictionary <string, int>(); for (int i = 0; i < suppliers.Length; i++) { dd.Add(suppliers[i], i + 1); } var _type = typeof(ProductResidueReportRow); int startCol = 1; int startRow = dataStartRow; var keys = new List <string>() { "CatalogName", "ProducerName", "RegionName" }; // записали ключи в имена колонок foreach (var p in _type.GetProperties().Where(x => keys.Contains(x.Name))) { // установили имя колонки var displayName = p.GetCustomAttribute <DisplayAttribute>().Name; ws.SetValue(startRow, startCol++, displayName); } // вытащили форматирование сумм var pCost = _type.GetProperty("Cost"); var costFormat = pCost.GetCustomAttribute <FormatAttribute>().Value; // показываем цены, если есть цены var showCost = querySort.Any(x => x.Cost.HasValue); // вставили заголовки рассчитываемых колонок if (showCost) { ws.Column(startCol).Style.Numberformat.Format = costFormat; ws.SetValue(startRow, startCol++, "Мин. цена"); ws.Column(startCol).Style.Numberformat.Format = costFormat; ws.SetValue(startRow, startCol++, "Средн. цена"); ws.Column(startCol).Style.Numberformat.Format = costFormat; ws.SetValue(startRow, startCol++, "Макс. цена"); } ws.SetValue(startRow, startCol++, "Лидер"); // записали поставщиков в имена колонок foreach (var s in suppliers) { ws.SetValue(startRow - 1, startCol, s); if (showCost) { ws.Column(startCol).Style.Numberformat.Format = costFormat; ws.Cells[startRow - 1, startCol, startRow - 1, startCol + 1].Merge = true; ws.SetValue(startRow, startCol, "Цена"); ws.SetValue(startRow, ++startCol, "Кол-во"); } else { // мёрдж одной ячейки, чтобы была одинаковая ширина колонок вне зависимости от длины названия поставщика потому что слитые ячейки не участвуют в алгоритме автоопределения оптимальной ширины столбца ws.Cells[startRow - 1, startCol, startRow - 1, startCol].Merge = true; ws.SetValue(startRow, startCol, "Кол-во"); } startCol++; } startRow++; var colCount = startCol - 1; // каждому key сопоставлен набор пар дата-цена var orderGrouping = from item in querySort let groupKey = new { item.CatalogName, item.ProducerName, item.RegionName } group new { item.SupplierName, item.Cost, item.Quantity } by groupKey into grouping orderby grouping.Key.CatalogName select grouping; // строка для каждого уникального ключа foreach (var group in orderGrouping) { startCol = 1; var key = group.Key; ws.SetValue(startRow, startCol++, key.CatalogName); ws.SetValue(startRow, startCol++, key.ProducerName); ws.SetValue(startRow, startCol++, key.RegionName); if (showCost) { ws.SetValue(startRow, startCol++, group.Min(x => x.Cost)); ws.SetValue(startRow, startCol++, group.Average(x => x.Cost)); ws.SetValue(startRow, startCol++, group.Max(x => x.Cost)); } var maxQuantity = group.Max(x => x.Quantity); var liderName = group.Where(x => x.Quantity == maxQuantity).Select(x => x.SupplierName).FirstOrDefault(); ws.SetValue(startRow, startCol, liderName); // записываем данные под соответствующим поставщиком foreach (var item in group) { if (showCost) { var col = startCol + 2 * dd[item.SupplierName] - 1; ws.SetValue(startRow, col, item.Cost); ws.SetValue(startRow, ++col, item.Quantity); } else { var col = startCol + dd[item.SupplierName]; ws.SetValue(startRow, col, item.Quantity); } } ++startRow; } var rowCount = startRow - 1; return(new ExcelAddressBase(dataStartRow, 1, rowCount, colCount)); }
public ExcelAddressBase WriteExcelData(ExcelWorksheet ws, int dataStartRow, DataTable dataTable, Report param) { // DataTable -> List var shredder = new ObjectShredder <ProductPriceDynamicsReportRow>(); var querySort = shredder.UnShred(dataTable); // вытащили различные даты из набора var dates = querySort.Select(x => x.Date).Distinct().OrderBy(x => x).ToArray(); var dd = new Dictionary <DateTime, int>(); for (int i = 0; i < dates.Length; i++) { dd.Add(dates[i], i + 1); } var _type = typeof(ProductPriceDynamicsReportRow); int startCol = 1; int startRow = dataStartRow; var keys = new List <string>() { "CatalogName", "ProducerName", "RegionName", "SupplierName" }; // записали ключи в имена колонок foreach (var p in _type.GetProperties().Where(x => keys.Contains(x.Name))) { // установили имя колонки var displayName = p.GetCustomAttribute <DisplayAttribute>().Name; ws.SetValue(startRow, startCol++, displayName); } // записали даты в имена колонок var pCost = _type.GetProperty("Cost"); var costFormat = pCost.GetCustomAttribute <FormatAttribute>().Value; var cparam = (ProductPriceDynamicsReport)param; foreach (var d in dates) { ws.SetValue(startRow - 1, startCol, d.ToShortDateString()); switch (cparam.VarCostOrQuantity) { case CostOrQuantity.WithCost: ws.Column(startCol).Style.Numberformat.Format = costFormat; ws.SetValue(startRow, startCol, "Цена"); break; case CostOrQuantity.WithQuantity: ws.SetValue(startRow, startCol, "Кол-во"); break; default: ws.Column(startCol).Style.Numberformat.Format = costFormat; ws.Cells[startRow - 1, startCol, startRow - 1, startCol + 1].Merge = true; ws.SetValue(startRow, startCol, "Цена"); ws.SetValue(startRow, ++startCol, "Кол-во"); break; } startCol++; } startRow++; var colCount = startCol - 1; // каждому key сопоставлен набор троек дата-цена-количество var orderGrouping = from item in querySort let groupKey = new { item.CatalogName, item.ProducerName, item.RegionName, item.SupplierName } group new { item.Date, item.Cost, item.Quantity } by groupKey into grouping //orderby grouping.Key.CatalogName select grouping; // строка для каждого уникального ключа foreach (var group in orderGrouping) { var key = group.Key; ws.SetValue(startRow, 1, key.CatalogName); ws.SetValue(startRow, 2, key.ProducerName); ws.SetValue(startRow, 3, key.RegionName); ws.SetValue(startRow, 4, key.SupplierName); // записываем данные под соответствующей датой foreach (var item in group) { int col; switch (cparam.VarCostOrQuantity) { case CostOrQuantity.WithCost: col = 4 + dd[item.Date]; ws.SetValue(startRow, col, item.Cost); break; case CostOrQuantity.WithQuantity: col = 4 + dd[item.Date]; ws.SetValue(startRow, col, item.Quantity); break; default: col = 4 + 2 * dd[item.Date] - 1; ws.SetValue(startRow, col, item.Cost); ws.SetValue(startRow, ++col, item.Quantity); break; } } ++startRow; } var rowCount = startRow - 1; return(new ExcelAddressBase(dataStartRow, 1, rowCount, colCount)); }
/// <summary> ///A test for ObjectShredder`1 Constructor ///</summary> public void ObjectShredderConstructorTestHelper <T>() { ObjectShredder <T> target = new ObjectShredder <T>(); Assert.Inconclusive("TODO: Implement code to verify target"); }