public void Should_cannot_add_objects_with_null_property_selectors() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage1.GetWorksheet("TEST5"); var stocks = new List <StocksNullable> { new StocksNullable { Barcode = "barcode123", Quantity = 5, UpdatedDate = DateTime.MaxValue } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => worksheet.AddObjects(stocks, 5, null); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.Should().Throw <ArgumentException>(); }
public void Should_add_objects_with_start_row_and_column_index_without_parameters() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage1.GetWorksheet("TEST5"); var stocks = new List <StocksNullable> { new StocksNullable { Barcode = "barcode123", Quantity = 5, UpdatedDate = DateTime.MaxValue } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- worksheet.AddObjects(stocks, 5, 3); IEnumerable <StocksNullable> list = worksheet.ToList <StocksNullable>(configuration => configuration.SkipCastingErrors()); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- list.Count().Should().Be(4); }
public void Should_add_objects_with_parameters() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage1.GetWorksheet("TEST5"); DateTime dateTime = DateTime.MaxValue; var stocks = new List <StocksNullable> { new StocksNullable { Barcode = "barcode123", Quantity = 5, UpdatedDate = dateTime } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- worksheet.AddObjects(stocks, 5, _ => _.Barcode, _ => _.Quantity, _ => _.UpdatedDate); IEnumerable <StocksNullable> list = worksheet.ToList <StocksNullable>(); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- list.Count().Should().Be(4); list.Last().Barcode.Should().Be("barcode123"); list.Last().Quantity.Should().Be(5); list.Last().UpdatedDate.Value.Date.Should().Be(dateTime.Date); list.Last().UpdatedDate.Value.Hour.Should().Be(dateTime.Hour); }
public void Should_AddObjects_method_work_without_parameters() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["TEST5"]; var stocks = new List <StocksNullable> { new StocksNullable { Barcode = "barcode123", Quantity = 5, UpdatedDate = DateTime.MaxValue } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- worksheet.AddObjects(stocks, 5, 3); IEnumerable <StocksNullable> list = worksheet.ToList <StocksNullable>(null, configuration => { configuration.SkipCastingErrors = true; configuration.HasHeaderRow = true; }); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- list.Count().Should().Be(4); }
public void Should_throw_exception_when_the_parameters_of_AddObjects_method_are_null() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["TEST5"]; var stocks = new List <StocksNullable> { new StocksNullable { Barcode = "barcode123", Quantity = 5, UpdatedDate = DateTime.MaxValue } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { worksheet.AddObjects(stocks, 5, null); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.Should().Throw <ArgumentException>(); }
public void Should_work_AddObjects_method_with_parameters() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["TEST5"]; var stocks = new List <StocksNullable> { new StocksNullable { Barcode = "barcode123", Quantity = 5, UpdatedDate = DateTime.MaxValue } }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- worksheet.AddObjects(stocks, 5, _ => _.Barcode, _ => _.Quantity, _ => _.UpdatedDate); IEnumerable <StocksNullable> list = worksheet.ToList <StocksNullable>(true); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- list.Count().Should().Be(4); }
/// <summary> /// Adds given list of objects to the worksheet with propery selectors /// </summary> /// <typeparam name="T"></typeparam> /// <param name="worksheet"></param> /// <param name="items"></param> /// <param name="startRowIndex"></param> /// <param name="propertySelectors"></param> /// <returns></returns> public static ExcelWorksheet AddObjects <T>(this ExcelWorksheet worksheet, IEnumerable <T> items, int startRowIndex, params Func <T, object>[] propertySelectors) => worksheet.AddObjects(items, startRowIndex, 1, null, propertySelectors);