private BookTitleCollection ChooseBooks(BookCollection bookCollection)
 {
     //TODO not sure if this is a violation of object calisthenics rules.
     //If it is, replace this with a Specification-ish setup (we're almost there anyway).
     if (new SpecialDiscountCalculator().WorksFor(bookCollection)) return new SpecialDiscountCalculator().GetBooks(bookCollection);
     return new NormalDiscountCalculator().GetBooks(bookCollection);
 }
 public RemoveSetResult RemoveSet(BookCollection bookCollection)
 {
     var books = bookCollection.Clone();
     var uniqueBookTitles = ChooseBooks(bookCollection);
     uniqueBookTitles.Each(books.Remove);
     return new RemoveSetResult(books, new BookSetFactory().Create(uniqueBookTitles));
 }
Пример #3
0
 protected void DelRecipe(object sender, EventArgs e)
 {
     try
     {
         if (UserCollection.status == 1)
         {
             if (UserCollection.currentUser.userName.Equals(BookCollection.currentBook.Author))
             {
                 BookCollection.deleteBook(ReqBook);
                 lblError.Text = "1 Book Deleted!";
                 Response.Redirect("AllBooks.aspx");
             }
             else
             {
                 lblError.Text = "You can not delete information about this book.";
             }
         }
         else
         {
             lblError.Text = "Please LogIn!!";
         }
     }
     catch (Exception ex)
     {
         lblError.Text = ex.ToString();
     }
 }
Пример #4
0
        private void SetupChangeNotifications(BookCollection collection)
        {
            collection.CollectionChanged += (sender, args) =>
            {
                _webSocketServer.SendEvent("editableCollectionList", "reload:" + collection.PathToDirectory);
            };

            _localizationChangedEvent?.Subscribe(unused =>
            {
                if (collection.IsFactoryInstalled)
                {
                    _webSocketServer.SendEvent("editableCollectionList", "reload:" + collection.PathToDirectory);
                }
                else
                {
                    // This is tricky. Reloading the collection won't do it, because nothing has changed that would cause
                    // the buttons to re-render. But some of them may be showing a string like "Missing title" that
                    // is localizable. This is not very efficient, as we may process updates for many books that
                    // don't need it or don't even have buttons due to laziness. But changing UI language is really rare.
                    foreach (var info in collection.GetBookInfos())
                    {
                        BookCommands.RequestButtonLabelUpdate(collection.PathToDirectory, info.Id);
                    }
                }
            });
        }
Пример #5
0
        private bool LoadOneCollection(BookCollection collection, FlowLayoutPanel flowLayoutPanel)
        {
            collection.CollectionChanged += OnCollectionChanged;
            bool loadedAtLeastOneBook = false;

            foreach (Book.BookInfo bookInfo in collection.GetBookInfos())
            {
                try
                {
                    var isSuitableSourceForThisEditableCollection = (_model.IsShellProject && bookInfo.IsSuitableForMakingShells) ||
                                                                    (!_model.IsShellProject && bookInfo.IsSuitableForVernacularLibrary);

                    if (isSuitableSourceForThisEditableCollection || collection.Type == BookCollection.CollectionType.TheOneEditableCollection)
                    {
                        if (!bookInfo.IsExperimental || Settings.Default.ShowExperimentalBooks)
                        {
                            loadedAtLeastOneBook = true;
                            AddOneBook(bookInfo, flowLayoutPanel);
                        }
                    }
                }
                catch (Exception error)
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Could not load the book at " + bookInfo.FolderPath);
                }
            }
            return(loadedAtLeastOneBook);
        }
Пример #6
0
        public void SelectBook(Book book, bool aboutToEdit = false)
        {
            if (_currentSelection == book)
            {
                return;
            }
            // We don't need to reload the collection just because we make changes bringing the book up to date.
            if (book != null)
            {
                BookCollection.TemporariliyIgnoreChangesToFolder(book.FolderPath);
            }

            // The bookdata null test prevents doing this on books not sufficiently initialized to
            // BringUpToDate, typically only in unit tests.
            if (book != null && book.BookData != null && book.IsEditable)
            {
                book?.BringBookUpToDate(new NullProgress());
            }

            _currentSelection = book;

            InvokeSelectionChanged(aboutToEdit);
            Settings.Default.CurrentBookPath = book?.FolderPath ?? "";
            Settings.Default.Save();
        }
