コード例 #1
0
        public void UpdateOrder_AddNew()
        {
            var newOrder = new Order();
            var addedOrder = new Order { Id = 1 };

            Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>();
            mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IOrderRepository>().Add(newOrder)).Returns(addedOrder);

            OrderManager manager = new OrderManager(mockDataRepositoryFactory.Object);
            var resultedOrder = manager.UpdateOrder(newOrder);

            Assert.AreEqual(addedOrder, resultedOrder);
        }
コード例 #2
0
        public void UpdateOrder_UpdateExisting()
        {
            var existingOrder = new Order { Id = 1, Notes = "1"};
            var updatedOrder = new Order { Id = 1, Notes = "2"};

            Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>();
            mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IOrderRepository>().Update(existingOrder)).Returns(updatedOrder);

            OrderManager manager = new OrderManager(mockDataRepositoryFactory.Object);
            var resultedOrder = manager.UpdateOrder(existingOrder);

            Assert.AreEqual(updatedOrder, resultedOrder);
        }
コード例 #3
0
        public Order UpdateOrder(Order order)
        {
            return ExecuteFaultHandledOperation(() =>
            {
                IOrderRepository orderRepository = _dataRepositoryFactory.GetDataRepository<IOrderRepository>();

                Order updatedEntity = null;

                if (order.Id == 0)
                    updatedEntity = orderRepository.Add(order);
                else
                    updatedEntity = orderRepository.Update(order);

                return updatedEntity;
            });
        }
コード例 #4
0
 public Order Update(Order order)
 {
     return _OrderRepository.Update(order);
 }