示例#1
0
        private void addDocToRDVMs(ReadDocument doc)
        {
            var docvm = new ReadDocumentViewModel(doc);

            _rdvms.Add(docvm);

            // When remove is requested remove the document from the manager, whih will inturn remove the docvm
            docvm.RequestClose = (s, e) => { _docsMan.Remove(doc); };

            //set the new document as selected
            Document = docvm;
        }
        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);
        }