Пример #7
0
        public static void RefUse()
        {
            var bc = new BookCollection();

            bc.ListBooks();

            ref var book = ref bc.GetBookByTitle("Call of the wild, The");
 public void Setup()
 {
     Palaso.Reporting.ErrorReport.IsOkToInteractWithUser = false;
     _folder      = new TemporaryFolder("BookCollectionTests");
     _fileLocator = new BloomFileLocator(new CollectionSettings(), new XMatterPackFinder(new string[] {}), ProjectContext.GetFactoryFileLocations(), ProjectContext.GetFoundFileLocations());
     _collection  = new BookCollection(_folder.Path, BookCollection.CollectionType.TheOneEditableCollection, new BookSelection());
 }
Пример #9
0
        static void Main(string[] args)
        {
            BookCollection collection = new BookCollection();

            collection.AddBook(new Book {
                BookID = 1, Title = "Pro C#"
            });
            collection.AddBook(new Book {
                BookID = 2, Title = "2 States"
            });
            collection.AddBook(new Book {
                BookID = 3, Title = "A Suitable Boy"
            });
            collection.AddBook(new Book {
                BookID = 4, Title = "King Lear"
            });

            //var iterator = collection.GetEnumerator();
            //while(iterator.MoveNext())
            //    Console.WriteLine(iterator.Current.Title);
            foreach (var book in collection)
            {
                Console.WriteLine(book.Title);
            }
            Console.WriteLine("The total no of books: " + collection.Total);
            for (int i = 0; i < collection.Total; i++)
            {
                Console.WriteLine(collection[i].Title);
            }
        }
Пример #10
0
        private async void InsertBook()
        {
            ErrorMsgVisibility = Visibility.Collapsed;
            if (!CheckAllInputFields())
            {
                return;
            }

            var _searchedBook = BookCollection.FirstOrDefault(s => s.AuthorName == AuthorName);

            // Check if there is already a book with same name and same authorname

            if (_searchedBook != null && _searchedBook.BookName == BookName)
            {
                ErrorMsg           = Properties.Resources.SameBookExistMsg;
                ErrorMsgVisibility = Visibility.Visible;
                return;
            }

            BookModel book = new BookModel()
            {
                BookId     = DateTime.Now.ToString().GetHashCode().ToString("x"),
                BookName   = this.BookName,
                AuthorName = this.AuthorName,
                Quantity   = Convert.ToInt32(this.Quantity)
            };

            _log.Message("Adding NewBook");
            await _dataAccess.InsertData(book, Properties.Resources.InsertBook);

            GetBooks();
            InvokeBookUpdate();
            ClearAllField();
        }
Пример #11
0
    static void Main(string[] args)
    {
        DataContractJsonSerializer ser =
            new DataContractJsonSerializer(
                typeof(BookCollection),
                new List <Type>(),           /* knownTypes */
                int.MaxValue,                /* maxItemsInObjectGraph */
                false,                       /* ignoreExtensionDataObject */
                new BookTypeSurrogate(),     /* dataContractSurrogate */
                false                        /* alwaysEmitTypeInformation */
                );
        string json = "{"
                      + "\"collectionname\":\"Books\","
                      + "\"collectionitems\": [ "
                      + "[\"12345-67890\",201,\"Book One\"],"
                      + "[\"09876-54321\",45,\"Book Two\"]"
                      + "]"
                      + "}";

        using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
        {
            BookCollection obj = ser.ReadObject(ms) as BookCollection;
            using (MemoryStream ms2 = new MemoryStream())
            {
                ser.WriteObject(ms2, obj);
                string serializedJson = Encoding.UTF8.GetString(ms2.GetBuffer(), 0, (int)ms2.Length);
            }
        }
    }
Пример #12
0
        /// <summary>
        /// Consutructor.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="updateBook"></param>
        public async Task <BookDTO> UpdateBook(string id, BookCollection updatedBook)
        {
            var applyFilter = _builderFilter.Where(bookInDb => bookInDb.Id == id);

            if (await _context.BookCollection.Find(applyFilter).FirstOrDefaultAsync() == null)
            {
                throw new NotFoundException("the book with Id " + id + " is not in DB");
            }
            var update = Builders <BookCollection> .Update
                         .Set("title", updatedBook.Title)
                         .Set("authors", updatedBook.Authors)
                         .Set("averageRating", updatedBook.AverageRating)
                         .Set("imageLinks", updatedBook.ImageLinks)
                         .Set("industryIdentifiers", updatedBook.IndustryIdentifiers)
                         .Set("infoLink", updatedBook.InfoLink)
                         .Set("language", updatedBook.Language)
                         .Set("pageCount", updatedBook.PageCount)
                         .Set("previewLink", updatedBook.PreviewLink)
                         .Set("printType", updatedBook.PrintType)
                         .Set("publishedDate", updatedBook.PublishedDate)
                         .Set("publisher", updatedBook.Publisher)
                         .Set("ratingsCount", updatedBook.RatingsCount);

            await _context.BookCollection.UpdateOneAsync(applyFilter, update);

            var result = await _context.BookCollection.Find(applyFilter).FirstOrDefaultAsync();

            return(_mapper.Map <BookDTO>(result));
        }
Пример #13
0
        private void UpdateCollection(BookCollection bookCollection)
        {
            using (Context db = new Context())
            {
                if (bookCollection.Id == 0)
                {
                    db.BookCollections.Add(bookCollection);
                }
                else
                {
                    var model = db.BookCollections.Single(c => c.Id == bookCollection.Id);

                    if (model != null)
                    {
                        model.Name            = bookCollection.Name;
                        model.Author          = bookCollection.Author;
                        model.Number_of_Pages = bookCollection.Number_of_Pages;
                        model.Publisher       = bookCollection.Publisher;
                        model.Amount          = bookCollection.Amount;
                        model.Local           = bookCollection.Local;
                        model.Purchase_Date   = bookCollection.Purchase_Date;
                        model.Book_Id         = bookCollection.Book_Id;
                    }
                }

                db.SaveChanges();
            }
        }
Пример #14
0
 public PublisherBookGroup(BookCollection books, int publisherGroupId, string publisherGroupName)
 {
     PublisherGroupId = publisherGroupId;
     PublisherGroupName = publisherGroupName;
     Books = books;
     SetAuthors();
 }
 public BookTitleCollection GetBooks(BookCollection bookCollection)
 {
     var titles = bookCollection
         .GroupBy(x => x.Accept(y=>y))
         .Select(x => x.Key);
     return new BookTitleCollection(titles);
 }
Пример #16
0
        public ProjectContext(string projectSettingsPath, IContainer parentContainer)
        {
            BuildSubContainerForThisProject(projectSettingsPath, parentContainer);

            ProjectWindow = _scope.Resolve <Shell>();

            string collectionDirectory = Path.GetDirectoryName(projectSettingsPath);

            //should we save a link to this in the list of collections?
            var collectionSettings = _scope.Resolve <CollectionSettings>();

            if (collectionSettings.IsSourceCollection)
            {
                AddShortCutInComputersBloomCollections(collectionDirectory);
            }

            if (Path.GetFileNameWithoutExtension(projectSettingsPath).ToLower().Contains("web"))
            {
                BookCollection editableCollection    = _scope.Resolve <BookCollection.Factory>()(collectionDirectory, BookCollection.CollectionType.TheOneEditableCollection);
                var            sourceCollectionsList = _scope.Resolve <SourceCollectionsList>();
                _bloomServer = new BloomServer(_scope.Resolve <CollectionSettings>(), editableCollection, sourceCollectionsList, _scope.Resolve <HtmlThumbNailer>());
                _bloomServer.Start();
            }
            else
            {
                if (Settings.Default.ImageHandler != "off")
                {
                    _imageServer = _scope.Resolve <ImageServer>();

                    _imageServer.StartWithSetupIfNeeded();
                }
            }
        }
Пример #17
0
        static void Main()
        {
            var bc = new BookCollection();

            bc.ListBooks();

            ref var book = ref bc.GetBookByTitle("Call of the Wild, The"); // ref local
Пример #18
0
        static void Main(string[] args)
        {
            BookCollection collection = new BookCollection();

            collection[0] = new Book("Harry Potter");
            collection[1] = new Book("Lord of the Ring");
            collection[2] = new Book("Dac Nhan Tam");


            // Create iterator
            Iterator iterator = collection.CreateIterator();

            // Skip every other item
            iterator.Step = 1;

            System.Console.WriteLine("Iterating over collection:");

            for (Book book = iterator.First(); !iterator.IsDone; book = iterator.Next())
            {
                System.Console.WriteLine(book.Name);
            }

            // Wait for user
            System.Console.ReadKey();
        }
Пример #19
0
        public string Get(int id)
        {
            Book   returnedBook = BookCollection.GetBook(id);
            string bookJson     = JsonConvert.SerializeObject(returnedBook, Formatting.Indented);

            return(bookJson);
        }
 private IEnumerable<IGrouping<int, IGrouping<BookTitle, Book>>> GroupBooks(BookCollection bookCollection)
 {
     return bookCollection
         .GroupBy(x => x.Accept(y=>y))
         .GroupBy(x => x.Count())
         .OrderBy(x => x.Key);
 }
Пример #21
0
        public void UpdateCollectionValidation(BookCollection bookCollection)
        {
            if (bookCollection.Registration_Order > 0 && !String.IsNullOrEmpty(bookCollection.Name) && !String.IsNullOrEmpty(bookCollection.Author) && !String.IsNullOrEmpty(bookCollection.Publisher))
            {
                int collectionId = GetCollectionId(bookCollection.Name, bookCollection.Author, bookCollection.Publisher);

                if (collectionId != 0)
                {
                    bookCollection.Id = collectionId;
                }

                try
                {
                    UpdateCollection(bookCollection);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error when trying to update collection, details: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("The Collection Name, Author and Publisher are required and Order should be granter then 0.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #22
0
        /// <summary>
        /// Handles the recursion through directories: if a folder looks like a Bloom book upload it; otherwise, try its children.
        /// Invisible folders like .hg are ignored.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="dlg"></param>
        /// <param name="container"></param>
        /// <param name="context"></param>
        private void UploadInternal(string folder, BulkUploadProgressDlg dlg, ApplicationContainer container, ref ProjectContext context)
        {
            if (Path.GetFileName(folder).StartsWith("."))
            {
                return;                 // secret folder, probably .hg
            }
            if (Directory.GetFiles(folder, "*.htm").Count() == 1)
            {
                // Exactly one htm file, assume this is a bloom book folder.
                dlg.Progress.WriteMessage("Starting to upload " + folder);

                // Make sure the files we want to upload are up to date.
                // Unfortunately this requires making a book object, which requires making a ProjectContext, which must be created with the
                // proper parent book collection if possible.
                var parent         = Path.GetDirectoryName(folder);
                var collectionPath = Directory.GetFiles(parent, "*.bloomCollection").FirstOrDefault();
                if (collectionPath == null && context == null)
                {
                    collectionPath = Settings.Default.MruProjects.Latest;
                }
                if (context == null || context.SettingsPath != collectionPath)
                {
                    if (context != null)
                    {
                        context.Dispose();
                    }
                    // optimise: creating a context seems to be quite expensive. Probably the only thing we need to change is
                    // the collection. If we could update that in place...despite autofac being told it has lifetime scope...we would save some time.
                    // Note however that it's not good enough to just store it in the project context. The one that is actually in
                    // the autofac object (_scope in the ProjectContext) is used by autofac to create various objects, in particular, books.
                    context = container.CreateProjectContext(collectionPath);
                }
                var server = context.BookServer;
                var book   = server.GetBookFromBookInfo(new BookInfo(folder, true));
                book.BringBookUpToDate(new NullProgress());

                // Assemble the various arguments needed to make the objects normally involved in an upload.
                // We leave some constructor arguments not actually needed for this purpose null.
                var bookSelection = new BookSelection();
                bookSelection.SelectBook(book);
                var currentEditableCollectionSelection = new CurrentEditableCollectionSelection();
                if (collectionPath != null)
                {
                    var collection = new BookCollection(collectionPath, BookCollection.CollectionType.SourceCollection,
                                                        bookSelection);
                    currentEditableCollectionSelection.SelectCollection(collection);
                }
                var publishModel = new PublishModel(bookSelection, new PdfMaker(), currentEditableCollectionSelection, null, server, _htmlThumbnailer);
                publishModel.PageLayout = book.GetLayout();
                var    view = new PublishView(publishModel, new SelectedTabChangedEvent(), new LocalizationChangedEvent(), this, null);
                string dummy;
                FullUpload(book, dlg.Progress, view, out dummy, dlg);
                return;
            }
            foreach (var sub in Directory.GetDirectories(folder))
            {
                UploadInternal(sub, dlg, container, ref context);
            }
        }
Пример #23
0
 public BloomServer(CollectionSettings collectionSettings, BookCollection booksInProjectLibrary,
                    SourceCollectionsList sourceCollectionsesList, HtmlThumbNailer thumbNailer)
 {
     _collectionSettings      = collectionSettings;
     _booksInProjectLibrary   = booksInProjectLibrary;
     _sourceCollectionsesList = sourceCollectionsesList;
     _thumbNailer             = thumbNailer;
 }
Пример #24
0
        static void Main(string[] args)
        {
            var bc = new BookCollection();

            bc.ListBooks();

            var     index = -1;
            ref var book  = ref bc.GetBookByTitle("Call of the Wild, The", ref index);
Пример #25
0
 public BloomServer(CollectionSettings collectionSettings, BookCollection booksInProjectLibrary,
                    SourceCollectionsList sourceCollectionsesList, BookThumbNailer thumbNailer)
     : base(new RuntimeImageProcessor(new BookRenamedEvent()), thumbNailer)
 {
     _collectionSettings      = collectionSettings;
     _booksInProjectLibrary   = booksInProjectLibrary;
     _sourceCollectionsesList = sourceCollectionsesList;
 }
Пример #26
0
        // This method displays the following output:
        // Original values in Main.  Name: Fasteners, ID: 54321
        // Back in Main.  Name: Stapler, ID: 12345

        // </Snippet3>

        private static void BookCollectionExample()
        {
            // <Snippet5>
            var bc = new BookCollection();

            bc.ListBooks();

            ref var book = ref bc.GetBookByTitle("Call of the Wild, The");
Пример #27
0
 public MainForm(BookCollection pBookCollection)
 {
     _pBookCollection = pBookCollection;
     _field           = new Field(4, 4);
     InitializeComponent();
     h_ShowBooks();
     h_FillField();
 }
        public void When_a_book_collection_with_no_books_is_asked_to_RemoveSet__should_remain_empty()
        {
            var bookCollection = new BookCollection(new Book[0]);

            var result = new BookSetDiscoverer().RemoveSet(bookCollection);

            Assert.AreEqual("", result.ToString());
        }
Пример #29
0
    public void Results(string query)
    {
        BookCollectionManager man  = new BookCollectionManager();
        BookCollection        data = man.GetBookCollection(query, 1);

        ViewData["BookCollection"] = data;
        RenderView("Results");
    }
Пример #30
0
        public void Setup()
        {
            Palaso.Reporting.ErrorReport.IsOkToInteractWithUser = false;
            _folder = new TemporaryFolder("BookCollectionTests");
//			_fileLocator = new BloomFileLocator(new CollectionSettings(), new XMatterPackFinder(new string[]{}), new string[] { FileLocator.GetDirectoryDistributedWithApplication("root"), FileLocator.GetDirectoryDistributedWithApplication("factoryCollections") });
            _fileLocator = new FileLocator(new string[] { FileLocator.GetDirectoryDistributedWithApplication("BloomBrowserUI"), FileLocator.GetDirectoryDistributedWithApplication("browserui/bookCss"), FileLocator.GetDirectoryDistributedWithApplication("factoryCollections") });

            _collection = new BookCollection(_folder.Path, BookCollection.CollectionType.TheOneEditableCollection, new BookSelection());
        }
Пример #31
0
 protected void Page_Load(object sender, EventArgs e)
 {
     BookCollection.loadBooks();
     foreach (var item in BookCollection.myBooks)
     {
         books = books + "<p class='item'><a href='BookDetail.aspx?recipe=" + item.ID.ToString() + "'><span>" + item.Name + "</span></a></p>";
     }
     multiRecipe.InnerHtml = books;
 }
        public void When_a_book_collection_adds_a_book__should_show_as_having_that_book()
        {
            var bookCollection = new BookCollection(new[]
                                                        {
                                                            new Book(BookTitle.BookOne)
                                                        });

            Assert.AreEqual("1", bookCollection.ToString());
        }
 public BookController()
 {
     bookCollection = new BookCollection();
     books = new List<Book>();
     if(bookCollection.GetBookCollection != null)
     {
         books = bookCollection.GetBookCollection;
     }
 }
Пример #34
0
        public void InsertBook_NotPresent_InsertsInEmptyList()
        {
            var infoNew    = new BookInfo("book11", true);
            var state      = new List <BookInfo>();
            var collection = new BookCollection(state);

            collection.InsertBookInfo(infoNew);
            Assert.That(state[0], Is.EqualTo(infoNew), "book info should be inserted between book10 and book20");
        }
Пример #35
0
 public void AddBook(Book Book, int Copies)
 {
     if (BookCollection.ContainsKey(Book))
     {
         Console.WriteLine($"Book {Book} is allready in the collection of {Name}.");
         return;
     }
     BookCollection.Add(Book, new BookStock(Copies));
 }
Пример #36
0
 public BloomServer(CollectionSettings collectionSettings, BookCollection booksInProjectLibrary,
                    SourceCollectionsList sourceCollectionsesList, HtmlThumbNailer thumbNailer)
     : base(new LowResImageCache(new BookRenamedEvent()))
 {
     _collectionSettings      = collectionSettings;
     _booksInProjectLibrary   = booksInProjectLibrary;
     _sourceCollectionsesList = sourceCollectionsesList;
     _thumbNailer             = thumbNailer;
 }
Пример #37
0
 public bool SearchBook(Book aBook, out int availableCopies)
 {
     if (BookCollection.ContainsKey(aBook))
     {
         availableCopies = BookCollection[aBook].AvailableBooks;
         return(true);
     }
     availableCopies = 0;
     return(false);
 }
        static void Main(string[] args)
        {
            var BookList   = new BookCollection().GetBooks();
            var cheapBooks = BookList.Where(b => b.Price < 10).OrderBy(bk => bk.Title);

            foreach (var book in cheapBooks)
            {
                Console.WriteLine($"Book: {book.Title} -- Price: {book.Price}.");
            }

            // Linq-Query and Linq-Expression are same;
            // Linq-Query:

            /* var b0 = from b in BookList
             *       where b.Price < 10
             *       orderby b.Title
             *       select b.Title; */
            // Linq-Expression:
            /* var b1 = BookList.Where(b => b.Price < 10).OrderBy(bk => bk.Title).Select(b => b.Title); */

            // last 3 in Linq Expression
            dynamic Last3 = BookList.Skip(2).Take(3);

            Console.WriteLine($"Take 1s to jump over 2 books...");
            Thread.Sleep(1000);
            foreach (var l3b in Last3)
            {
                Console.WriteLine($"Book: {l3b.Title} -- Price: {l3b.Price}.");
            }

            // common Linq-Expression

            /* BookList.Add();
             * BookList.AddRange();
             * BookList.Aggregate();
             * BookList.Find();
             * BookList.FindIndex();
             * BookList.FindLast();
             * BookList.ElementAtOrDefault();
             * BookList.First(); || BookList.FirstOrDefault();
             * BookList.Last(); || BookList.LastOrDefault();
             * BookList.Single(); || BookList.SingleOrDefault();
             *
             * BookList.Min(); || BookList.Max(); || BookList.Count(); || BookList.Sum(); ||BookList.Average();
             *
             * BookList.Skip().Take(); */

            // Nullable now...
            Nullable_Ops.ShowNullableDates();
            DyanmicVariables.ShowDynamicVariables();

            Exist exi = new Exist();

            exi.ExistByEnter();
        }
        public void When_a_book_collection_adds_books__should_show_them_separated_by_semicolons()
        {
            var bookCollection = new BookCollection(new[]
                                                        {
                                                            new Book(BookTitle.BookOne),
                                                            new Book(BookTitle.BookTwo),
                                                            new Book(BookTitle.BookThree),
                                                        });

            Assert.AreEqual("1;2;3", bookCollection.ToString());
        }
        public void When_a_book_collection_with_one_book_is_asked_to_RemoveSet__should_remove_the_one_book()
        {
            var bookCollection = new BookCollection(new[]
                                                        {
                                                            new Book(BookTitle.BookOne)
                                                        });

            var result = new BookSetDiscoverer().RemoveSet(bookCollection);

            Assert.AreEqual("", result.ToString());
        }
        public void When_a_book_collection_adds_books_out_of_proper_order__should_show_the_books_in_order_regardless()
        {
            var bookCollection = new BookCollection(new[]
                                                        {
                                                            new Book(BookTitle.BookTwo),
                                                            new Book(BookTitle.BookOne),
                                                            new Book(BookTitle.BookThree),
                                                            new Book(BookTitle.BookOne),
                                                        });

            Assert.AreEqual("1;1;2;3", bookCollection.ToString());
        }
        public void UndoablePropertyValueRedo()
        {
            BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( ClockWorkOrange );
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             // Redo of a basic property
             UndoablePropertyValue<BookCollection, String> nameChange =
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my favorite books", "A few of my books" );
             nameChange.Redo();
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 3, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.IsTrue( myBooks.Library.Contains( ClockWorkOrange ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );

             UndoablePropertyValue<BookCollection, Book> favoriteChange =
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, ClockWorkOrange, MereChristianity );
             favoriteChange.Redo();
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 3, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.IsTrue( myBooks.Library.Contains( ClockWorkOrange ) );
             Assert.AreEqual( MereChristianity, myBooks.FavoriteBook );

             // Redo of a removal from a collection
             UndoablePropertyValue<BookCollection, Book> removeBook =
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Remove, ClockWorkOrange, null );
             removeBook.Redo();
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( MereChristianity, myBooks.FavoriteBook );

             // Redo of an addition to a collection
             UndoablePropertyValue<BookCollection, Book> addBook =
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, MereChristianity );
             addBook.Redo();
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 3, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( MereChristianity, myBooks.FavoriteBook );
        }
        public BookTitleCollection GetBooks(BookCollection bookCollection)
        {
            var bookSets = GroupBooks(bookCollection);
            var oneBookFromEachDoubleStockedTitle = bookSets
                .Last()
                .Select(x => x.Key);

            var oneSingleStockedTitle = new[]
                                 {
                                     bookSets.First().First().Key
                                 };

            var titles = oneBookFromEachDoubleStockedTitle.Union(oneSingleStockedTitle);
            return new BookTitleCollection(titles);
        }
        public void When_provided_with_any_other_combination_of_books__should_indicate_it_does_not_qualify_for_a_special_discount()
        {
            var bookCollection = new BookCollection(new[]
                                                        {
                                                            new Book(BookTitle.BookOne),
                                                            new Book(BookTitle.BookTwo),
                                                            new Book(BookTitle.BookThree),
                                                            new Book(BookTitle.BookFour),

                                                            new Book(BookTitle.BookThree),
                                                            new Book(BookTitle.BookFour),
                                                            new Book(BookTitle.BookFive),
                                                        });

            Assert.IsFalse(new SpecialDiscountCalculator().WorksFor(bookCollection));
        }
Пример #45
0
    public BookCollection GetBookCollection(string query, int page)
    {
        BookCollection returnCollection = new BookCollection();

        for(int i = 0; i < 25; i++)
        {
            Book newBook = new Book();
            newBook.Title = "Buch " + i.ToString();
            newBook.Description = "Beschreibung" + i.ToString();
            newBook.PicUrl = "PicUrl " + i.ToString();

            returnCollection.Add(newBook);
        }

        return returnCollection;
    }
        public void When_provided_with_books_that_make_up_two_fourbook_discount__should_indicate_it_qualifies_for_a_special_discount()
        {
            var bookCollection = new BookCollection(new[]
                                                        {
                                                            new Book(BookTitle.BookOne),
                                                            new Book(BookTitle.BookTwo),
                                                            new Book(BookTitle.BookThree),
                                                            new Book(BookTitle.BookFour),

                                                            new Book(BookTitle.BookTwo),
                                                            new Book(BookTitle.BookThree),
                                                            new Book(BookTitle.BookFour),
                                                            new Book(BookTitle.BookFive),
                                                        });

            Assert.IsTrue(new SpecialDiscountCalculator().WorksFor(bookCollection));
        }
        public void UndoablePropertyValueConstruct()
        {
            BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my books";
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             // Construct an object representing a change to a basic property
             UndoablePropertyValue<BookCollection, String> nameChange =
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my books", "Some good books" );

             // Construct an object representing an addition to a collection
             UndoablePropertyValue<BookCollection, Book> addBook =
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, MereChristianity );

             // Construct an object representing a removal from a collection
             UndoablePropertyValue<BookCollection, Book> removeBook =
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Remove, MereChristianity, null );
        }
Пример #48
0
        public void UndoRedoManagerCanRedo()
        {
            UndoRedoManager undoRedoManager = new UndoRedoManager();

             BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( ClockWorkOrange );
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             // Originally, cannot redo, there is nothing to redo.
             Assert.IsFalse( undoRedoManager.CanRedo );

             // Add an item, still nothing to redo
             myBooks.Name = "Some Books";
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my favorite books", "Some Books" ) );
             Assert.IsFalse( undoRedoManager.CanRedo );

             // Undo this item, we now have something to redo
             undoRedoManager.Undo();
             Assert.IsTrue( undoRedoManager.CanRedo );

             // Redo it, and we no longer have anything to redo
             undoRedoManager.Redo();
             Assert.IsFalse( undoRedoManager.CanRedo );

             // Undo it, make a change, undo that one, have two items to redo
             undoRedoManager.Undo();
             myBooks.FavoriteBook = MereChristianity;
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, ClockWorkOrange, MereChristianity ) );
             undoRedoManager.Undo();

             Assert.IsTrue( undoRedoManager.CanRedo );
             undoRedoManager.Redo();
             Assert.IsTrue( undoRedoManager.CanRedo );
             undoRedoManager.Redo();
             Assert.IsFalse( undoRedoManager.CanRedo );
        }
        //should be private, but made public for tests
        public bool WorksFor(BookCollection bookCollection)
        {
            if (bookCollection.IsEmpty()) return false;
            //e.g. a book collection fitting this profile: 1;2;3;3;4;4;5;5
            //when grouped by GroupBooks, we would have two groups:
            // first group: 1-book-per-title (2 items: (1) ; (2))
            // second group: 2-books-per-title (3 items: (3;3) ; (4;4) ; (5;5))
            var bookSets = GroupBooks(bookCollection);

            bool exactlyTwoQuantitiesOfBooksRemain = bookSets.Count() == 2;
            bool theSmallerGroupingContainsBooksSpanningTwoTitles = bookSets.First().Count() == 2;
            bool theSmallerGroupingContainsOneBookPerTitle = bookSets.First().Key == 1;
            bool theLargerGroupingContainsBooksSpanningThreeTitles = bookSets.Last().Count() == 3;
            bool theLargerGroupingContainsTwoBooksPerTitle = bookSets.Last().Key == 2;

            return exactlyTwoQuantitiesOfBooksRemain
                && theSmallerGroupingContainsBooksSpanningTwoTitles
                && theSmallerGroupingContainsOneBookPerTitle
                && theLargerGroupingContainsBooksSpanningThreeTitles
                && theLargerGroupingContainsTwoBooksPerTitle;
        }
Пример #50
0
        public void UndoRedoManagerCanUndo()
        {
            UndoRedoManager undoRedoManager = new UndoRedoManager();

             BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( ClockWorkOrange );
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             // Originally, cannot undo, there is nothing to undo.
             Assert.IsFalse( undoRedoManager.CanUndo );

             // Add an item, can now undo
             myBooks.Name = "Some Books";
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my favorite books", "Some Books" ) );
             Assert.IsTrue( undoRedoManager.CanUndo );

             // After undoing the one change, there is nothing to undo
             undoRedoManager.Undo();
             Assert.IsFalse( undoRedoManager.CanUndo );

             // After redoing, we should be able to undo it again
             undoRedoManager.Redo();
             Assert.IsTrue( undoRedoManager.CanUndo );

             // Make another change, then undo it, should still be able to undo as the first one is still in there.
             myBooks.FavoriteBook = MereChristianity;
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, ClockWorkOrange, MereChristianity ) );
             Assert.IsTrue( undoRedoManager.CanUndo );

             undoRedoManager.Undo();
             Assert.IsTrue( undoRedoManager.CanUndo );

             undoRedoManager.Undo();
             Assert.IsFalse( undoRedoManager.CanUndo );
        }
