public void ProductRepositoryAddNewItemSaveItem()
      {
         //Arrange
         var unitOfWork = new MainBcUnitOfWork();
         IProductRepository productRepository = new ProductRepository(unitOfWork);

         var book = new Book("The book title", "Any book description", "Krasis Press", "ABC");

         book.ChangeUnitPrice(40);
         book.IncrementStock(1);
         book.GenerateNewIdentity();

         //Act
         productRepository.Add(book);
         unitOfWork.Commit();

      }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/>
        /// </summary>
        /// <param name="bookDTO"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param>
        public BookDTO AddNewBook(BookDTO bookDTO)
        {
            if (bookDTO == null)
                throw new ArgumentNullException(Messages.warning_CannotAddSoftwareWithNullInformation);

            //Create the book entity
            var newBook = new Book(bookDTO.Title, bookDTO.Description,bookDTO.Publisher,bookDTO.ISBN);
            
            //set stock and unit price
            newBook.IncrementStock(bookDTO.AmountInStock);
            newBook.ChangeUnitPrice(bookDTO.UnitPrice);

            //Assign the poid
            newBook.GenerateNewIdentity();

            //save software
            SaveProduct(newBook);

            //return software dto
            return newBook.ProjectedAs<BookDTO>();
        }
      public void FindProductsByFilterMaterializeResults()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var productRepository = new StubIProductRepository();
         var orderRepository = new StubIOrderRepository();
         productRepository.AllMatchingISpecificationOfProduct = (spec) =>
         {
            var book = new Book("title", "description", "publisher", "isbn");
            book.ChangeUnitPrice(10);
            book.GenerateNewIdentity();

            var software = new Software("title", "description", "license code");
            software.ChangeUnitPrice(10);
            software.GenerateNewIdentity();

            return new List<Product>()
            {
               book,
               software
            };
         };

         var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

         //act
         var result = salesManagement.FindProducts("filter text");

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Count == 2);
      }
      public void FindProductsInPageMaterializeResults()
      {
         //Arrange
         var customerRepository = new StubICustomerRepository();
         var productRepository = new StubIProductRepository();
         var orderRepository = new StubIOrderRepository();
         //productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>(
         //   (index, count, order, ascending) =>
         //   {
         //      var book = new Book("title", "description", "publisher", "isbn");
         //      book.ChangeUnitPrice(10M);
         //      book.GenerateNewIdentity();

         //      var software = new Software("title", "description", "license code");
         //      software.ChangeUnitPrice(10);
         //      software.GenerateNewIdentity();

         //      return new List<Product>()
         //      {
         //         book,
         //         software
         //      };
         //   });

         productRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfProductM0Boolean<string>(
            (index, count, order, ascending) =>
            {
               var book = new Book("title", "description", "publisher", "isbn");
               book.ChangeUnitPrice(10M);
               book.GenerateNewIdentity();

               var software = new Software("title", "description", "license code");
               software.ChangeUnitPrice(10);
               software.GenerateNewIdentity();

               return new List<Product>
               {
                  book,
                  software
               };

            });

         var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

         //act
         var result = salesManagement.FindProducts(0, 2);

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Count == 2);
      }
        public void EnumerableBookToListBookDTOAdapter()
        {
            //Arrange
            var book = new Book("the title", "The description","Krasis Press","ABD12");

            book.ChangeUnitPrice(10);
            book.IncrementStock(10);
            book.GenerateNewIdentity();

            var books = new List<Book>() { book };

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var booksDTO = adapter.Adapt<IEnumerable<Book>, List<BookDTO>>(books);

            //Assert
            Assert.AreEqual(books[0].Id, booksDTO[0].Id);
            Assert.AreEqual(books[0].Title, booksDTO[0].Title);
            Assert.AreEqual(books[0].Description, booksDTO[0].Description);
            Assert.AreEqual(books[0].AmountInStock, booksDTO[0].AmountInStock);
            Assert.AreEqual(books[0].UnitPrice, booksDTO[0].UnitPrice);
            Assert.AreEqual(books[0].ISBN, booksDTO[0].ISBN);
            Assert.AreEqual(books[0].Publisher, booksDTO[0].Publisher);
        }
        public void BookToBookDTOAdapter()
        {
            //Arrange
            var book = new Book("the title", "The description", "Krasis Press", "ABD12");

            book.ChangeUnitPrice(10);
            book.IncrementStock(10);

            book.GenerateNewIdentity();

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();
            var bookDTO = adapter.Adapt<Book, BookDTO>(book);

            //Assert
            Assert.AreEqual(book.Id, bookDTO.Id);
            Assert.AreEqual(book.Title, bookDTO.Title);
            Assert.AreEqual(book.Description, bookDTO.Description);
            Assert.AreEqual(book.AmountInStock, bookDTO.AmountInStock);
            Assert.AreEqual(book.UnitPrice, bookDTO.UnitPrice);
            Assert.AreEqual(book.ISBN, bookDTO.ISBN);
            Assert.AreEqual(book.Publisher, bookDTO.Publisher);
        }