Example #1
0
		public void TypicalEmbedInMyXmlDocument()
		{
			var system = new OlacSystem();
			var work = new Work();
			work.Licenses.Add(License.CreativeCommons_Attribution_ShareAlike);
			work.Contributions.Add(new Contribution("Charlie Brown", system.GetRoleByCodeOrThrow("author")));
			work.Contributions.Add(new Contribution("Linus", system.GetRoleByCodeOrThrow("editor")));

			string metaData = system.GetXmlForWork(work);

			//Embed that data in our own file
			using (var f = new TempFile(@"<doc>
				<metadata>" + metaData + @"</metadata>
				<ourDocumentContents>blah blah<ourDocumentContents/></doc>"))
			{
				//Then when it comes time to read the file, we can extract out the work again
				var dom = new XmlDocument();
				dom.Load(f.Path);

				var node = dom.SelectSingleNode("//metadata");
				var work2 = new Work();
				system.LoadWorkFromXml(work2, node.InnerXml);

				Assert.AreEqual(2,work2.Contributions.Count());
			}
		}
Example #2
0
		public void Setup()
		{
			_mediaFile = new Bitmap(10, 10);
			_tempFile = TempFile.WithExtension("png");
			_mediaFile.Save(_tempFile.Path);
		   _outgoing = Metadata.FromFile(_tempFile.Path);
		 }
Example #3
0
 public void ValidateFile_IllFormedXml_ReturnsProblem()
 {
     var handler = new LiftFileHandler();
     using (var file = new TempFile("<lift>"))
     {
         var result = handler.ValidateFile(file.Path, new ConsoleProgress());
         Assert.IsNotNull(result);
     }
 }
Example #4
0
 public void ValidateFile_SimpleLift_ReturnsNull()
 {
     var handler = new LiftFileHandler();
     using(var file = new TempFile("<lift/>"))
     {
         var result = handler.ValidateFile(file.Path, new ConsoleProgress());
         Assert.IsNull(result);
     }
 }
Example #5
0
        public IEnumerable<IChangeReport> DescribeInitialContents(FileInRevision fileInRevision, TempFile file)
        {
            var dom = new XmlDocument();
            dom.Load(file.Path);

            foreach (XmlNode e in dom.SafeSelectNodes("notes/annotation"))
            {
                yield return new XmlAdditionChangeReport(fileInRevision, e);
            }
        }
        public void LiftSynchronizerReadsLift15VersionCorrectly()
        {
            // Setup
            using (var myfile = new TempFile(testLift15File))
            {
                // SUT
                var syncAdjunct = new LiftSynchronizerAdjunct(myfile.Path);

                // Verification
                Assert.AreEqual("LIFT0.15", syncAdjunct.BranchName, "BranchName should be 'LIFT0.15'");
            }
        }
        public void DeletionReport_Not_ProducedForDeletedAnnotationUsingNotesHandler()
        {
            const string parent = @"<?xml version='1.0' encoding='utf-8'?>
                    <notes version='0'>
                        <annotation guid='old1'/>
                        <annotation guid='soonToBeGoner'/>
                    </notes>";
            const string child = @"<?xml version='1.0' encoding='utf-8'?>
                    <notes version='0'>
                        <annotation guid='old1'/>
                    </notes>";

            // Make sure the common differ code does produce the deletion report.
            using (var parentTempFile = new TempFile(parent))
            using (var childTempFile = new TempFile(child))
            {
                var listener = new ListenerForUnitTests();
                var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path,
                    listener,
                    null,
                    "annotation",
                    "guid");
                differ.ReportDifferencesToListener();
                listener.AssertExpectedChangesCount(1);
                listener.AssertFirstChangeType<XmlDeletionChangeReport>();
            }
            // Now make sure the ChorusNotesFileHandler filters it out, and does not return it,
            // as per the original notes differ code.
            var notesHandler = (from handler in ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers().Handlers
                                where handler.GetType().Name == "ChorusNotesFileHandler"
                                select handler).First();
            using (var repositorySetup = new RepositorySetup("randy"))
            {
                repositorySetup.AddAndCheckinFile("notestest.ChorusNotes", parent);
                repositorySetup.ChangeFileAndCommit("notestest.ChorusNotes", child, "change it");
                var hgRepository = repositorySetup.Repository;
                var allRevisions = (from rev in hgRepository.GetAllRevisions()
                                    orderby rev.Number.LocalRevisionNumber
                                    select rev).ToList();
                var first = allRevisions[0];
                var second = allRevisions[1];
                var firstFiR = hgRepository.GetFilesInRevision(first).First();
                var secondFiR = hgRepository.GetFilesInRevision(second).First();
                var result = notesHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository);
                Assert.AreEqual(0, result.Count());
            }
        }
Example #8
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});
            }
        }
Example #9
0
 public void GuidAttrBeforeIdAttrDoesNotGenerateReports()
 {
     const string parent = @"<?xml version='1.0' encoding='utf-8'?>
             <root>
                 <item id='fuzz-old1' guid='old1'/>
             </root>";
     const string child = @"<?xml version='1.0' encoding='utf-8'?>
             <root>
                 <item guid='old1' id='fuzz-old1'/>
             </root>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             null, "item", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(0);
         listener.AssertExpectedConflictCount(0);
     }
 }
