예제 #1
0
 public void GetAll_EmptyDOM_OK()
 {
     using (var r = AnnotationRepository.FromString("id", "<notes version='0'/>"))
     {
         Assert.AreEqual(0, r.GetAllAnnotations().Count());
     }
 }
예제 #2
0
        public void GetByCurrentStatus_NoMessages_ReturnsNone()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
	<annotation guid='123'/></notes>"    ))
            {
                Assert.AreEqual(0, r.GetByCurrentStatus("open").Count());
            }
        }
예제 #3
0
        public void CreateOrphanAnnotation_DoesNotAddToRepository()
        {
            var repo  = AnnotationRepository.FromString("id", "<notes version='0'/>");
            var model = new NotesBarModel(repo);

            model.SetTargetObject("foo3");
            model.CreateAnnotation();
            Assert.AreEqual(0, repo.GetAllAnnotations().Count());
        }
예제 #4
0
 public void GetMatches_Has0Matches_ReturnsNone()
 {
     using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
     {
         var index = new IndexOfRefsOfQuestionAnnotations();
         r.AddObserver(index, _progress);
         Assert.AreEqual(0, index.GetMatches(key => key.Contains("b"), _progress).Count());
     }
 }
예제 #5
0
 public void GetAll_NoneInIndex_Returns0()
 {
     using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
     {
         var index = new IndexOfRefsOfQuestionAnnotations();
         r.AddObserver(index, _progress);
         Assert.AreEqual(0, index.GetAll().Count());
     }
 }
예제 #6
0
        public void Save_AfterCreatingFromString_GivesMessage()
        {
            using (new ErrorReport.NonFatalErrorReportExpected())
                using (var r = AnnotationRepository.FromString("id", @"<notes version='0'><annotation guid='123'>
<message guid='234'>&lt;p&gt;hello</message></annotation></notes>"))
                {
                    //  Assert.Throws<InvalidOperationException>(() =>
                    r.Save(new ConsoleProgress());
                }
        }
예제 #7
0
 public void AddIndex_AddSameIndexTwice_Throws()
 {
     using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
     {
         var index1 = new IndexOfAllOpenConflicts();
         r.AddObserver(index1, _progress);
         var index2 = new IndexOfAllOpenConflicts();
         Assert.Throws <ApplicationException>(() => r.AddObserver(index2, _progress));
     }
 }
예제 #8
0
        public void AddIndex_CallInitializeOnIndex()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'><annotation guid='123'>
<message guid='234'>&lt;p&gt;hello</message></annotation></notes>"))
            {
                var index = new TestAnnotationIndex();
                r.AddObserver(index, _progress);
                Assert.AreEqual(1, index.InitialItems);
            }
        }
예제 #9
0
 public void Remove_AnnotationAddedDynamically_RemovesIt()
 {
     using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
     {
         var a = new Annotation("question", "blah://blah/?id=foo", "");
         r.AddAnnotation(a);
         r.Remove(a);
         Assert.AreEqual(0, r.GetAllAnnotations().Count(), "should be none left");
     }
 }
예제 #10
0
        public void GetAll_Has2_ReturnsBoth()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
	<annotation guid='12D388BD-E83D-41AD-BAB3-B7E46D8C13CE'/>
	<annotation guid='12D39999-E83D-41AD-BAB3-B7E46D8C13CE'/>
</notes>"))
            {
                Assert.AreEqual(2, r.GetAllAnnotations().Count());
            }
        }
예제 #11
0
        public void CreateAnnotation_CreatesNewAnotationUsingIdOfCurrentAnnotatedObject()
        {
            var repo  = AnnotationRepository.FromString("id", "<notes version='0'/>");
            var model = new NotesBarModel(repo);

            model.SetTargetObject("foo3");
            model.AddAnnotation(model.CreateAnnotation());
            Assert.AreEqual(1, repo.GetAllAnnotations().Count());
            Assert.IsTrue(repo.GetAllAnnotations().First().RefStillEscaped.Contains("id=" + "foo3"));
        }
예제 #12
0
        public void GetMatches_PredicateGivesNullForOne_ReturnsIt()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='question'/>
</notes>"))
            {
                var index = new IndexOfRefsOfQuestionAnnotations();
                r.AddObserver(index, _progress);
                Assert.AreEqual(1, index.GetMatches(key => string.IsNullOrEmpty(key), _progress).Count());
            }
        }
예제 #13
0
        public void GetAll_0OutOf1MatchFilter_Returns0()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='note' ref='file://black'/>
