public void ShouldCorrectlyLoadFirstAndLastRows() { // Arrange // Act var result = _sut.Map <PersonModel>(SheetName, opt => opt .ForMember(m => m.CustomRowNumber, Resolve.ByValue("Custom Identification No"))).ToList(); // Assert Assert.Equal(202, result.First().CustomRowNumber); Assert.Equal(1201, result.Last().CustomRowNumber); }
public void ShouldCreatePropertyMapForEntireModel() { // Arrange const string sheetName = "InvalidColumnNameDataSheet"; var worksheet = _fixture.GetWorkbook(Workbook).Worksheet(sheetName); // Act var result = _sut.CreatePropertyMap <Person>(worksheet, opt => opt.ForMember(p => p.FirstName, Resolve.ByValue("First Name")) .ForMember(p => p.LastName, Resolve.ByValue("Last Name"))); // Assert ValidatePropertyMapFor(result, "FirstName", "First Name"); ValidatePropertyMapFor(result, "LastName", "Last Name"); ValidatePropertyMapFor(result, "Age", "Age"); }
public void ShouldLoad1000RowsInUnder2Seconds() { // Arrange var sw = new Stopwatch(); sw.Start(); // Act var result = _sut.Map <PersonModel>(SheetName, opt => opt .ForMember(m => m.CustomRowNumber, Resolve.ByValue("Custom Identification No"))).ToList(); sw.Stop(); // Assert Assert.Equal(1000, result.Count); Assert.True(5000 > sw.ElapsedMilliseconds); _output.WriteLine("{0} records loaded in {1} milliseconds.", result.Count, sw.ElapsedMilliseconds); }
public void ShouldThrowIfColumnCantBeResolved() { // Arrange const string sheetName = "FullDataSheet"; var worksheet = _fixture.GetWorkbook(Workbook).Worksheet(sheetName); // Act var exception = Assert.ThrowsAny <MappingException>(() => { var result = _sut.CreatePropertyMap <Person>(worksheet, opt => opt.ForMember(p => p.FirstName, Resolve.ByValue("InvalidColumn"))); }); // Assert Assert.IsType <MappedColumnByValueNotFoundException>(exception.Exceptions.Single()); }
public void ShouldThrowAggegateExceptionWithTwoInnerExceptionsToCaptureAllMappingProblems() { // Arrange const string sheetName = "FullDataSheet"; var worksheet = _fixture.GetWorkbook(Workbook).Worksheet(sheetName); // Act var exception = Assert.ThrowsAny <MappingException>( () => { var result = _sut.CreatePropertyMap <Employee>(worksheet, opt => opt.ForMember(e => e.FirstName, Resolve.ByValue("InvalidPropertyName"))); }); // Assert Assert.Equal(2, exception.Exceptions.Count); Assert.True(exception.Exceptions.OfType <UnmapppedPropertyException>().Any()); Assert.True(exception.Exceptions.OfType <MappedColumnByValueNotFoundException>().Any()); }
private static void Main(string[] args) { var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); serviceCollection.AddExcel(); var serviceProvider = serviceCollection.BuildServiceProvider(); var builder = serviceProvider.GetService <IExcelMapperBuilder>(); var mapper = builder.Build(LoadWorkbook(Workbook)); Console.WriteLine("Press any key when ready to load some EXCEL data:)"); Console.ReadLine(); var sw = new Stopwatch(); Console.WriteLine($"Loading '{Workbook}' ..."); sw.Start(); var result = mapper.Map <PersonModel>("Sheet1", opt => opt.ForMember(m => m.CustomRowNumber, Resolve.ByValue("Custom Identification No"))).ToList(); sw.Stop(); Console.WriteLine($"{result.Count} records loaded from {Workbook} in {sw.ElapsedMilliseconds} milliseconds."); Console.WriteLine("Press any key to exit."); Console.ReadLine(); }
public void ShouldBuildColumnMappingsBasedOnPassedinConfiguration() { // Arrange Action <IMemberSpec <Person> > mappings = m => m.ForMember(p => p.FirstName, Resolve.ByValue("MyColumn")); // Act _sut.Map(SheetName, mappings); // Assert _propertyMapFactory.Received(1).CreatePropertyMap(Arg.Is <IDataSheet>(w => w.Name == SheetName), mappings); }