public void GetValidBookModel()
        {
            var expectedBook = new Book
            {
                Id = Guid.NewGuid(),
                Price = 7.77,
                Title = "Joyland",
                Author = new Author
                    {
                        Id = Guid.NewGuid(),
                        FirstName = "Stephen",
                        LastName = "King",
                        Rank = 2
                    }
            };
            _fileSystemStorage.Save(expectedBook);

            var book = _fileSystemStorage.Get(expectedBook.Id);

            Assert.AreEqual(expectedBook.Id, book.Id);
            Assert.AreEqual(expectedBook.Price, book.Price);
            Assert.AreEqual(expectedBook.Title, book.Title);
            Assert.AreEqual(expectedBook.Author.FirstName, book.Author.FirstName);
            Assert.AreEqual(expectedBook.Author.LastName, book.Author.LastName);
            Assert.AreEqual(expectedBook.Author.Id, book.Author.Id);
            Assert.AreEqual(expectedBook.Author.Rank, book.Author.Rank);
        }
        private void DataPreparation()
        {
            var book = new Book
            {
                Price = 21.62,
                Title = "The Twelve : A Novel",
                Author = new Author
                    {
                        Id = Guid.NewGuid(),
                        FirstName = "Justin",
                        LastName = "Cronin",
                        Rank = 23
                    }
            };

            var customer = new Customer
            {
                Address = "Somewhere over the rainbow",
                CardNumber = "221234324",
                FirstName = "Clark",
                LastName = "Kent"
            };

            _bookList.Add(book);
            _customerList.Add(customer);
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var applicationSettings = new ApplicationSettings();
            var bookRepo = new FileSystemStorage<Book>(applicationSettings);
            var customerRepo = new FileSystemStorage<Customer>(applicationSettings);

            var bookShopService = new BookShopService(bookRepo, customerRepo);

            #region data preparation
            var book = new Book
            {
                Price = 21.62,
                Title = "The Twelve : A Novel",
                Author = new Author
                {
                    Id = Guid.NewGuid(),
                    FirstName = "Justin",
                    LastName = "Cronin",
                    Rank = 23
                }
            };

            var customer = new Customer
            {
                Address = "Somewhere over the rainbow",
                CardNumber = "221234324",
                FirstName = "Clark",
                LastName = "Kent"
            };
            #endregion

            bookShopService.BuyOneBook(customer, book);
        }
        public void ListAllBookModels()
        {
            _fileSystemStorage.EraseAll();
            var expectedBook1 = new Book
            {
                Id = Guid.NewGuid(),
                Price = 8.48,
                Title = "Star Wars: Vader's Little Princess",
                Author = new Author
                    {
                        Id = Guid.NewGuid(),
                        FirstName = "Jeffrey",
                        LastName = "Brown",
                        Rank = 3
                    }
            };
            var expectedBook2 = new Book
            {
                Id = Guid.NewGuid(),
                Price = 9.81,
                Title = "Wonder",
                Author = new Author
                    {
                        Id = Guid.NewGuid(),
                        FirstName = "R. J.",
                        LastName = "Palacio",
                        Rank = 3
                    }
            };
            _fileSystemStorage.Save(expectedBook1);
            _fileSystemStorage.Save(expectedBook2);

            var books = _fileSystemStorage.List();
            Assert.IsNotNull(books);
            Assert.AreEqual(2, books.Count);

            var book1 = books.First(f => f.Id == expectedBook1.Id);
            Assert.AreEqual(expectedBook1.Id, book1.Id);
            Assert.AreEqual(expectedBook1.Price, book1.Price);
            Assert.AreEqual(expectedBook1.Title, book1.Title);
            Assert.AreEqual(expectedBook1.Author.FirstName, book1.Author.FirstName);
            Assert.AreEqual(expectedBook1.Author.LastName, book1.Author.LastName);
            Assert.AreEqual(expectedBook1.Author.Id, book1.Author.Id);
            Assert.AreEqual(expectedBook1.Author.Rank, book1.Author.Rank);

            var book2 = books.First(f => f.Id == expectedBook2.Id);
            Assert.AreEqual(expectedBook2.Id, book2.Id);
            Assert.AreEqual(expectedBook2.Price, book2.Price);
            Assert.AreEqual(expectedBook2.Title, book2.Title);
            Assert.AreEqual(expectedBook2.Author.FirstName, book2.Author.FirstName);
            Assert.AreEqual(expectedBook2.Author.LastName, book2.Author.LastName);
            Assert.AreEqual(expectedBook2.Author.Id, book2.Author.Id);
            Assert.AreEqual(expectedBook2.Author.Rank, book2.Author.Rank);
        }
        public void BuyOneBook(Customer customer, Book book)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            if (book == null)
                throw new ArgumentNullException("book");

            if (string.IsNullOrEmpty(customer.CardNumber))
                throw new InvalidCardNumberException();

            _bookRepository.Save(book);
            _customerRepository.Save(customer);
        }
 public void SaveValidBookModel()
 {
     var book = new Book
         {
             Price = 17.15,
             Title = "Inferno",
             Author = new Author
                 {
                     Id = Guid.NewGuid(),
                     FirstName = "Dan",
                     LastName = "Brown",
                     Rank = 1
                 }
         };
     _fileSystemStorage.Save(book);
     Console.WriteLine("The book has been saved successfully.");
 }
        public void RemoveValidBookModel()
        {
            var expectedBook = new Book
            {
                Id = Guid.NewGuid(),
                Price = 8.41,
                Title = "The Great Gatsby",
                Author = new Author
                    {
                        Id = Guid.NewGuid(),
                        FirstName = "F. Scott",
                        LastName = "Fitzgerald",
                        Rank = 3
                    }
            };
            _fileSystemStorage.Save(expectedBook);

            _fileSystemStorage.Remove(expectedBook);

            _fileSystemStorage.Get(expectedBook.Id);
        }