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

            var book = new Book()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                ISBN = "ABC",
                Publisher = "Krasiss Press",
                Title = "The book title",
                UnitPrice = 40,
                Description = "Any book description",
                AmountInStock = 1
            };

            //Act

            productRepository.Add(book);
            productRepository.UnitOfWork.Commit();

            //Assert

            var result = productRepository.Get(book.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == book.Id);
        }
        public void BookToBookDTOAdapter()
        {
            //Arrange
            var book = new Book()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                Title = "the title",
                UnitPrice = 10,
                Description = "The description",
                AmountInStock = 10,
                ISBN ="ABD12",
                Publisher= "Krasis Press"
            };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            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);
        }
예제 #3
0
      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();

      }
예제 #4
0
 public void CannotCreateAProductWithWhitespacePublisher()
 {
    //Arrange and Act
    var product = new Book("the title", "description", " ", "isbn");
 }
예제 #5
0
 public void CannotCreateAProductWithWhitespaceTitle()
 {
    //Arrange and Act
    var product = new Book(" ", "the description", "publisher", "isbn");
 }
예제 #6
0
 public void CannotCreateAProductWithEmptyIsbn()
 {
    //Arrange and Act
    var product = new Book("the title", "description", "publisher", string.Empty);
 }
예제 #7
0
 public void CannotCreateAProductWithEmptyTitle()
 {
    //Arrange and Act
    var product = new Book(string.Empty, "the description", "publisher", "isbn");
 }
예제 #8
0
 public void CannotCreateAProductWithNullIsbn()
 {
    //Arrange and Act
    var product = new Book("the title", "description", "publisher", null);
 }
예제 #9
0
 public void CannotCreateAProductWithNullTitle()
 {
    //Arrange and Act
    var product = new Book(null, "the description", "publisher", "isbn");
 }
예제 #10
0
        /// <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>();
        }
예제 #11
0
      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);
      }
예제 #12
0
      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);
        }