예제 #1
0
        public void Should_Return_BadRequest_When_Create_And_Exception_Is_Thrown()
        {
            var fakeRepository = _fakes.FakeOrderItemRepository(true).Object;

            var request  = _fakes.Get <CreateOrderItemRequest>().First();
            var expected = Responses.BadRequestResponse(Fakes.TestException.Message);

            var service = new OrderItemService(_fakes.Mapper, fakeRepository);
            var actual  = service.Create(request).Result;

            Assert.ThrowsAnyAsync <Exception>(() => service.Create(request));
            Assert.IsType <Response>(actual);
            Assert.Equal(expected, actual, new ResponseComparer());
        }
 public async Task Create(OrderItemDto orderItem)
 {
     using (UnitOfWorkProvider.Create())
     {
         _OrderItemService.Create(orderItem);
         await UnitOfWorkProvider.GetUnitOfWorkInstance().Commit();
     }
 }
예제 #3
0
 public ActionResult Create(OrderCreateViewModel viewmodel)
 {
     if (ModelState.IsValid)
     {
         var transaction = NHibernateSession.Current.BeginTransaction();
         try
         {
             if (viewmodel.IsIndividual)
             {
                 var order = _orderService.Create(Guid.NewGuid(), viewmodel.SupplierId, viewmodel.Instructions, viewmodel.CurrencyId);
                 _orderItemService.Create(
                     Guid.NewGuid(), order.Id, viewmodel.Description,
                     viewmodel.Quantity, viewmodel.PartNo, viewmodel.Instructions,
                     viewmodel.DeliveryDays, viewmodel.JobItemId, viewmodel.Price, viewmodel.Carriage);
             }
             else
             {
                 _orderItemService.CreatePending(
                     Guid.NewGuid(), viewmodel.SupplierId, viewmodel.Description,
                     viewmodel.Quantity, viewmodel.PartNo, viewmodel.Instructions,
                     viewmodel.DeliveryDays, viewmodel.JobItemId, viewmodel.Price, viewmodel.Carriage);
             }
             transaction.Commit();
             return(RedirectToAction("Details", "Job", new { id = viewmodel.JobId, tabNo = "0" }));
         }
         catch (DomainValidationException dex)
         {
             transaction.Rollback();
             ModelState.UpdateFromDomain(dex.Result);
         }
         finally
         {
             transaction.Dispose();
         }
     }
     return(View("Create", viewmodel));
 }
예제 #4
0
        public void Should_Return_Item_When_Create()
        {
            var fakeRepository = _fakes.FakeOrderItemRepository().Object;

            var request = _fakes.Get <CreateOrderItemRequest>().First();
            var item    = _fakes.Get <OrderItem>().First();

            var response = _fakes.Mapper.Map <OrderItemResponse>(item);

            response.Id = Fakes.NewEntityId; // Mocked id when creating a new item
            var expected = Responses.OkResponse(null, response);

            var service = new OrderItemService(_fakes.Mapper, fakeRepository);
            var actual  = service.Create(request).Result;

            Assert.IsType <Response>(actual);
            Assert.Equal(expected, actual, new OrderItemResponseComparer());
        }