public void TestSaveCommand()
        {
            Supplier supplier = TestHelper.GetTestSupplier();

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

            EditSupplierViewModel viewModel = new EditSupplierViewModel(mockServiceFactory.Object, supplier);

            mockServiceFactory.Setup(mock => mock.CreateClient<ISupplierService>().UpdateSupplier(It.IsAny<Supplier>())).Returns(viewModel.Supplier);

            viewModel.Supplier.Name = "Black";

            bool supplierUpdated = false;
            string color = string.Empty;
            viewModel.SupplierUpdated += (s, e) =>
            {
                supplierUpdated = true;
                color = e.Supplier.Name;
            };

            viewModel.SaveCommand.Execute(null);

            Assert.IsTrue(supplierUpdated);
            Assert.IsTrue(color == "Black");
        }
Exemplo n.º 2
0
        void OnAddSupplierCommand(object arg)
        {
            Supplier supplier = new Supplier();

            CurrentSupplierViewModel = new EditSupplierViewModel(_serviceFactory, supplier);
            CurrentSupplierViewModel.SupplierUpdated    += CurrentSupplierViewModel_SupplierUpdated;
            CurrentSupplierViewModel.CancelEditSupplier += CurrentSupplierViewModel_CancelEvent;
        }
Exemplo n.º 3
0
 void OnEditSupplierCommand(Supplier supplier)
 {
     if (supplier != null)
     {
         CurrentSupplierViewModel = new EditSupplierViewModel(_serviceFactory, supplier);
         CurrentSupplierViewModel.SupplierUpdated    += CurrentSupplierViewModel_SupplierUpdated;
         CurrentSupplierViewModel.CancelEditSupplier += CurrentSupplierViewModel_CancelEvent;
     }
 }
        public void TestViewModelConstruction()
        {
            Supplier supplier = TestHelper.GetTestSupplier();

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

            EditSupplierViewModel viewModel = new EditSupplierViewModel(mockServiceFactory.Object, supplier);

            Assert.IsTrue(viewModel.Supplier != null && viewModel.Supplier != supplier);
            Assert.IsTrue(viewModel.Supplier.Id == supplier.Id && viewModel.Supplier.Name == supplier.Name);
        }
        public void TestSupplierIsValid()
        {
            Supplier supplier = TestHelper.GetTestSupplier();

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

            EditSupplierViewModel viewModel = new EditSupplierViewModel(mockServiceFactory.Object, supplier);

            viewModel.Supplier.Name = "";
            Assert.IsFalse(viewModel.Supplier.IsValid);

            viewModel.Supplier.Name = "Valid Name";
            Assert.IsTrue(viewModel.Supplier.IsValid);
        }
        public void TestCanSaveCommand()
        {
            Supplier supplier = TestHelper.GetTestSupplier();

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

            EditSupplierViewModel viewModel = new EditSupplierViewModel(mockServiceFactory.Object, supplier);

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

            viewModel.Supplier.Name = "Black";

            Assert.IsTrue(viewModel.SaveCommand.CanExecute(null));
        }
 void OnAddSupplierCommand(object arg)
 {
     Supplier supplier = new Supplier();
     CurrentSupplierViewModel = new EditSupplierViewModel(_serviceFactory, supplier);
     CurrentSupplierViewModel.SupplierUpdated += CurrentSupplierViewModel_SupplierUpdated;
     CurrentSupplierViewModel.CancelEditSupplier += CurrentSupplierViewModel_CancelEvent;
 }
 void OnEditSupplierCommand(Supplier supplier)
 {
     if (supplier != null)
     {
         CurrentSupplierViewModel = new EditSupplierViewModel(_serviceFactory, supplier);
         CurrentSupplierViewModel.SupplierUpdated += CurrentSupplierViewModel_SupplierUpdated;
         CurrentSupplierViewModel.CancelEditSupplier += CurrentSupplierViewModel_CancelEvent;
     }
 }
        public void TestCancelCommand()
        {
            Supplier supplier = new Supplier() { Id = 1, Name = "White" };

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

            EditSupplierViewModel viewModel = new EditSupplierViewModel(mockServiceFactory.Object, supplier);

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

            Assert.IsTrue(!canceled);

            viewModel.CancelCommand.Execute(null);

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

            Assert.IsTrue(canceled);
        }