public void ReadRow_AutoMappedNullableDateTime_Success() { using (var importer = Helpers.GetImporter("DateTimes.xlsx")) { ExcelSheet sheet = importer.ReadSheet(); sheet.ReadHeading(); // Valid cell value. NullableDateTimeValue row1 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Equal(new DateTime(2017, 07, 19), row1.Value); // Empty cell value. NullableDateTimeValue row5 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Null(row5.Value); // Invalid cell value. Assert.Throws <ExcelMappingException>(() => sheet.ReadRow <NullableDateTimeValue>()); } }
public void ReadRow_DefaultMappedNullableDateTime_Success() { using var importer = Helpers.GetImporter("DateTimes.xlsx"); importer.Configuration.RegisterClassMap <DefaultNullableDateTimeClassMap>(); ExcelSheet sheet = importer.ReadSheet(); sheet.ReadHeading(); // Valid cell value. NullableDateTimeValue row1 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Equal(new DateTime(2017, 07, 19), row1.Value); // Empty cell value. NullableDateTimeValue row5 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Null(row5.Value); // Invalid cell value. Assert.Throws <ExcelMappingException>(() => sheet.ReadRow <NullableDateTimeValue>()); }
public void ReadRow_CustomMappedNullableDateTime_Success() { using (var importer = Helpers.GetImporter("DateTimes.xlsx")) { importer.Configuration.RegisterClassMap <NullableDateTimeValueFallbackMap>(); ExcelSheet sheet = importer.ReadSheet(); sheet.ReadHeading(); // Valid cell value. NullableDateTimeValue row1 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Equal(new DateTime(2017, 07, 19), row1.Value); // Empty cell value. NullableDateTimeValue row5 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Equal(new DateTime(2017, 07, 20), row5.Value); // Invalid cell value. NullableDateTimeValue row6 = sheet.ReadRow <NullableDateTimeValue>(); Assert.Equal(new DateTime(2017, 07, 21), row6.Value); } }