public List <StoragePlace> ImportStoragePlacesList() { List <StoragePlace> storagePlaces = new List <StoragePlace>(); foreach (var spreadsheetStoragePlaceData in StoragePlaceData) { var storagePlace = StoragePlaceExtractor.Extract(spreadsheetStoragePlaceData.Name, spreadsheetStoragePlaceData.Comment); if (storagePlace != null) { storagePlaces.Add(storagePlace); } } foreach (var spreadsheetCatalogData in CatalogData) { var storagePlace = StoragePlaceExtractor.Extract(spreadsheetCatalogData.StoragePlace); if (storagePlace != null) { storagePlaces.Add(storagePlace); } } var storagePlacesWithoutDoubles = storagePlaces .GroupBy(a => a.StoragePlaceName) .Select(a => a.FirstOrDefault(b => !string.IsNullOrEmpty(b.Comment)) ?? a.First()) .ToList(); return(storagePlacesWithoutDoubles); }
public void Extract_BothArgumentNull_ShouldReturnNull() { // Arrange string storagePlaceName = null; string comment = null; // Act var storagePlace = StoragePlaceExtractor.Extract(storagePlaceName, comment); // Assert storagePlace.Should().BeNull(); }
public void Extract_OnlyNameArgument_ShouldReturnStoragePlace() { // Arrange var storagePlaceName = "IX"; // Act var storagePlace = StoragePlaceExtractor.Extract(storagePlaceName); // Assert storagePlace.Id.Should().NotBeEmpty(); storagePlace.StoragePlaceName.Should().Be(storagePlaceName); storagePlace.Comment.Should().BeNull(); }
public void Extract_ShouldReturnStoragePlace() { // Arrange var storagePlaceName = "IX"; var comment = "Literatura piękna, klasyka, itp.- szare pudło ACE"; // Act var storagePlace = StoragePlaceExtractor.Extract(storagePlaceName, comment); // Assert storagePlace.Id.Should().NotBeEmpty(); storagePlace.StoragePlaceName.Should().Be(storagePlaceName); storagePlace.Comment.Should().Be(comment); }
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); }