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

            var window = new MainWindow();

            var welcomeText = new ReadDocument((FlowDocument)Application.Current.Resources["WelcomeDocument"])
            {
                Name = "Welcome"
            };

            var docMan = new ReadDocumentManager(new List <ReadDocument>()
            {
                welcomeText
            });

            // Create the ViewModel to which the main window binds
            var viewModel = new MainWindowViewModel(docMan);

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

            // set the DataContext to the viewModel
            window.DataContext = viewModel;

            window.Show();
        }
        public void AddTest()
        {
            var docs = createDocList();
            ReadDocumentManager target = new ReadDocumentManager(docs);

            target.Add();
            var difference = target.Documents.Except(docs);

            Assert.IsTrue(difference.Count() == 1);
            target.Add();
            difference = target.Documents.Except(docs);
            Assert.IsTrue(difference.Count() == 2);
        }
        public void ReadDocumentManagerConstructorTest()
        {
            // Test the empty creator
            ReadDocumentManager target = new ReadDocumentManager();

            Assert.AreEqual(0, target.Documents.Count);

            var docs = createDocList();

            target = new ReadDocumentManager(docs);
            Assert.AreEqual(2, target.Documents.Count);

            CollectionAssert.AreEquivalent(docs, target.Documents);
        }
Exemple #4
0
        public MainWindowViewModel(ReadDocumentManager docsMan)
        {
            // Add commandbindings
            _reader = new DocumentReader();
            _reader.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_reader_PropertyChanged);

            _commandBindings = new CommandBindingCollection();

            CommandBinding NewCmdBinding = new CommandBinding(
                ApplicationCommands.New, (t, e) => _docsMan.Add());

            this.CommandBindings.Add(NewCmdBinding);

            CommandBinding PlayCmdBinding = new CommandBinding(
                MediaCommands.Play, PlayCmdExecuted, PlayCmdCanExecute);

            this.CommandBindings.Add(PlayCmdBinding);

            CommandBinding PauseCmdBinding = new CommandBinding(
                MediaCommands.Pause, PauseCmdExecuted, PauseCmdCanExecute);

            this.CommandBindings.Add(PauseCmdBinding);

            CommandBinding StopCmdBinding = new CommandBinding(
                MediaCommands.Stop, (t, e) => _reader.StopReading());

            this.CommandBindings.Add(StopCmdBinding);


            _docsMan = docsMan;
            _rdvms   = new ObservableCollection <ReadDocumentViewModel>();

            //The easiest way to republate the viewmodel is to call the delegate that manages the changes
            MainWindowViewModel_CollectionChanged(_docsMan.Documents, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

            // To keep our ViewModelCollection up to date we need to listen for changes
            ((INotifyCollectionChanged)(_docsMan.Documents)).CollectionChanged += new NotifyCollectionChangedEventHandler(MainWindowViewModel_CollectionChanged);

            // Select the first document if any.
            Document = Documents.FirstOrDefault();
        }
        public void RemoveTest()
        {
            ReadDocumentManager        target;     // The manager that is being tested
            List <ReadDocument>        docs;       // The documents in the start
            ReadDocument               doc1;       // The created documents
            ReadDocument               doc2;       // The created documents
            IEnumerable <ReadDocument> difference; // Creates the difference from the before to the current

            // Test adding one document
            docs       = createDocList();
            target     = new ReadDocumentManager(docs);
            doc1       = target.Add();
            difference = target.Documents.Except(docs);
            Assert.IsTrue(difference.Count() == 1);
            Assert.AreEqual(doc1, difference.First());
            target.Remove(doc1);
            CollectionAssert.AreEqual(docs, target.Documents);

            // Test adding two documents, remove the first, and the second
            docs       = createDocList();
            target     = new ReadDocumentManager(docs);
            doc1       = target.Add();
            difference = target.Documents.Except(docs);
            Assert.IsTrue(difference.Count() == 1);
            Assert.AreEqual(doc1, difference.First());
            doc2       = target.Add();
            difference = target.Documents.Except(docs);
            Assert.IsTrue(difference.Count() == 2);
            target.Remove(doc1);
            difference = target.Documents.Except(docs);
            Assert.IsTrue(difference.Count() == 1);
            Assert.AreEqual(doc2, difference.First());
            target.Remove(doc2);
            difference = target.Documents.Except(docs);
            Assert.IsTrue(difference.Count() == 0);
            CollectionAssert.AreEqual(docs, target.Documents);
        }