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);
            }
        }
 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);
     }
 }
        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);
            }
        }
 public void CloseAnnotation_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();
         annotation.SetStatus("joe", "closed");
         Assert.AreEqual(1, index.Modification);
     }
 }
        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 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 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 ExternalFileModification_NotifiesIndices_ButSaveDoesNot()
        {
            using (var t = new TempFile(@"<notes version='0'><annotation guid='123'>
<message guid='234'>&lt;p&gt;hello</message></annotation></notes>"))
            {
                using (var r = AnnotationRepository.FromFile("id", t.Path, new NullProgress()))
                {
                    var index = new TestAnnotationIndex();
                    r.AddObserver(index, _progress);

                    File.WriteAllText(t.Path, @"<notes version='0'><annotation guid='123'>
<message guid='234'>&lt;p&gt;goodbye</message></annotation></notes>");

                    int tries = 0;
                    while (index.StaleNotifications == 0 && tries++ < 3)
                    {
                        Thread.Sleep(10);
                    }
                    Assert.AreEqual(1, index.StaleNotifications);

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

                    r.Save(new NullProgress());

                    tries = 0;
                    while (index.StaleNotifications == 1 && tries++ < 3)
                    {
                        Thread.Sleep(10);
                    }
                    // It's still 1, after waiting long enough to be fairly sure we would have
                    // seen the notification.
                    Assert.AreEqual(1, index.StaleNotifications);
                }
            }
        }
        public void CloseAnnotation_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.Modification);
                annotation.SetStatus("joe", "closed");

                Assert.AreEqual(1, index.Modification);
            }
        }