Ejemplo n.º 1
0
        public void Extract_Kr_ShouldReturnExtractException()
        {
            // Arrange
            var text = "KR";
            // Act
            Action act = () => LanguageExtractor.Extract(text);

            // Assert
            act.Should().Throw <ExtractorException>("Cannot extract language from text");
        }
Ejemplo n.º 2
0
        public void Extract_TextWithSpaces_ShouldReturnEnum()
        {
            // Arrange
            var text = " UK ";
            // Act
            var language = LanguageExtractor.Extract(text);

            // Assert
            language.Should().Be(Language.UK);
        }
Ejemplo n.º 3
0
        public void Extract_Pl_ShouldReturnEnum()
        {
            // Arrange
            var text = "PL";
            // Act
            var language = LanguageExtractor.Extract(text);

            // Assert
            language.Should().Be(Language.PL);
        }
Ejemplo n.º 4
0
        public void Extract_Null_ShouldReturnExtractException()
        {
            // Arrange
            string text = null;
            // Act
            Action act = () => LanguageExtractor.Extract(text);

            // Assert
            act.Should().Throw <ExtractorException>($"Language is null or empty, [{text}]");
        }
Ejemplo n.º 5
0
        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);
        }