public void TestSaveCommand()
        {
            Order order = TestHelper.GetTestOrder();

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();
            mockServiceFactory.Setup(mock => mock.CreateClient<IOrderService>().GetOrder(1)).Returns(order);

            EditOrderViewModel viewModel = new EditOrderViewModel(mockServiceFactory.Object, order.Id);

            mockServiceFactory.Setup(mock => mock.CreateClient<IOrderService>().UpdateOrder(It.IsAny<Order>())).Returns(viewModel.Order);

            viewModel.Order.InvoiceNumber = "Black";

            bool orderUpdated = false;
            string color = string.Empty;
            viewModel.OrderUpdated += (s, e) =>
            {
                orderUpdated = true;
                color = e.Order.InvoiceNumber;
            };

            viewModel.SaveCommand.Execute(null);

            Assert.IsTrue(orderUpdated);
            Assert.IsTrue(color == "Black");
        }
예제 #2
0
        void OnAddOrderCommand(object arg)
        {
            int zeroAsNewOrderId = 0;

            CurrentOrderViewModel = new EditOrderViewModel(_serviceFactory, zeroAsNewOrderId);
            CurrentOrderViewModel.OrderUpdated    += CurrentOrderViewModel_OrderUpdated;
            CurrentOrderViewModel.CancelEditOrder += CurrentOrderViewModel_CancelEvent;
            if (OpenEditOrderWindow != null)
            {
                OpenEditOrderWindow(this, CurrentOrderViewModel);
            }
        }
        public void TestViewModelConstruction()
        {
            Order order = TestHelper.GetTestOrder();
            order.Id = 1;

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();
            mockServiceFactory.Setup(mock => mock.CreateClient<IOrderService>().GetOrder(1)).Returns(order);

            EditOrderViewModel viewModel = new EditOrderViewModel(mockServiceFactory.Object, order.Id);

            Assert.IsTrue(viewModel.Order != null);
            Assert.IsTrue(viewModel.Order.Id == order.Id && viewModel.Order.InvoiceNumber == order.InvoiceNumber);
        }
예제 #4
0
 void OnEditOrderCommand(Order order)
 {
     if (order != null)
     {
         CurrentOrderViewModel = new EditOrderViewModel(_serviceFactory, order.Id);
         CurrentOrderViewModel.OrderUpdated    += CurrentOrderViewModel_OrderUpdated;
         CurrentOrderViewModel.CancelEditOrder += CurrentOrderViewModel_CancelEvent;
     }
     if (OpenEditOrderWindow != null)
     {
         OpenEditOrderWindow(this, CurrentOrderViewModel);
     }
 }
        public void TestCanSaveCommand()
        {
            Order order = TestHelper.GetTestOrder();

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();
            mockServiceFactory.Setup(mock => mock.CreateClient<IOrderService>().GetOrder(1)).Returns(order);

            EditOrderViewModel viewModel = new EditOrderViewModel(mockServiceFactory.Object, order.Id);

            Assert.IsFalse(viewModel.SaveCommand.CanExecute(null));

            viewModel.Order.InvoiceNumber = "Black";

            Assert.IsTrue(viewModel.SaveCommand.CanExecute(null));
        }
        public void TestCancelCommand()
        {
            Order order = new Order() { Id = 1, InvoiceNumber = "White" };

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();
            mockServiceFactory.Setup(mock => mock.CreateClient<IOrderService>().GetOrder(1)).Returns(order);

            EditOrderViewModel viewModel = new EditOrderViewModel(mockServiceFactory.Object, order.Id);

            bool canceled = false;
            viewModel.CancelEditOrder += (s, e) => canceled = true;

            Assert.IsTrue(!canceled);

            viewModel.CancelCommand.Execute(null);

            Assert.IsTrue(viewModel.CancelCommand.CanExecute(null));

            Assert.IsTrue(canceled);
        }
 public EditOrderWindow(EditOrderViewModel editOrderViewModel)
 {
     InitializeComponent();
     DataContext = editOrderViewModel;
 }
예제 #8
0
 void OnOpenEditOrderWindow(object sender, EditOrderViewModel e)
 {
     EditOrderWindow editPartWindow = new EditOrderWindow(e);
     editPartWindow.Show();
 }
예제 #9
0
 void OnAddOrderCommand(object arg)
 {
     int zeroAsNewOrderId = 0;
     CurrentOrderViewModel = new EditOrderViewModel(_serviceFactory, zeroAsNewOrderId);
     CurrentOrderViewModel.OrderUpdated += CurrentOrderViewModel_OrderUpdated;
     CurrentOrderViewModel.CancelEditOrder += CurrentOrderViewModel_CancelEvent;
     if (OpenEditOrderWindow != null) OpenEditOrderWindow(this, CurrentOrderViewModel);
 }
예제 #10
0
 void OnEditOrderCommand(Order order)
 {
     if (order != null)
     {
         CurrentOrderViewModel = new EditOrderViewModel(_serviceFactory, order.Id);
         CurrentOrderViewModel.OrderUpdated += CurrentOrderViewModel_OrderUpdated;
         CurrentOrderViewModel.CancelEditOrder += CurrentOrderViewModel_CancelEvent;
     }
     if (OpenEditOrderWindow != null) OpenEditOrderWindow(this, CurrentOrderViewModel);
 }