Пример #51
0
 /// <summary>
 /// private constructor, so no one can call this
 /// except for the class itself
 /// </summary>
 private Business()
 {
     BookCollection = new BookCollection();
 }
Пример #52
0
 /// <summary>
 /// calls the file-loader and sets this bookcollection 
 /// to the content
 /// </summary>
 public void LoadFile()
 {
     this.BookCollection = LoadObject();
 }
Пример #53
0
        public void UndoRedoManagerUndoAndRedo()
        {
            UndoRedoManager undoRedoManager = new UndoRedoManager();

             BookCollection myBooks = new BookCollection();
             myBooks.Name = "A few of my favorite books";
             myBooks.Library.Add( DarwinsGod );
             myBooks.Library.Add( SoftwareEstimates );
             myBooks.FavoriteBook = ClockWorkOrange;

             DarwinsGod.Pages = 700;
             SoftwareEstimates.Pages = 800;

             Assert.AreEqual( "A few of my favorite books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             // Simulate the following editting that got to the state above:
             //    1 - Name -> "Some Books"
             //    2 - Library -> Add MereChristianity
             //    3 - Name -> "A few of my books"
             //    4 - Favorite -> DarwinsGod
             //    5 - Library -> Add DarwinsGod
             //    6 - DarwinsGod -> change pages to 700
             //    7 - SoftwareEstimates -> change pages to 800
             //    8 - Library -> Remove MereChristianity
             //    9 - Favorite -> ClockWorkOrange
             //   10 - Library -> Add SoftwareEstimates
             //   11 - Name -> "A few of my favorite books"
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, null, "Some Books" ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, MereChristianity ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "Some Books", "A few of my books" ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, null, DarwinsGod ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, DarwinsGod ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<Book, Int16>( DarwinsGod, "Pages", UndoableActions.Modify, 338, 700 ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<Book, Int16>( SoftwareEstimates, "Pages", UndoableActions.Modify, 308, 800 ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Remove, MereChristianity, null ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, DarwinsGod, ClockWorkOrange ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, SoftwareEstimates ) );
             undoRedoManager.Add(
            new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my books", "A few of my favorite books" ) );

             // Can undo, cannot redo.  Undo five items, verify undo() performed at each step.
             Assert.IsTrue( undoRedoManager.CanUndo );
             Assert.IsFalse( undoRedoManager.CanRedo );
             undoRedoManager.Undo(); // 11
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 10
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 1, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 9
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 1, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 8
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Undo(); // 7
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 308, SoftwareEstimates.Pages );

             // Redo two items
             undoRedoManager.Redo(); // 7
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             undoRedoManager.Redo(); // 8
             Assert.AreEqual( "A few of my books", myBooks.Name );
             Assert.AreEqual( 1, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.AreEqual( DarwinsGod, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             // Undo all items
             undoRedoManager.Undo(); // 8
             undoRedoManager.Undo(); // 7
             undoRedoManager.Undo(); // 6
             undoRedoManager.Undo(); // 5
             undoRedoManager.Undo(); // 4
             undoRedoManager.Undo(); // 3
             undoRedoManager.Undo(); // 2
             undoRedoManager.Undo(); // 1
             Assert.IsFalse( undoRedoManager.CanUndo );
             Assert.IsTrue( String.IsNullOrEmpty( myBooks.Name ) );
             Assert.AreEqual( 0, myBooks.Library.Count );
             Assert.IsNull( myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 338, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 308, SoftwareEstimates.Pages );

             // Redo all items
             undoRedoManager.Redo(); //  1
             undoRedoManager.Redo(); //  2
             undoRedoManager.Redo(); //  3
             undoRedoManager.Redo(); //  4
             undoRedoManager.Redo(); //  5
             undoRedoManager.Redo(); //  6
             undoRedoManager.Redo(); //  7
             undoRedoManager.Redo(); //  8
             undoRedoManager.Redo(); //  9
             undoRedoManager.Redo(); // 10
             undoRedoManager.Redo(); // 11
             Assert.IsFalse( undoRedoManager.CanRedo );
             Assert.AreEqual( "A few of my favorite books", myBooks.Name );
             Assert.AreEqual( 2, myBooks.Library.Count );
             Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) );
             Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) );
             Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook );
             Assert.AreEqual( 192, ClockWorkOrange.Pages );
             Assert.AreEqual( 700, DarwinsGod.Pages );
             Assert.AreEqual( 227, MereChristianity.Pages );
             Assert.AreEqual( 800, SoftwareEstimates.Pages );

             // Reset pages on potentially changed books
             DarwinsGod.Pages = 338;
             SoftwareEstimates.Pages = 308;
        }
        public void When_a_book_collection_is_empty__should_show_itself_as_empty()
        {
            var bookCollection = new BookCollection(new Book[0]);

            Assert.AreEqual("", bookCollection.ToString());
        }