コード例 #1
0
        public void TestSaveCommand()
        {
            Part stock = TestHelper.GetTestPart();

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();

            EditStockViewModel viewModel = new EditStockViewModel(mockServiceFactory.Object, stock);

            mockServiceFactory.Setup(mock => mock.CreateClient<IPartService>().UpdatePart(It.IsAny<Part>())).Returns(viewModel.Stock);

            viewModel.Stock.Description = "Description";
            viewModel.Stock.Notes = "Black";
            
            bool stockUpdated = false;
            string color = string.Empty;
            viewModel.StockUpdated += (s, e) =>
            {
                stockUpdated = true;
                color = e.Stock.Notes;
            };

            viewModel.SaveCommand.Execute(null);

            Assert.IsTrue(stockUpdated);
            Assert.IsTrue(color == "Black");
        }
コード例 #2
0
        public void TestViewModelConstruction()
        {
            Part stock = TestHelper.GetTestPart();

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();

            EditStockViewModel viewModel = new EditStockViewModel(mockServiceFactory.Object, stock);

            Assert.IsTrue(viewModel.Stock != null);
            Assert.IsTrue(viewModel.Stock.Id == stock.Id && viewModel.Stock.Notes == stock.Notes);
        }
コード例 #3
0
        void OnEditStockCommand(Part stockItem)
        {
            if (stockItem.Id > 0)
            {
                CurrentStockViewModel = new EditStockViewModel(_serviceFactory, stockItem);
                CurrentStockViewModel.StockUpdated    += CurrentStockViewModel_StockUpdated;
                CurrentStockViewModel.CancelEditStock += CurrentStockViewModel_CancelEvent;
            }

            if (OpenEditStockWindow != null)
            {
                OpenEditStockWindow(this, CurrentStockViewModel);
            }
        }
コード例 #4
0
        public void TestCanSaveCommand()
        {
            Part stock = TestHelper.GetTestPart();

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();

            EditStockViewModel viewModel = new EditStockViewModel(mockServiceFactory.Object, stock);

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

            viewModel.Stock.Notes = "Black";

            Assert.IsTrue(viewModel.SaveCommand.CanExecute(null));
        }
コード例 #5
0
        public void TestStockIsValid()
        {
            Part stock = TestHelper.GetTestPart();

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();

            EditStockViewModel viewModel = new EditStockViewModel(mockServiceFactory.Object, stock);

            viewModel.Stock.Id = 0;
            viewModel.Stock.Description = "";
            Assert.IsFalse(viewModel.Stock.IsValid);

            viewModel.Stock.Id = 1;
            viewModel.Stock.Description = "Test";
            viewModel.Stock.ComponentsCost = 0;

            Assert.IsTrue(viewModel.Stock.IsValid);
        }
コード例 #6
0
 void OnOpenEditStockWindow(object sender, EditStockViewModel e)
 {
     var updateStockWindow = new UpdateStockWindow(e);
     updateStockWindow.Show();
 }
コード例 #7
0
 public UpdateStockWindow(EditStockViewModel editStockViewModel)
 {
     InitializeComponent();
     DataContext = editStockViewModel;
 }
コード例 #8
0
        void OnEditStockCommand(int partId)
        {
            if (partId > 0)
            {
                CurrentStockViewModel = new EditStockViewModel(_serviceFactory, partId);
                CurrentStockViewModel.StockUpdated += CurrentStockViewModel_StockUpdated;
                CurrentStockViewModel.CancelEditStock += CurrentStockViewModel_CancelEvent;
            }

            if (OpenEditStockWindow != null) OpenEditStockWindow(this, CurrentStockViewModel);
        }
コード例 #9
0
        public void TestCancelCommand()
        {
            Part stock = new Part { Id = 1, Notes = "White" };

            Mock<IServiceFactory> mockServiceFactory = new Mock<IServiceFactory>();

            EditStockViewModel viewModel = new EditStockViewModel(mockServiceFactory.Object, stock);

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

            Assert.IsTrue(!canceled);

            viewModel.CancelCommand.Execute(null);

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

            Assert.IsTrue(canceled);
        }