예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
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();
        }