Example #1
0
        public void ExtenstionTests()
        {
            IDocumentManagerService service   = new TestDocumentManagerService();
            TestDocument            document1 = (TestDocument)service.CreateDocument("Type", null);

            Assert.AreEqual("Type", document1.DocumentType);
            Assert.AreEqual(null, document1.Parameter);
            Assert.AreEqual(null, document1.ParentViewModel);

            TestDocument document2 = (TestDocument)service.CreateDocument("Type", "Model");

            Assert.AreEqual("Type", document2.DocumentType);
            Assert.AreEqual("Model", document2.ViewModel);
            Assert.AreEqual(null, document2.Parameter);
            Assert.AreEqual(null, document2.ParentViewModel);


            IDocument document3 = (TestDocument)service.CreateDocument("Type", "Param", "Model");

            Assert.AreEqual("Type", ((TestDocument)document3).DocumentType);
            Assert.AreEqual(null, ((TestDocument)document3).ViewModel);
            Assert.AreEqual("Param", ((TestDocument)document3).Parameter);
            Assert.AreEqual("Model", ((TestDocument)document3).ParentViewModel);


            var byViewModel = service.GetDocumentsByParentViewModel("Model");

            Assert.AreEqual(1, byViewModel.Count());
            Assert.AreEqual(document3, byViewModel.First());

            Assert.AreEqual(document3, service.FindDocument("Param", "Model"));

            IDocument oldDocument = document3;

            service.CreateDocumentIfNotExistsAndShow(ref document3, "Type", "X", "Y", "title");
            Assert.AreSame(oldDocument, document3);

            IDocument newDocument = null;

            service.CreateDocumentIfNotExistsAndShow(ref newDocument, "Type", "X", "Y", "title");
            Assert.AreEqual("Type", ((TestDocument)newDocument).DocumentType);
            Assert.AreEqual("X", ((TestDocument)newDocument).Parameter);
            Assert.AreEqual("Y", ((TestDocument)newDocument).ParentViewModel);

            Assert.IsNull(service.FindDocument("content"));
            document1.Content = "content";
            Assert.AreEqual(document1, service.FindDocument("content"));

            var viewModel           = new TestViewModel();
            var documentByViewModel = service.CreateDocument(viewModel);

            Assert.AreEqual(null, ((TestDocument)documentByViewModel).DocumentType);
            Assert.AreEqual(null, ((TestDocument)documentByViewModel).Parameter);
            Assert.AreEqual(viewModel, ((TestDocument)documentByViewModel).ViewModel);
            Assert.AreEqual(null, ((TestDocument)documentByViewModel).ParentViewModel);
        }
Example #2
0
        public void SetTitleBindingTest()
        {
            var viewModel = ViewModelSource.Create(() => new TestDocumentContent());

            viewModel.Title = "a";
            IDocumentManagerService service = new TestDocumentManagerService();
            IDocument document = service.CreateDocument("doc", viewModel);

            Assert.AreEqual("a", document.Title);
            viewModel.Title = "b";
            Assert.AreEqual("b", document.Title);
        }
