public void GetAll_EmptyDOM_OK() { using (var r = AnnotationRepository.FromString("id", "<notes version='0'/>")) { Assert.AreEqual(0, r.GetAllAnnotations().Count()); } }
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()); } }
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()); }
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()); } }
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()); } }
public void Save_AfterCreatingFromString_GivesMessage() { using (new ErrorReport.NonFatalErrorReportExpected()) using (var r = AnnotationRepository.FromString("id", @"<notes version='0'><annotation guid='123'> <message guid='234'><p>hello</message></annotation></notes>")) { // Assert.Throws<InvalidOperationException>(() => r.Save(new ConsoleProgress()); } }
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)); } }
public void AddIndex_CallInitializeOnIndex() { using (var r = AnnotationRepository.FromString("id", @"<notes version='0'><annotation guid='123'> <message guid='234'><p>hello</message></annotation></notes>")) { var index = new TestAnnotationIndex(); r.AddObserver(index, _progress); Assert.AreEqual(1, index.InitialItems); } }
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"); } }
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()); } }
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")); }
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()); } }
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()); } }
public void Remove_AnnotationFromFile_RepositoryNotifiesIndices() { using (var r = AnnotationRepository.FromString("id", @"<notes version='0'><annotation guid='123'> <message guid='234'><p>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); } }
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"); } }
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"); } }
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); } }
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()); } }
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"); } }
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&id={0}&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")); }
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()); } }
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); } }
public void GetAnnotationsToShow_ShowsAnnotationsFromFunctionToGoFromObjectToItsId() { var repo = AnnotationRepository.FromString("guid", @"<notes version='0'> <annotation guid='123' ref='lift://FTeam.lift?type=entry&guid=abc'><message guid='234'>hello</message></annotation> <annotation guid='345' ref='lift://FTeam.lift?type=entry&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")); }
public void FromString_FormatIsBadXml_Throws() { Assert.Throws <AnnotationFormatException>(() => AnnotationRepository.FromString("id", "<notes version='99'>")); }