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); }
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); }
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; }); }
public Order Update(Order order) { return _OrderRepository.Update(order); }