Example #3
0
        public void ExtenstionTests_FindById()
        {
            IDocumentManagerService service   = new TestDocumentManagerService();
            TestDocument            document1 = (TestDocument)service.CreateDocument("Type", null);

            document1.Id = "doc1";
            Assert.IsNull(service.FindDocumentById("none"));
            Assert.AreEqual(document1, service.FindDocumentById("DOC1".ToLower()));

            Assert.AreEqual(document1, service.FindDocumentByIdOrCreate("doc1", x => { throw new NotImplementedException(); }));
            IDocument document2 = service.FindDocumentByIdOrCreate("doc2", x => {
                var doc   = x.CreateDocument(null);
                doc.Title = "title";
                return(doc);
            });

            Assert.AreEqual("title", document2.Title);
            Assert.AreEqual("doc2", document2.Id);
            Assert.AreEqual(document2, service.FindDocumentById("doc2"));
        }
        public void ExtenstionTests_FindById() {
            IDocumentManagerService service = new TestDocumentManagerService();
            TestDocument document1 = (TestDocument)service.CreateDocument("Type", null);
            document1.Id = "doc1";
            Assert.IsNull(service.FindDocumentById("none"));
            Assert.AreEqual(document1, service.FindDocumentById("DOC1".ToLower()));

            Assert.AreEqual(document1, service.FindDocumentByIdOrCreate("doc1", x => { throw new NotImplementedException(); }));
            IDocument document2 = service.FindDocumentByIdOrCreate("doc2", x => {
                var doc = x.CreateDocument(null);
                doc.Title = "title";
                return doc;
            });
            Assert.AreEqual("title", document2.Title);
            Assert.AreEqual("doc2", document2.Id);
            Assert.AreEqual(document2, service.FindDocumentById("doc2"));
        }
 public void SetTitleBindingTest() {
     var viewModel = ViewModelSource.Create(() => new TestDocumentContent());
     viewModel.Title = "a";
     IDocumentManagerService service = new TestDocumentManagerService();
     IDocument document = service.CreateDocument("doc", viewModel);
     Assert.AreEqual("a", document.Title);
     viewModel.Title = "b";
     Assert.AreEqual("b", document.Title);
 }
        public void ExtenstionTests() {
            IDocumentManagerService service = new TestDocumentManagerService();
            TestDocument document1 = (TestDocument)service.CreateDocument("Type", null);
            Assert.AreEqual("Type", document1.DocumentType);
            Assert.AreEqual(null, document1.Parameter);
            Assert.AreEqual(null, document1.ParentViewModel);

            TestDocument document2 = (TestDocument)service.CreateDocument("Type", "Model");
            Assert.AreEqual("Type", document2.DocumentType);
            Assert.AreEqual("Model", document2.ViewModel);
            Assert.AreEqual(null, document2.Parameter);
            Assert.AreEqual(null, document2.ParentViewModel);


            IDocument document3 = (TestDocument)service.CreateDocument("Type", "Param", "Model");
            Assert.AreEqual("Type", ((TestDocument)document3).DocumentType);
            Assert.AreEqual(null, ((TestDocument)document3).ViewModel);
            Assert.AreEqual("Param", ((TestDocument)document3).Parameter);
            Assert.AreEqual("Model", ((TestDocument)document3).ParentViewModel);


            var byViewModel = service.GetDocumentsByParentViewModel("Model");
            Assert.AreEqual(1, byViewModel.Count());
            Assert.AreEqual(document3, byViewModel.First());

            Assert.AreEqual(document3, service.FindDocument("Param", "Model"));

            IDocument oldDocument = document3;
            service.CreateDocumentIfNotExistsAndShow(ref document3, "Type", "X", "Y", "title");
            Assert.AreSame(oldDocument, document3);

            IDocument newDocument = null;
            service.CreateDocumentIfNotExistsAndShow(ref newDocument, "Type", "X", "Y", "title");
            Assert.AreEqual("Type", ((TestDocument)newDocument).DocumentType);
            Assert.AreEqual("X", ((TestDocument)newDocument).Parameter);
            Assert.AreEqual("Y", ((TestDocument)newDocument).ParentViewModel);

            Assert.IsNull(service.FindDocument("content"));
            document1.Content = "content";
            Assert.AreEqual(document1, service.FindDocument("content"));

            var viewModel = new TestViewModel();
            var documentByViewModel = service.CreateDocument(viewModel);
            Assert.AreEqual(null, ((TestDocument)documentByViewModel).DocumentType);
            Assert.AreEqual(null, ((TestDocument)documentByViewModel).Parameter);
            Assert.AreEqual(viewModel, ((TestDocument)documentByViewModel).ViewModel);
            Assert.AreEqual(null, ((TestDocument)documentByViewModel).ParentViewModel);
        }