public void Sync_FileLockedForWritingDuringUpdate_GetUpdatedFileOnceLockIsGone() { HgRunner.TimeoutSecondsOverrideForUnitTests = 3; using (var bob = new RepositorySetup("bob")) { bob.ProjectFolderConfig.IncludePatterns.Add("*.txt"); bob.AddAndCheckinFile("one.txt", "hello"); using (var sally = new RepositorySetup("sally", bob)) { bob.AddAndCheckinFile("one.txt", "hello-bob"); using (sally.GetFileLockForWriting("one.txt")) { // Note: Mono succeeds here Assert.That(sally.CheckinAndPullAndMerge(bob).Succeeded, Is.False, "CheckinAndPullAndMerge should have failed"); sally.AssertFileContents("one.txt", "hello"); } sally.AssertSingleHead(); //ok, now whatever was holding that file is done with it, and we try again Assert.That(sally.CheckinAndPullAndMerge(bob).Succeeded, Is.True, "ChecinAndPullAndMerge(bob) should have succeeded"); sally.AssertFileContents("one.txt", "hello-bob"); } } }
public void Unbundle_ValidBundleFile_ReturnsTrue() { using (var setup = new RepositorySetup("unbundleTests")) { var bundleFilePath = setup.RootFolder.GetNewTempFile(false).Path; setup.AddAndCheckinFile(setup.ProjectFolder.GetNewTempFile(true).Path, "some file we don't care about"); var hash = setup.Repository.GetTip().Number.Hash; setup.AddAndCheckinFile(setup.ProjectFolder.GetNewTempFile(true).Path, "another file we don't care about"); setup.Repository.MakeBundle(new [] { hash }, bundleFilePath); setup.Repository.RollbackWorkingDirectoryToLastCheckin(); Assert.That(setup.Repository.Unbundle(bundleFilePath), Is.True); } }
public void SampleDiff() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <CheckList> <CmPossibilityList guid='06425922-3258-4094-a9ec-3c2fe5b52b39'> <Name> <AUni ws='en'>Proper names</AUni> </Name> </CmPossibilityList> </CheckList>"; var child = parent.Replace("Proper names", "My Proper names"); using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile("Sample." + SharedConstants.List, parent); repositorySetup.ChangeFileAndCommit("Sample." + SharedConstants.List, 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); var onlyReport = result[0]; Assert.IsInstanceOf <XmlChangedRecordReport>(onlyReport); Assert.AreEqual(firstFiR.FullPath, onlyReport.PathToFile); } }
public void SynchNow_OnNamedBranchAndDefaultBranchExists_DoesNotMergeWithIt() { using (var repo = new RepositorySetup("bob")) { if (repo.Synchronizer == null) { repo.Synchronizer = repo.CreateSynchronizer(); } repo.Synchronizer.SynchronizerAdjunct = new ProgrammableSynchronizerAdjunct("default"); repo.AddAndCheckinFile("test.txt", "apple"); var afterFirstCheckin = repo.CreateBookmarkHere(); repo.ChangeFileAndCommit("test.txt", "pear", "second on default"); afterFirstCheckin.Go(); repo.Repository.BranchingHelper.Branch(new ConsoleProgress(), "animals"); repo.Synchronizer.SynchronizerAdjunct = new ProgrammableSynchronizerAdjunct("animals"); repo.ChangeFileAndCommit("test.txt", "dog", "first on animals"); var animalHead = repo.CreateBookmarkHere(); repo.AssertHeadCount(2); repo.CheckinAndPullAndMerge(); repo.AssertHeadCount(2); animalHead.AssertRepoIsAtThisPoint(); } }
public void Find2WayDifferencesShouldReportOneChangeNoMatterHowManyWereMade() { // There are actually more than one change, but we don't fret about that at this point. const string parent = @"<?xml version='1.0' encoding='utf-8'?> <UserLexiconSettings> </UserLexiconSettings>"; const string child = @"<?xml version='1.0' encoding='utf-8'?> <UserLexiconSettings> <WritingSystems /> </UserLexiconSettings>"; using (var repositorySetup = new RepositorySetup("randy-" + Guid.NewGuid())) { repositorySetup.AddAndCheckinFile("some.ulsx", parent); repositorySetup.ChangeFileAndCommit("some.ulsx", 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 = _userLexiconSettingsFileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository); Assert.AreEqual(1, result.Count()); Assert.AreEqual("Edited", result.First().ActionLabel); } }
public void SampleDiff() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <TranslatedScripture> <Scripture guid='06425922-3258-4094-a9ec-3c2fe5b52b39'> <VerseSepr> <Uni>,</Uni> </VerseSepr> </Scripture> </TranslatedScripture>"; var child = parent.Replace("<Uni>,</Uni>", "<Uni>+</Uni>"); using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile(SharedConstants.ScriptureTransFilename, parent); repositorySetup.ChangeFileAndCommit(SharedConstants.ScriptureTransFilename, 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); var onlyReport = result[0]; Assert.IsInstanceOf <XmlChangedRecordReport>(onlyReport); Assert.AreEqual(firstFiR.FullPath, onlyReport.PathToFile); } }
public void SampleDiff() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <LayoutInventory> <layout class='CmLocation' type='jtview' name='publishStemLocation#Stem-612' version='19'> <generate class='LexExampleSentence' fieldType='mlstring' restrictions='customOnly' /> </layout> </LayoutInventory>"; var child = parent.Replace("19", "20"); using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile("Sample." + SharedConstants.fwlayout, parent); repositorySetup.ChangeFileAndCommit("Sample." + SharedConstants.fwlayout, 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); var onlyReport = result[0]; Assert.IsInstanceOf <XmlChangedRecordReport>(onlyReport); Assert.AreEqual(firstFiR.FullPath, onlyReport.PathToFile); } }
public void SampleDiff() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <ImportSettings> <ScrImportSet guid='0a0be0c1-39c4-44d4-842e-231680c7cd56' > <ImportType val='2' /> </ScrImportSet> </ImportSettings>"; var child = parent.Replace("val='2'", "val='3'"); using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile(SharedConstants.ImportSettingsFilename, parent); repositorySetup.ChangeFileAndCommit(SharedConstants.ImportSettingsFilename, 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); var onlyReport = result[0]; Assert.IsInstanceOf <XmlChangedRecordReport>(onlyReport); Assert.AreEqual(firstFiR.FullPath, onlyReport.PathToFile); } }
public void Find2WayDifferencesShouldReportOneChangeNoMatterHowManyWereMade() { // There are actually more than one change, but we don't fret about that at this point. const string parent = @"<?xml version='1.0' encoding='utf-8'?> <ldml> <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' /> </ldml>"; const string child = @"<?xml version='1.0' encoding='utf-8'?> <ldml> <identity /> <special xmlns:fw='urn://fieldworks.sil.org/ldmlExtensions/v1' /> <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' /> </ldml>"; using (var repositorySetup = new RepositorySetup("randy-" + Guid.NewGuid())) { repositorySetup.AddAndCheckinFile("some.ldml", parent); repositorySetup.ChangeFileAndCommit("some.ldml", 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 = _ldmlFileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository); Assert.AreEqual(1, result.Count()); Assert.AreEqual("Edited", result.First().ActionLabel); } }
public void FileDeletedLocallyAndChangedRemotelyKeepsChanged() { using (var localRepo = new RepositorySetup("unbundleTests")) { var localFilePath = localRepo.ProjectFolder.GetNewTempFile(true).Path; localRepo.AddAndCheckinFile(localFilePath, "file to change and delete"); using (var remoteRepo = new RepositorySetup("remote", localRepo)) { remoteRepo.CheckinAndPullAndMerge(); var remoteFilePath = Path.Combine(remoteRepo.ProjectFolder.Path, Path.GetFileName(localFilePath)); Assert.That(File.Exists(remoteFilePath)); // Make sure that we have a file to delete. File.Delete(remoteFilePath); remoteRepo.SyncWithOptions(new SyncOptions { CheckinDescription = "delete file", DoMergeWithOthers = false, DoPullFromOthers = false, DoSendToOthers = false }); Assert.That(!File.Exists(remoteFilePath)); // Make sure we actually got rid of it. localRepo.ChangeFileAndCommit(localFilePath, "new file contents", "changed the file"); localRepo.CheckinAndPullAndMerge(remoteRepo); Assert.That(File.Exists(localFilePath), Is.True, "Did not keep changed file."); var chorusNotesPath = localFilePath + ".ChorusNotes"; Assert.That(File.Exists(chorusNotesPath), "Did not record conflict"); AssertThatXmlIn.File(chorusNotesPath).HasAtLeastOneMatchForXpath("//annotation[@class='mergeconflict']"); } } }
public void Find2WayDifferencesShouldReportThreeChanges() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <AdditionalFields> <CustomField class='WfiWordform' key='WfiWordformCertified' name='Certified' type='Boolean' /> <CustomField class='WfiWordform' key='WfiWordformGoner' name='Goner' type='Boolean' /> <CustomField class='WfiWordform' key='WfiWordformDirtball' name='Dirtball' type='Boolean' /> </AdditionalFields>"; // One deletion, one change, and one insertion, and one unchanged. const string child = @"<?xml version='1.0' encoding='utf-8'?> <AdditionalFields> <CustomField class='WfiWordform' key='WfiWordformCertified' name='Certified' type='Boolean' /> <CustomField class='WfiWordform' key='WfiWordformDirtball' name='Dirtball' type='Integer' /> <CustomField class='WfiWordform' key='WfiWordformNewby' name='Newby' type='Boolean' /> </AdditionalFields>"; using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile(SharedConstants.CustomPropertiesFilename, parent); repositorySetup.ChangeFileAndCommit(SharedConstants.CustomPropertiesFilename, 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(3, result.Count); } }
public void GetRevision_RevisionDoesExist_Ok() { using (var setup = new RepositorySetup("Dan")) { setup.AddAndCheckinFile("test.txt", "hello"); Assert.IsNotNull(setup.Repository.GetRevision("0")); } }
public void HasFileHandlers_ValidCommit_Validates_DoesNothing() { using (var bob = new RepositorySetup("bob")) { bob.AddAndCheckinFile("test.chorusTest", "hello"); using (var cop = new CommitCop(bob.Repository, ChorusFileTypeHandlerCollection.CreateWithTestHandlerOnly(), bob.Progress)) { bob.ChangeFile("test.chorusTest", "aloha"); bob.AddAndCheckinFile("test2.chorusTest", "hi"); Assert.That(cop.ValidationResult, Is.Null.Or.Empty); } bob.AssertHeadCount(1); bob.AssertLocalRevisionNumber(1); bob.AssertFileExistsInRepository("test2.chorusTest"); bob.AssertFileContents("test.chorusTest", "aloha"); bob.AssertFileContents("test2.chorusTest", "hi"); } }
public void Sync_FileLockedForReadingDuringMerge_LeftWithMultipleHeads() { HgRunner.TimeoutSecondsOverrideForUnitTests = 3; using (var bob = new RepositorySetup("bob")) { bob.ProjectFolderConfig.IncludePatterns.Add("*.txt"); bob.AddAndCheckinFile("one.txt", "hello"); using (var sally = new RepositorySetup("sally", bob)) { bob.AddAndCheckinFile("one.txt", "hello-bob"); using (sally.GetFileLockForReading("one.txt")) { sally.CheckinAndPullAndMerge(bob); } sally.AssertHeadCount(2); } } }
public void HasFileHandlers_Validates_DoesNothing() { using (var bob = new RepositorySetup("bob")) { using (var cop = new CommitCop(bob.Repository, ChorusFileTypeHandlerCollection.CreateWithTestHandlerOnly(), bob.Progress)) { bob.AddAndCheckinFile("test.chorusTest", "hello"); } bob.AssertLocalRevisionNumber(0); } }
public void NoMatchingFileHandlers_DoesNothing() { using (var bob = new RepositorySetup("bob")) { using (var cop = new CommitCop(bob.Repository, ChorusFileTypeHandlerCollection.CreateWithTestHandlerOnly(), bob.Progress)) { bob.AddAndCheckinFile("test.abc", "hello"); Assert.That(cop.ValidationResult, Is.Null.Or.Empty); } bob.AssertLocalRevisionNumber(0); } }
public void Sync_MergeFailure_NoneOfTheOtherGuysFilesMakeItIntoWorkingDirectory() { using (var bob = new RepositorySetup("bob")) { bob.ProjectFolderConfig.IncludePatterns.Add("*.txt"); bob.AddAndCheckinFile("aaa.txt", "apple"); bob.AddAndCheckinFile("bbb.txt", "bread"); bob.AddAndCheckinFile("zzz.txt", "zoo"); using (var sally = new RepositorySetup("sally", bob)) { bob.AddAndCheckinFile("aaa.txt", "bob-apple"); bob.AddAndCheckinFile("bbb.txt", "bob-bread"); bob.AddAndCheckinFile("zzz.txt", "bob-zoo"); using (new FailureSimulator("TextMerger-bbb.txt")) { sally.AddAndCheckinFile("aaa.txt", "sally-apple"); sally.AddAndCheckinFile("bbb.txt", "sally-bread"); sally.AddAndCheckinFile("zzz.txt", "sally-zipper"); Assert.That(sally.CheckinAndPullAndMerge(bob).Succeeded, Is.False); //make sure we ended up on Sally's revision, even though Bob's are newer var currentRevision = sally.Repository.GetRevisionWorkingSetIsBasedOn(); Assert.AreEqual("sally", sally.Repository.GetRevision(currentRevision.Number.Hash).UserId); //sally should see no changes, because it should all be rolled back sally.AssertFileContents("aaa.txt", "sally-apple"); sally.AssertFileContents("bbb.txt", "sally-bread"); sally.AssertFileContents("zzz.txt", "sally-zipper"); // sally.ShowInTortoise(); sally.AssertHeadCount(2); Assert.That(sally.GetProgressString(), Does.Not.Contain("creates new remote heads")); } } } File.Delete(Path.Combine(Path.GetTempPath(), "TextMerger-bbb.txt")); }
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()); } }
public void SynchNow_OnDefaultBranchAndAnotherBranchExists_DoesNotMergeWithIt() { using (var repo = new RepositorySetup("bob")) { repo.AddAndCheckinFile("test.txt", "hello"); repo.AssertHeadCount(1); repo.ChangeFileOnNamedBranchAndComeBack("test.txt", "blah", "mybranch"); //NB: this used to pass prior to hg 1.5, but, well, it shouldn't! // Shouldn't there be two heads after the branch, above? (jh, April 2010) // repo.AssertHeadCount(1); repo.ChangeFileAndCommit("test.txt", "hello there", "second"); repo.AssertHeadCount(2); repo.CheckinAndPullAndMerge(); repo.AssertHeadCount(2); } }
public void SecondCheckin_Invalid_BacksOut() { using (var bob = new RepositorySetup("bob")) { bob.AddAndCheckinFile("test.chorusTest", "hello"); bob.ChangeFile("test.chorusTest", ChorusTestFileHandler.GetInvalidContents()); using (var cop = new CommitCop(bob.Repository, ChorusFileTypeHandlerCollection.CreateWithTestHandlerOnly(), bob.Progress)) { Assert.That(cop.ValidationResult, Is.Not.Null.And.Not.Empty); bob.Repository.Commit(false, "bad data"); } Debug.WriteLine(bob.Repository.GetLog(-1)); bob.AssertHeadCount(1); bob.AssertLocalRevisionNumber(2); bob.AssertFileContents("test.chorusTest", "hello"); } }
public void Sync_ExistingRejectChangeSet_NotMergedIn() { using (var bob = new RepositorySetup("bob")) { bob.AddAndCheckinFile("test.txt", "original"); bob.CreateRejectForkAndComeBack(); bob.ChangeFileAndCommit("test.txt", "ok", "goodGuy"); //move on so we have two distinct branches bob.AssertHeadCount(2); bob.CheckinAndPullAndMerge(null); Assert.AreEqual("goodGuy", bob.Repository.GetRevisionWorkingSetIsBasedOn().Summary); bob.AssertLocalRevisionNumber(3); bob.AssertHeadCount(2); } }
public void InitialFileCommit_Invalid_BacksOut() { using (var bob = new RepositorySetup("bob")) { bob.AddAndCheckinFile("validfile.chorustest", "valid contents"); bob.ChangeFile("test.chorusTest", ChorusTestFileHandler.GetInvalidContents()); using (var cop = new CommitCop(bob.Repository, ChorusFileTypeHandlerCollection.CreateWithTestHandlerOnly(), bob.Progress)) { bob.Repository.AddAndCheckinFile("test.chorusTest"); Assert.That(cop.ValidationResult, Does.Contain("Failed")); } Debug.WriteLine(bob.Repository.GetLog(-1)); bob.AssertHeadCount(1); bob.AssertLocalRevisionNumber(2); bob.AssertFileDoesNotExistInRepository("test.chorusTest"); bob.AssertFileExistsInRepository("validfile.chorustest"); } }
public void SampleDiff() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <Lexicon> <header> <LexDb guid='06425922-3258-4094-a9ec-3c2fe5b52b39' > <Introduction> <StText guid='45b78bcf-2400-48d5-a9c1-973447d36d4e'> <DateModified val='2011-2-2 19:39:28.829' /> <Paragraphs> <ownseq class='StTxtPara' guid='9edbb6e1-2bdd-481c-b84d-26c69f22856c'> <ParseIsCurrent val='False' /> </ownseq> </Paragraphs> </StText> </Introduction> </LexDb> </header> <LexEntry guid='016f2759-ed12-42a5-abcb-7fe3f53d05b0' /> </Lexicon>"; var child = parent.Replace("False", "True"); using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile(string.Format("{0}_01.{1}", SharedConstants.Lexicon, SharedConstants.Lexdb), parent); repositorySetup.ChangeFileAndCommit(string.Format("{0}_01.{1}", SharedConstants.Lexicon, SharedConstants.Lexdb), 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); var onlyReport = result[0]; Assert.IsInstanceOf <XmlChangedRecordReport>(onlyReport); Assert.AreEqual(firstFiR.FullPath, onlyReport.PathToFile); } }
public void Find2WayDifferencesShouldReportOneChangeEvenWhenNoneArePresent() { // One 'change' reported, even for the exact same file. const string parent = @"<?xml version='1.0' encoding='utf-8'?> <UserLexiconSettings> </UserLexiconSettings>"; using (var repositorySetup = new RepositorySetup("randy-" + Guid.NewGuid())) { repositorySetup.AddAndCheckinFile("some.ulsx", parent); repositorySetup.ChangeFileAndCommit("some.ulsx", parent, "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 firstFiR = hgRepository.GetFilesInRevision(first).First(); var result = _userLexiconSettingsFileHandler.Find2WayDifferences(firstFiR, firstFiR, hgRepository); Assert.AreEqual(1, result.Count()); Assert.AreEqual("Edited", result.First().ActionLabel); } }
public void Find2WayDifferencesShouldReportOneChange() { const string parent = "{\"modelversion\": 7000000}"; // One change. const string child = "{\"modelversion\": 7000002}"; using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile("FLExProject.ModelVersion", parent); repositorySetup.ChangeFileAndCommit("FLExProject.ModelVersion", 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); Assert.IsInstanceOf(typeof(FieldWorksModelVersionUpdatedReport), result[0]); } }
public void SampleDiff() { const string parent = @"<?xml version='1.0' encoding='utf-8'?> <ReferenceSystem> <ScrRefSystem guid='0a0be0c1-39c4-44d4-842e-231680c7cd56' > <Books> <ScrBookRef guid='51caa4a0-8cd1-4c66-acac-7daead917510'> <BookName> <AUni ws='en'>Genesis</AUni> </BookName> </ScrBookRef> </Books> </ScrRefSystem> </ReferenceSystem>"; var child = parent.Replace("Genesis", "Startup"); using (var repositorySetup = new RepositorySetup("randy")) { repositorySetup.AddAndCheckinFile(SharedConstants.ScriptureReferenceSystemFilename, parent); repositorySetup.ChangeFileAndCommit(SharedConstants.ScriptureReferenceSystemFilename, 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 = FileHandler.Find2WayDifferences(firstFiR, secondFiR, hgRepository).ToList(); Assert.AreEqual(1, result.Count); var onlyReport = result[0]; Assert.IsInstanceOf <XmlChangedRecordReport>(onlyReport); Assert.AreEqual(firstFiR.FullPath, onlyReport.PathToFile); } }
public void Sync_ModifiedFileIsInvalid_CheckedInButThenBackedOut() { /* * @ changeset: 2 | summary: [Backout due to validation Failure] | | o changeset: 1 | summary: missing checkin description | | o changeset: 0 | summary: Add test.chorusTest */ using (var bob = new RepositorySetup("bob")) { bob.AddAndCheckinFile("test.chorusTest", "original"); bob.AssertLocalRevisionNumber(0); bob.ChangeFile("test.chorusTest", ChorusTestFileHandler.GetInvalidContents()); bob.CheckinAndPullAndMerge(); bob.AssertLocalRevisionNumber(2); bob.AssertHeadCount(1); bob.AssertLocalRevisionNumber(int.Parse(bob.Repository.GetTip().Number.LocalRevisionNumber)); Debug.WriteLine(bob.Repository.GetLog(-1)); } }
[Category("UnknownMonoIssue")] // Do3WayMerge is never called on Mono, for some reason. public void DictConfigMerge_DifferentUpradePathKeepsFileFormat() { const string commonAncestor = null; const string sue = @"<?xml version='1.0' encoding='utf-8'?> <DictionaryConfiguration name='Root-based (complex forms as subentries)' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' allPublications='true' version='14' lastModified='2014-10-07'> <ConfigurationItem name='Main Entry' style='Dictionary-Normal' isEnabled='true' field='LexEntry' cssClassNameOverride='entry'> <ParagraphOptions paragraphStyle='Dictionary-Normal' continuationParagraphStyle='Dictionary-Continuation' /> <ConfigurationItem name='Headword' between=' ' after=' ' style='Dictionary-Headword' isEnabled='true' field='MLHeadWord' cssClassNameOverride='mainheadword'> <WritingSystemOptions writingSystemType='vernacular' displayWSAbreviation='false'> <Option id='vernacular' isEnabled='false'/> <Option id='fr' isEnabled='true' /> </WritingSystemOptions> </ConfigurationItem> <ConfigurationItem name='Variant Forms' before='(' between='; ' after=') ' isEnabled='true' field='VariantFormEntryBackRefs'> <ListTypeOptions list='variant'> <Option isEnabled='true' id='b0000000-c40e-433e-80b5-31da08771344'/> <Option isEnabled='false' id='0c4663b3-4d9a-47af-b9a1-c8565d8112ed'/> </ListTypeOptions> </ConfigurationItem> </ConfigurationItem> </DictionaryConfiguration>"; const string randy = @"<?xml version='1.0' encoding='utf-8'?> <DictionaryConfiguration xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' name='Root-based (complex forms as subentries)' allPublications='true' version='17' lastModified='2014-10-07'> <ConfigurationItem name='Main Entry' style='Dictionary-Normal' isEnabled='true' field='LexEntry' cssClassNameOverride='entry'> <ParagraphOptions paragraphStyle='Dictionary-Normal' continuationParagraphStyle='Dictionary-Continuation' /> <ConfigurationItem name='Headword' between=' ' after=' ' style='Dictionary-Headword' isEnabled='true' field='MLHeadWord' cssClassNameOverride='mainheadword'> <WritingSystemOptions writingSystemType='vernacular' displayWSAbreviation='false'> <Option id='vernacular' isEnabled='true'/> </WritingSystemOptions> </ConfigurationItem> <ConfigurationItem name='Variant Forms' before='(' between='; ' after=') ' isEnabled='true' field='VariantFormEntryBackRefs'> <ListTypeOptions list='variant'> <Option isEnabled='false' id='b0000000-c40e-433e-80b5-31da08771344'/> <Option isEnabled='true' id='0c4663b3-4d9a-47af-b9a1-c8565d8112ed'/> </ListTypeOptions> </ConfigurationItem> </ConfigurationItem> </DictionaryConfiguration>"; using (var tempFolder = new TemporaryFolder("Temp")) { // Copy the Dictionary Configuration Schema to where the Dictionary Configuration Handler Strategy looks var appsDir = Path.GetDirectoryName(Utilities.StripFilePrefix(Assembly.GetExecutingAssembly().CodeBase)); var xsdPath = Path.Combine(appsDir, "TestData", "Language Explorer", "Configuration", SharedConstants.DictConfigSchemaFilename); var xsdPathInProj = Path.Combine(tempFolder.Path, SharedConstants.DictConfigSchemaFilename); File.Copy(xsdPath, xsdPathInProj, true); using (var sueRepo = new RepositorySetup("Sue", true)) { sueRepo.AddAndCheckinFile("unrelated.txt", "unrelated to SUT, here to get us rev 0 so repos are related"); using (var randyRepo = new RepositorySetup("Randy", sueRepo)) { // By doing the clone before making Sue's changes, we get the common starting state in both repos. sueRepo.AddAndCheckinFile(string.Format("root.{0}", SharedConstants.fwdictconfig), sue); var randyDictConfigInRepoPath = Path.Combine(randyRepo.ProjectFolder.Path, string.Format("root.{0}", SharedConstants.fwdictconfig)); var mergeConflictsNotesFile = ChorusNotesMergeEventListener.GetChorusNotesFilePath(randyDictConfigInRepoPath); Assert.IsFalse(File.Exists(mergeConflictsNotesFile), "ChorusNotes file should NOT have been in working set."); randyRepo.AddAndCheckinFile(string.Format("root.{0}", SharedConstants.fwdictconfig), randy); randyRepo.CheckinAndPullAndMerge(sueRepo); Assert.IsTrue(File.Exists(mergeConflictsNotesFile), "ChorusNotes file should have been in working set."); var notesContents = File.ReadAllText(mergeConflictsNotesFile); Assert.IsNotNullOrEmpty(notesContents); Assert.That(notesContents, Is.StringContaining("Both added the same element, but with different content")); Assert.That(notesContents, Is.StringContaining("The merger kept the change made by Randy.")); Assert.That(notesContents, Is.StringContaining("alphaUserId=\"Randy\"")); Assert.That(notesContents, Is.StringContaining("betaUserId=\"Sue\"")); // Make sure merged file has Randy's changes var doc = XDocument.Load(randyDictConfigInRepoPath); var options = doc.Root.Element("ConfigurationItem").Elements("ConfigurationItem").Last(/*Variant Forms*/) .Element("ListTypeOptions").Elements("Option").ToList(); Assert.AreEqual(2, options.Count, "There should be two Variant Forms options"); Assert.AreEqual("b0000000-c40e-433e-80b5-31da08771344", options[0].Attribute("id").Value, "Options are out of order"); Assert.AreEqual("0c4663b3-4d9a-47af-b9a1-c8565d8112ed", options[1].Attribute("id").Value, "Options are out of order"); Assert.AreEqual("false", options[0].Attribute("isEnabled").Value, "First option should be disabled"); Assert.AreEqual("true", options[1].Attribute("isEnabled").Value, "Second option should be enabled"); // Make sure merged file does *not* have Sue's changes options = doc.Root.Element("ConfigurationItem").Element("ConfigurationItem" /*Headword*/) .Element("WritingSystemOptions").Elements("Option").ToList(); Assert.AreEqual(1, options.Count, "There should be only one WS Option"); Assert.AreEqual("vernacular", options[0].Attribute("id").Value, "should be default vernacular"); Assert.AreEqual("true", options[0].Attribute("isEnabled").Value, "should be enabled"); // Make sure the merged file has proper xsd namespace attributes var xsiAttr = doc.Root.Attribute("xsi"); var xsdAttr = doc.Root.Attribute("xsd"); Assert.Null(xsiAttr, "xsi missing namespace"); Assert.Null(xsdAttr, "xsd missing namespace"); // XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance"; XNamespace xsdNs = "http://www.w3.org/2001/XMLSchema"; xsiAttr = doc.Root.Attribute(xsiNs + "xsi"); xsdAttr = doc.Root.Attribute(xsdNs + "xsd"); Assert.Null(xsiAttr, "xsi attribute missing entirely from result"); Assert.Null(xsdAttr, "xsd attribute missing entirely from result"); } } } }
public void GetFilteredStatusForFilesHasExpectedResults() { using (var repo = new RepositorySetup("BigFiles", true)) { // 'clean' - C repo.AddAndCheckinFile("control.txt", "original"); repo.AddAndCheckinFile("modified.txt", "original"); repo.AddAndCheckinFile("removed.txt", "removed properly"); repo.AddAndCheckinFile("goner.txt", "short lived"); File.WriteAllText(Path.Combine(repo.ProjectFolder.Path, "added.txt"), "added file"); // 'modified' - M repo.ChangeFile("modified.txt", "updated"); // 'added' - A repo.Repository.Execute(10, "add", "added.txt"); // 'removed' - R repo.Repository.Execute(10, "rm", "removed.txt"); // 'missing' - ! File.Delete(Path.Combine(repo.ProjectFolder.Path, "goner.txt")); // 'unknown' - ? File.WriteAllText(Path.Combine(repo.ProjectFolder.Path, "unknown.txt"), "new data"); // excluded File.WriteAllText(Path.Combine(repo.ProjectFolder.Path, "unknown.jpg"), "some binary data"); repo.ProjectFolderConfig.ExcludePatterns.Add("*.jpg"); repo.ProjectFolderConfig.IncludePatterns.Add("*.txt"); var results = LargeFileFilter.GetStatusOfFilesOfInterest(repo.Repository, repo.ProjectFolderConfig); Assert.AreEqual(3, results.Keys.Count); Assert.IsTrue(results.ContainsKey("M")); // tracked and modifed Assert.IsTrue(results.ContainsKey("A")); // Added with hg add Assert.IsTrue(results.ContainsKey("?")); // untracked foreach (var resultKvp in results) { var resultValue = resultKvp.Value; Assert.AreEqual(1, resultValue.Keys.Count); Assert.IsTrue(resultValue.ContainsKey("txt")); Assert.AreEqual(1, resultValue.Values.Count); switch (resultKvp.Key) { case "M": Assert.AreEqual("modified.txt", resultValue["txt"][0]); break; case "A": Assert.AreEqual("added.txt", resultValue["txt"][0]); break; case "?": Assert.AreEqual("unknown.txt", resultValue["txt"][0]); break; } } } }