public void Extract_Null_ShouldReturnExtractorException() {
     // Arrange
     string text = null;
     // Act
     var category = CategoryExtractor.Extract(text);
     // Assert
     category.Should().BeNull();
 }
 public void Extract_EmptyText_ShouldReturnExtractorException() {
     // Arrange
     var text = string.Empty;
     // Act
     var category = CategoryExtractor.Extract(text);
     // Assert
     category.Should().BeNull();
 }
 public void Extract_WrongCode_ShouldReturnExtractorException() {
     // Arrange
     var text = "_____";
     // Act
     Action act = () => CategoryExtractor.Extract(text);
     // Assert
     act.Should().Throw<ExtractorException>("Cannot extract color from text");
 }
 public void Extract_E7CFB7_ShouldReturnCategory() {
     // Arrange 
     var prefix = "__";
     var colorCode = "E7CFB7";
     var text = $"{prefix}{colorCode}";
     var expectedCategory = new Category {
         Name = CategoryName.History
     };
     // Act
     var category = CategoryExtractor.Extract(text);
     // Assert
     category.Should().BeEquivalentTo(expectedCategory);
 }
 public void Extract_3333FF_ShouldReturnCategory() {
     // Arrange 
     var prefix = "__";
     var colorCode = "3333FF";
     var text = $"{prefix}{colorCode}";
     var expectedCategory = new Category {
         Name = CategoryName.Relationship
     };
     // Act
     var category = CategoryExtractor.Extract(text);
     // Assert
     category.Should().BeEquivalentTo(expectedCategory);
 }
 public void Extract_FFFFCC_ShouldReturnCategory() {
     // Arrange 
     var prefix = "__";
     var colorCode = "FFFFCC";
     var text = $"{prefix}{colorCode}";
     var expectedCategory = new Category {
         Name = CategoryName.LanguageLearning
     };
     // Act
     var category = CategoryExtractor.Extract(text);
     // Assert
     category.Should().BeEquivalentTo(expectedCategory);
 }
Beispiel #7
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);
        }
Beispiel #8
0
        public List <Category> ImportCategoriesList()
        {
            List <Category> categories = new List <Category>();

            foreach (var spreadsheetCategoryData in CategoryData)
            {
                var category = CategoryExtractor.Extract(spreadsheetCategoryData.Colour);
                if (category != null)
                {
                    categories.Add(category);
                }
            }

            return(categories);
        }