public List <SeriesInfo> ImportSeriesListInfo() { List <SeriesInfo> seriesInfoList = new List <SeriesInfo>(); foreach (var spreadsheetData in CatalogData) { SeriesInfo seriesInfo; try { seriesInfo = SeriesInfoExtractor.Extract(spreadsheetData.Series); } catch (ExtractorException e) { _log.Error($"Series Extract Error: [{e.Text}]"); continue; } if (seriesInfo != null) { seriesInfoList.Add(seriesInfo); } } var seriesInfoWithoutDoubles = seriesInfoList .GroupBy(a => new { a.SeriesName, a.VolumeNumber }) .Select(a => a.First()) .ToList(); return(seriesInfoWithoutDoubles); }
public void Extractor_TwoMatches_ShouldReturnExtractorException() { // Arrange string text = " - tom 5 - tom 6"; // Act Action act = () => SeriesInfoExtractor.Extract(text); // Assert act.Should().Throw <ExtractorException>("Cannot extract data from text"); }
public void Extractor_Empty_ShouldReturnSeriesEmptySeries() { // Arrange var text = ""; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Should().BeNull(); }
public void Extractor_Null_ShouldReturnSeriesEmptySeries() { // Arrange string text = null; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Should().BeNull(); }
public void Extractor_PauseAndApostrophe_ShouldReturnSeriesEmptySeries() { // Arrange var text = "'-"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Should().BeNull(); }
public void Extractor_OnlyName_ShouldReturnSeriesWithoutNumber() { // Arrange var text = "Igrzyska śmierci"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().Be(text); series.VolumeNumber.Should().Be(0); }
public void Extractor_OnlyNameWithPause_ShouldReturnSeries() { // Arrange var text = "Bajki-rozkladanki"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().Be(text); series.VolumeNumber.Should().Be(0); }
public void Extractor_OnlyVolumeNumber_ShouldReturnSeriesWithoutName() { // Arrange var text = "Tom 4"; var number = 4; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().BeEmpty(); series.VolumeNumber.Should().Be(number); }
public void Extractor_OnlyVolumeWithSmallFirstLetter_ShouldReturnSeries() { // Arrange var name = "tom 1"; var number = 1; // Act var series = SeriesInfoExtractor.Extract(name); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().BeEmpty(); series.VolumeNumber.Should().Be(number); }
public List <Book> ImportBooksList() { var authors = ImportAuthorsList(); var seriesInfos = ImportSeriesListInfo(); var publishingHouses = ImportPublishingHousesList(); var storagePlaces = ImportStoragePlacesList(); var categories = ImportCategoriesList(); var seriesList = seriesInfos .GroupBy(a => a.SeriesName) .Select(a => a.First()) .Where(a => !string.IsNullOrEmpty(a.SeriesName)) .Select(a => a.ToSeries()) .ToList(); List <Book> books = new List <Book>(); foreach (var spreadsheetCatalogData in CatalogData) { var bookCategories = new List <Category>() { CategoryExtractor.Extract(spreadsheetCatalogData.Category) }; bookCategories = bookCategories.Where(a => a != null).ToList(); var bookSeriesInfo = SeriesInfoExtractor.Extract(spreadsheetCatalogData.Series); var book = new Book { Id = Guid.NewGuid(), Title = TitleExtractor.Extract(spreadsheetCatalogData.Title), Authors = AuthorExtractor.Extract(spreadsheetCatalogData.Author), Series = bookSeriesInfo?.ToSeries(), PublishingHouse = PublishingHouseExtractor.Extract(spreadsheetCatalogData.PublishingHouse), PublishmentYear = YearExtractor.Extract(spreadsheetCatalogData.Year), ISBN = IsbnExtractor.Extract(spreadsheetCatalogData.ISBN), Language = LanguageExtractor.Extract(spreadsheetCatalogData.Language), StoragePlace = StoragePlaceExtractor.Extract(spreadsheetCatalogData.StoragePlace), Comment = CommentExtractor.Extract(spreadsheetCatalogData.Comment), Categories = bookCategories, VolumeNumber = bookSeriesInfo?.VolumeNumber }; ImportBookValidator.CheckAuthors(authors, book.Authors); ImportBookValidator.CheckSeries(seriesList, book.Series); ImportBookValidator.CheckPublishingHouse(publishingHouses, book.PublishingHouse); ImportBookValidator.CheckStoragePlace(storagePlaces, book.StoragePlace); ImportBookValidator.CheckCategory(categories, book.Categories); books.Add(book); } return(books); }
public void Extractor_NameWithApostropheAndVolumeNumber_ShouldReturnSeries() { // Arrange var name = "Tytus Romek i A'Tomek"; var number = 1; var text = $"{name} - tom {number}"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().Be(name); series.VolumeNumber.Should().Be(number); }
public void Extractor_NameAndVolumeNumber_ShouldReturnSeries() { // Arrange var name = "Igrzyska śmierci"; var number = 3; var text = $"{name} - tom {number}"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().Be(name); series.VolumeNumber.Should().Be(number); }
public void Extractor_NameWithPauseAndVolumeNumber_ShouldReturnSeries() { // Arrange var name = "Ewa wzywa 07 - 31"; var number = 1; var text = $"{name} - tom {number}"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().Be(name); series.VolumeNumber.Should().Be(number); }
public void Extractor_NameWithComaAndPauseAndVolumeNumber_ShouldReturnSeries() { // Arrange var name = "Druga wojna swiatowa - bohaterowie, operacje, kulisy"; var number = 1; var text = $"{name} - tom {number}"; // Act var series = SeriesInfoExtractor.Extract(text); // Assert series.Id.Should().NotBeEmpty(); series.SeriesName.Should().Be(name); series.VolumeNumber.Should().Be(number); }