Example #10
0
 public void Deletion_WasTombstoneNowMissing_NoDeletionReport()
 {
     const string parent = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <item id='old1' dateDeleted='2009-06-16T06:14:20Z'/>
                 <item id='old2'/>
             </lift>";
     const string child = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <item id='old2'/>
             </lift>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             null, "item", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(0);
         listener.AssertExpectedConflictCount(0);
     }
 }
 public void DeletionReport_Not_ProducedForDeletionInParentAndChild()
 {
     var parent = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry id='old1' dateDeleted='2009-06-16T06:14:20Z'/>
                 <entry id='old2'/>
             </lift>";
     var child = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry	id='old1'	dateDeleted='2009-06-16T06:14:20Z'/>
                 <entry id='old2'/>
             </lift>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             "header",
                                                      "entry", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(0);
     }
 }
Example #12
0
 public IEnumerable<IChangeReport> DescribeInitialContents(FileInRevision fileInRevision, TempFile file)
 {
     return new IChangeReport[] { new DefaultChangeReport(fileInRevision, "Added") };
 }
Example #13
0
        public void Setup()
        {
            _tempFolder = new TemporaryFolder("ChorusSystemUsage");
            _dataFolderRoot = _tempFolder.Path;
            _someDataFile = new TempFileFromFolder(_tempFolder, "test.txt", "hello");
            _someDataFilePath = _someDataFile.Path;

            _chorusSystem = new ChorusSystem(_dataFolderRoot);
            _chorusSystem.Init("john");
        }
 /// <summary>
 /// This is like a diff, but for when the file is first checked in.  So, for example, a dictionary
 /// handler might list any the words that were already in the dictionary when it was first checked in.
 /// </summary>
 public IEnumerable<IChangeReport> DescribeInitialContents(FileInRevision fileInRevision, TempFile file)
 {
     throw new NotImplementedException();
 }
 public void WeRemovedEntry_Reported()
 {
     var child = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry id='old1'/>
             </lift>";
     var parent = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry id='old1'/>
                 <entry id='old2'/>
             </lift>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             "header",
                                                      "entry", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(1);
         listener.AssertFirstChangeType<XmlDeletionChangeReport>();
     }
 }
 public void IdHasEntityDoesNotGenerateReports()
 {
     var parent = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
     <entry
     id=""Id'dPrematurely_18d66025-59bc-4bd0-b59c-0f01ae09dede""
     dateCreated='2009-09-14T10:02:26Z'
     dateModified='2009-09-14T10:26:21Z'
     guid='18d66025-59bc-4bd0-b59c-0f01ae09dede'>
     </entry>
             </lift>";
     var child = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
     <entry dateCreated='2009-09-14T10:02:26Z' dateModified='2009-09-14T10:26:21Z' guid='18d66025-59bc-4bd0-b59c-0f01ae09dede' id=""Id&apos;dPrematurely_18d66025-59bc-4bd0-b59c-0f01ae09dede"">
     </entry>
             </lift>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             "header", "entry", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(0);
     }
 }
 public void GuidAttrBeforeIdAttrDoesNotGenerateReports()
 {
     var parent = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry id='fuzz-old1' guid='old1'/>
             </lift>";
     var child = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry guid='old1' id='fuzz-old1'/>
             </lift>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             "header", "entry", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(0);
     }
 }
 public void DuplicateIdInParentEntry_EmitsWarning()
 {
     var parent = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry id='old1'/>
                 <entry id='old1'/>
             </lift>";
     var child = @"<?xml version='1.0' encoding='utf-8'?>
             <lift version='0.10' producer='WeSay 1.0.0.0'>
                 <entry	id='old1'	dateDeleted='2009-06-16T06:14:20Z'/>
                 <entry id='old2'/>
             </lift>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             "header",
                                                      "entry", "id");
         differ.ReportDifferencesToListener();
         Assert.AreEqual(1, listener.Warnings.Count);
     }
 }
Example #19
0
 public void SimpleChangeGeneratesReport()
 {
     const string parent = @"<?xml version='1.0' encoding='utf-8'?>
             <root>
                 <item id='old1'/>
             </root>";
     const string child = @"<?xml version='1.0' encoding='utf-8'?>
             <root>
                 <item id='old1' newAttr='newValue' />
             </root>";
     using (var parentTempFile = new TempFile(parent))
     using (var childTempFile = new TempFile(child))
     {
         var listener = new ListenerForUnitTests();
         var differ = Xml2WayDiffer.CreateFromFiles(parentTempFile.Path, childTempFile.Path, listener,
             null, "item", "id");
         differ.ReportDifferencesToListener();
         listener.AssertExpectedChangesCount(1);
         listener.AssertFirstChangeType<XmlChangedRecordReport>();
         listener.AssertExpectedConflictCount(0);
     }
 }
 public HtmlFileForMerging(string pathToHtml)
 {
     _pathToHtml = pathToHtml;
     xmlFile = TempFile.WithExtension("xhtm");
 }
Example #21
0
        public void Setup()
        {
            _folder = new TemporaryFolder("ChorusSystemTests");
            _targetFile1 = new TempFileFromFolder(_folder,  "one.txt", "just a pretend file");
            _existingNotesFile = new TempFileFromFolder(_folder, "one.txt." + AnnotationRepository.FileExtension,
                        @"<notes version='0'>
                    <annotation ref='somwhere://foo?id=x' class='mergeConflict'>
                        <message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
                            some description of the conflict
                        </message>
                    </annotation>
                </notes>");

            _system = new ChorusSystem(_folder.Path);
            _system.Init(string.Empty);
        }