Exemplo n.º 1
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();

      }
Exemplo n.º 2
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>();
        }
        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);
        }