Exemple #1
0
        public void ShowNotesBrowser_LargeNumber()
        {
            using (var f = new TempFile("<notes version='0'/>"))
            {
                var r = AnnotationRepository.FromFile("id", f.Path, new NullProgress());
                for (int i = 0; i < 10000; i++)
                {
                    var annotation = new Annotation("question",
                                                    string.Format("nowhere://blah?id={0}&label={1}", Guid.NewGuid().ToString(), i.ToString()),
                                                    f.Path);
                    r.AddAnnotation(annotation);
                    annotation.AddMessage("test", "open", "blah blah");
                }

                ShowBrowser(new List <AnnotationRepository> {
                    r
                });
            }
        }
        public void Save_AfterCreatingFromFile_IsSaved()
        {
            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 ConsoleProgress()))
                {
                    var an = new Annotation("fooClass", "http://somewhere.org", "somepath");
                    r.AddAnnotation(an);
                    r.Save(new ConsoleProgress());
                }
                using (var x = AnnotationRepository.FromFile("id", t.Path, new ConsoleProgress()))
                {
                    Assert.AreEqual(2, x.GetAllAnnotations().Count());
                    Assert.AreEqual("<p>hello", x.GetAllAnnotations().First().Messages.First().GetSimpleHtmlText());
                    Assert.AreEqual("fooClass", x.GetAllAnnotations().ToArray()[1].ClassName);
                }
            }
        }
        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);
                }
            }
        }