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");
        }
Beispiel #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);
        }
Beispiel #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;
 }
 void OnOpenEditOrderWindow(object sender, EditOrderViewModel e)
 {
     EditOrderWindow editPartWindow = new EditOrderWindow(e);
     editPartWindow.Show();
 }
 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);
 }
 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);
 }