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"); }
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); }
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); } }
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)); }
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); }
void OnOpenEditStockWindow(object sender, EditStockViewModel e) { var updateStockWindow = new UpdateStockWindow(e); updateStockWindow.Show(); }
public UpdateStockWindow(EditStockViewModel editStockViewModel) { InitializeComponent(); DataContext = editStockViewModel; }
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); }
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); }