Exemple #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            MainWindow window = new MainWindow();

            // Create the ViewModel to which 
            // the main window binds.
            string path = "Data/customers.xml";
            var viewModel = new MainWindowViewModel(path);

            // When the ViewModel asks to be closed, 
            // close the window.
            EventHandler handler = null;
            handler = delegate
            {
                viewModel.RequestClose -= handler;
                window.Close();
            };
            viewModel.RequestClose += handler;

            // Allow all controls in the window to 
            // bind to the ViewModel by setting the 
            // DataContext, which propagates down 
            // the element tree.
            window.DataContext = viewModel;

            window.Show();
        }
		public void TestCreateNewCustomer( )
		{
			MainWindowViewModel target = new MainWindowViewModel( Constants.CUSTOMER_DATA_FILE );
			CommandViewModel commandVM = target.Commands.First( cvm => cvm.DisplayName == Strings.MainWindowViewModel_Command_CreateNewCustomer );
			commandVM.Command.Execute( null );

			var collectionView = CollectionViewSource.GetDefaultView( target.Workspaces );
			Assert.IsTrue( collectionView.CurrentItem is CustomerViewModel, "Invalid current item." );
		}
        public void TestCannotViewAllCustomersTwice()
        {
            MainWindowViewModel target = new MainWindowViewModel(Constants.CUSTOMER_DATA_FILE);
            CommandViewModel commandVM = target.Commands.First(cvm => cvm.DisplayName == Strings.MainWindowViewModel_Command_ViewAllCustomers);
            // Tell the ViewModel to show all customers twice.
            commandVM.Command.Execute(null);
            commandVM.Command.Execute(null);

            var collectionView = CollectionViewSource.GetDefaultView(target.Workspaces);
            Assert.IsTrue(collectionView.CurrentItem is AllCustomersViewModel, "Invalid current item.");
            Assert.IsTrue(target.Workspaces.Count == 1, "Invalid number of view models.");
        }
		public void TestCloseAllCustomersWorkspace( )
		{
			MainWindowViewModel target = new MainWindowViewModel( Constants.CUSTOMER_DATA_FILE );

			Assert.AreEqual( 0, target.Workspaces.Count, "Workspaces isn't empty." );

			CommandViewModel commandVM = target.Commands.First( cvm => cvm.DisplayName == Strings.MainWindowViewModel_Command_ViewAllCustomers );

			commandVM.Command.Execute( null );
			Assert.AreEqual( 1, target.Workspaces.Count, "Did not create viewmodel." );

			var allCustomersVM = target.Workspaces[ 0 ] as AllCustomersViewModel;
			Assert.IsNotNull( allCustomersVM, "Wrong viewmodel type created." );

			allCustomersVM.CloseCommand.Execute( null );
			Assert.AreEqual( 0, target.Workspaces.Count, "Did not close viewmodel." );
		}
Exemple #5
0
		protected override void OnStartup( StartupEventArgs e )
		{
			base.OnStartup( e );

			MainWindow window = new MainWindow( );

			string path = @"C:\Trabajos\Conferencias\RUN 09 - Arquitecturas de presentacion con WPF\Samples\MvvmDemoApp_Spanish\DemoApp\bin\Debug\customers.xml";
			var viewModel = new MainWindowViewModel( path );

			EventHandler handler = null;
			handler = delegate
			{
				viewModel.RequestClose -= handler;
				window.Close( );
			};
			viewModel.RequestClose += handler;

			window.DataContext = viewModel;

			window.Show( );

			if ( e.Args != null && e.Args.GetUpperBound( 0 ) == 0 )
			{
				if ( e.Args[ 0 ] == ViewAllCustomerArg )
				{
					viewModel.ShowAllCustomers( );
				}
				else
				{
					string[] customerData = Path.GetFileNameWithoutExtension( e.Args[ 0 ].Replace( "/doc", String.Empty ) ).Split( '_' );

					if ( customerData.GetUpperBound( 0 ) == 0 )
						viewModel.ShowCustomer( customerData[ 0 ], null );
					else
						viewModel.ShowCustomer( customerData[ 0 ], customerData[ 1 ] );
				}
			}
		}
        public void TestCloseAllCustomersWorkspace()
        {
            // Create the MainWindowViewModel, but not the MainWindow.
            MainWindowViewModel target =
                new MainWindowViewModel(Constants.CUSTOMER_DATA_FILE);

            Assert.AreEqual(0, target.Workspaces.Count, "Workspaces isn't empty.");

            // Find the command that opens the "All Customers" workspace.
            CommandViewModel commandVM =
                target.Commands.First(cvm => cvm.DisplayName == Strings.MainWindowViewModel_Command_ViewAllCustomers);

            // Open the "All Customers" workspace.
            commandVM.Command.Execute(null);
            Assert.AreEqual(1, target.Workspaces.Count, "Did not create viewmodel.");

            // Ensure the correct type of workspace was created.
            var allCustomersVM = target.Workspaces[0] as AllCustomersViewModel;
            Assert.IsNotNull(allCustomersVM, "Wrong viewmodel type created.");

            // Tell the "All Customers" workspace to close.
            allCustomersVM.CloseCommand.Execute(null);
            Assert.AreEqual(0, target.Workspaces.Count, "Did not close viewmodel.");
        }