</notes>"))
            {
                var index = new IndexOfRefsOfQuestionAnnotations();
                r.AddObserver(index, _progress);
                Assert.AreEqual(0, index.GetAll().Count());
            }
        }
        public void GetMatchesByKey_HasAnnotationWithoutRef_DoesntCrash()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'></notes>"))
            {
                r.AddAnnotation(new Annotation("question", "lift://blah.lift", "somepath"));

                var index = new SubClassForTest("id");
                r.AddObserver(index, _progress);
                Assert.AreEqual(0, index.GetMatchesByKey("222").Count());
            }
        }
예제 #15
0
        public void Remove_AnnotationFromFile_RepositoryNotifiesIndices()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'><annotation guid='123'>
<message guid='234'>&lt;p&gt;hello</message></annotation></notes>"))
            {
                var index = new TestAnnotationIndex();
                r.AddObserver(index, _progress);
                var annotation = r.GetAllAnnotations().First();
                r.Remove(annotation);
                Assert.AreEqual(1, index.Deletions);
            }
        }
예제 #16
0
        public void GetMatchesOfKey_Has0Matches_ReturnsNone()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='question' ref='file://red'/>
<annotation class='note' ref='file://black'/>
</notes>"))
            {
                var index = new IndexOfRefsOfQuestionAnnotations();
                r.AddObserver(index, _progress);
                Assert.AreEqual(0, index.GetMatchesByKey("blue").Count());
            }
        }
        public void Remove_FromXmlOnlyAnnotationsOfKey_RemovesIt()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='note' ref='blah://blah?id=blue'/>
</notes>"))
            {
                var blues = r.GetMatchesByPrimaryRefKey("blue");
                r.Remove(blues.First());
                blues = r.GetMatchesByPrimaryRefKey("blue");
                Assert.AreEqual(0, blues.Count(), "should be none left");
            }
        }
예제 #18
0
        public void GetByCurrentStatus_UsesTheLastMessage()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
	<annotation guid='123'><message status='open'/>
<message status='processing'/> <message status='closed'/>
</annotation>
</notes>"))
            {
                Assert.AreEqual(0, r.GetByCurrentStatus("open").Count());
                Assert.AreEqual(0, r.GetByCurrentStatus("processing").Count());
                Assert.AreEqual(1, r.GetByCurrentStatus("closed").Count());
            }
        }
 public void Remove_FromConstructorOnlyAnnotationsOfKey_RemovesIt()
 {
     using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
     {
         var a = new Annotation("note", "blah://blah?id=blue", "");
         r.AddAnnotation(a);
         var blues = r.GetMatchesByPrimaryRefKey("blue");
         Assert.AreEqual(a, blues.First());
         r.Remove(a);
         blues = r.GetMatchesByPrimaryRefKey("blue");
         Assert.AreEqual(0, blues.Count(), "should be none left");
     }
 }
        public void Remove_IndexAddedAfterRepoConstruction_RemovesIt()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='note' ref='blah://blah?id=blue'/>
</notes>"))
            {
                var index = new SubClassForTest("id");
                r.AddObserver(index, _progress);
                var blues = index.GetMatchesByKey("blue");
                r.Remove(blues.First());
                blues = index.GetMatchesByKey("blue");
                Assert.AreEqual(0, blues.Count(), "should be none left");
            }
        }
예제 #21
0
        public void AddAnnotation_NotifiesIndices()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
            {
                var index = new TestAnnotationIndex();
                r.AddObserver(index, _progress);

                r.AddAnnotation(new Annotation("question", "foo://blah.org?id=1", @"c:\pretendPath"));
                r.AddAnnotation(new Annotation("question", "foo://blah.org?id=1", @"c:\pretendPath"));

                Assert.AreEqual(2, index.Additions);
                Assert.AreEqual(0, index.Modification);
            }
        }
예제 #22
0
        public void GetMatches_Has2Matches_Returns2()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='question' ref='file://red'/>
<annotation class='question' ref='file://blue'/>
<annotation class='question' ref='file://blue'/>
<annotation class='note' ref='file://black'/>
</notes>"))
            {
                var index = new IndexOfRefsOfQuestionAnnotations();
                r.AddObserver(index, _progress);
                Assert.AreEqual(2, index.GetMatches(key => key.Contains("b"), _progress).Count());
            }
        }
