Beispiel #1
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 AddNewBookReturnAddedBook()
      {
         //Arrange 
         var customerRepository = new StubICustomerRepository();
         var orderRepository = new StubIOrderRepository();
         var productRepository = new StubIProductRepository();

         productRepository.UnitOfWorkGet = () =>
         {
            var uow = new StubIUnitOfWork();
            uow.Commit = () => { };

            return uow;
         };

         productRepository.AddProduct = (product) => { };

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

         var dto = new BookDto()
         {
            Title = "The title",
            Description = "description",
            Publisher = "license",
            Isbn = "isbn",
            AmountInStock = 10,
            UnitPrice = 10
         };

         //Act
         var result = salesManagement.AddNewBook(dto);

         //Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(result.Id != Guid.Empty);
         Assert.AreEqual(result.Title, dto.Title);
         Assert.AreEqual(result.Description, dto.Description);
         Assert.AreEqual(result.Publisher, dto.Publisher);
         Assert.AreEqual(result.Isbn, dto.Isbn);
         Assert.AreEqual(result.AmountInStock, dto.AmountInStock);
         Assert.AreEqual(result.UnitPrice, dto.UnitPrice);
      }
 /// <summary>
 ///    <see
 ///       cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService" />
 /// </summary>
 /// <param name="book">
 ///    <see
 ///       cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService" />
 /// </param>
 /// <returns>
 ///    <see
 ///       cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IMainBoundedContextService" />
 /// </returns>
 public BookDto AddNewBook(BookDto book)
 {
    return _salesAppService.AddNewBook(book);
 }
      public void AddNewBookThrowExceptionWhenDataIsInvalid()
      {
         //Arrange 

         var customerRepository = new StubICustomerRepository();
         var productRepository = new StubIProductRepository();
         var orderRepository = new StubIOrderRepository();

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

         var dto = new BookDto()
         {
            Title = "The title",
            Description = "description",
            Publisher = "license",
            Isbn = "isbn",
            AmountInStock = 10,
            UnitPrice = -1 //this is a not valid value
         };

         //Act
         var result = salesManagement.AddNewBook(dto);

      }