예제 #23
0
        public void CreateAnnotation_HaveCustomUrlGenerator_UseIt()
        {
            var repo    = AnnotationRepository.FromString("id", "<notes version='0'/>");
            var mapping = new NotesToRecordMapping();

            mapping.FunctionToGoFromObjectToItsId      = (target) => "x" + target.ToString() + "x";
            mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, escapedId) => "foobar:" + escapedId;
            var model = new NotesBarModel(repo, mapping);

            model.SetTargetObject("foo3");
            model.AddAnnotation(model.CreateAnnotation());
            Assert.AreEqual(1, repo.GetAllAnnotations().Count());
            Assert.AreEqual("foobar:xfoo3x", repo.GetAllAnnotations().First().RefStillEscaped);
        }
        public void Remove_2AnnotationsWithSameTarget_OnlyRemoves1FromIndex()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'>
<annotation class='question' ref='blah://blah?id=blue'/>
<annotation class='note' ref='blah://blah?id=blue'/>
</notes>"))
            {
                var index = new SubClassForTest("id");
                r.AddObserver(index, _progress);
                var blues = index.GetMatchesByKey("blue");
                r.Remove(blues.First());
                blues = index.GetMatchesByKey("blue");
                Assert.AreEqual(1, blues.Count(), "should be one left");
            }
        }
예제 #25
0
        public void CreateAnnotation_KeyHasDangerousCharacters_ResultingUrlHasThemEscaped()
        {
            var repo    = AnnotationRepository.FromString("id", "<notes version='0'/>");
            var mapping = new NotesToRecordMapping();

            mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, escapedId) => string.Format("lift://object?type=entry&id={0}&type=test", escapedId);
            mapping.FunctionToGoFromObjectToItsId      = NotesToRecordMapping.DefaultIdGeneratorUsingObjectToStringAsId;

            //mapping.UrlGenerator = (target,key)=> string.Format("lift://object?type=entry&amp;id={0}&amp;type=test", key);
            var model = new NotesBarModel(repo, mapping);

            model.SetTargetObject("two'<three&four");
            model.AddAnnotation(model.CreateAnnotation());
            Assert.IsTrue(repo.GetAllAnnotations().First().RefUnEscaped.Contains("two'<three&four"));
        }
예제 #26
0
        public void GetMatches_AddedBeforeIndexInitialization_FoundViaPredicate()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'></notes>"))
            {
                var ann = new Annotation("conflict", "blah://blah?rid=12345", "somepath");
                ann.AddMessage("merger", "open", string.Empty);
                r.AddAnnotation(ann);

                var index = new IndexOfAllOpenConflicts();
                r.AddObserver(index, _progress);
                Assert.AreEqual(1, index.GetMatches(rf => rf.Contains("rid=12345"), _progress).Count());
                Assert.AreEqual(0, index.GetMatches(rf => rf.Contains("rid=333"), _progress).Count());
                ann.SetStatusToClosed("testman");
                Assert.AreEqual(0, index.GetMatches(rf => rf.Contains("rid=12345"), _progress).Count());
            }
        }
예제 #27
0
        public void Remove_AnnotationWasAddedDynamically_RepositoryNotifiesIndices()
        {
            using (var r = AnnotationRepository.FromString("id", @"<notes version='0'/>"))
            {
                var index = new TestAnnotationIndex();
                r.AddObserver(index, _progress);

                var annotation = new Annotation("question", "foo://blah.org?id=1", @"c:\pretendPath");
                r.AddAnnotation(annotation);

                Assert.AreEqual(0, index.Deletions);
                r.Remove(annotation);

                Assert.AreEqual(1, index.Deletions);
            }
        }
예제 #28
0
        public void GetAnnotationsToShow_ShowsAnnotationsFromFunctionToGoFromObjectToItsId()
        {
            var repo = AnnotationRepository.FromString("guid",
                                                       @"<notes version='0'>
<annotation guid='123' ref='lift://FTeam.lift?type=entry&amp;guid=abc'><message guid='234'>hello</message></annotation>
<annotation guid='345' ref='lift://FTeam.lift?type=entry&amp;guid=def'><message guid='234'>hello</message></annotation>
</notes>");
            var mapping = new NotesToRecordMapping();

            mapping.FunctionToGoFromObjectToItsId = (x) => "def";
            var model = new NotesBarModel(repo, mapping);

            model.SetTargetObject("xyz");
            var annotationsToShow = model.GetAnnotationsToShow().ToList();

            Assert.That(annotationsToShow, Has.Count.EqualTo(1));
            Assert.That(annotationsToShow[0].Guid, Is.EqualTo("345"));
        }
예제 #29
0
 public void FromString_FormatIsBadXml_Throws()
 {
     Assert.Throws <AnnotationFormatException>(() =>
                                               AnnotationRepository.FromString("id", "<notes version='99'>"));
 }