示例#1
0
        public void CanMakeNotesBarWithOtherFiles()
        {
            using (var otherFile = new TempFileFromFolder(_folder, "two.txt", "just a pretend file"))
                using (var otherNotesFile = new TempFileFromFolder(_folder,
                                                                   "two.txt." + AnnotationRepository.FileExtension,
                                                                   @"<notes version='0'>
					<annotation ref='somwhere://foo?guid=x' class='mergeConflict'>
						<message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
							some description of the conflict
						</message>
					</annotation>
				</notes>"                ))
                {
                    var mapping = new NotesToRecordMapping();
                    mapping.FunctionToGoFromObjectToItsId =
                        obj => "x";                 // means it looks for "x" as the id in the one.txt urls and the guid in the two.txt urls.
                    using (var view = _system.WinForms.CreateNotesBar(_targetFile1.Path,
                                                                      (new List <String> {
                        otherFile.Path
                    }), "guid", mapping, _progress))
                    {
                        view._model.SetTargetObject("myobj");
                        var annotations = view._model.GetAnnotationsToShow().ToList();
                        Assert.That(annotations, Has.Count.EqualTo(2),
                                    "should have obtained annotations from both files");
                        ShowWindowWithControlThenClose(view);
                    }
                }
        }
示例#2
0
 public void RemoveOldLocks_WLockButNotRunningHg_LockRemoved()
 {
     using (var setup = new HgTestSetup())
     {
         var file = TempFileFromFolder.CreateAt(setup.Root.Combine(".hg", "wlock"), "blah");
         Assert.IsTrue(setup.Repository.RemoveOldLocks());
         Assert.IsFalse(File.Exists(file.Path));
     }
 }
示例#3
0
 public void RemoveOldLocks_WLockAndLockButNotRunningHg_BothLocksRemoved()
 {
     using (var setup = new HgTestSetup())
     {
         var file1 = TempFileFromFolder.CreateAt(setup.Root.Combine(".hg", "wlock"), "blah");
         var file2 = TempFileFromFolder.CreateAt(setup.Root.Combine(".hg", "store", "lock"), "blah");
         Assert.That(setup.Repository.RemoveOldLocks(), Is.True);
         Assert.That(File.Exists(file1.Path), Is.False);
         Assert.That(File.Exists(file2.Path), Is.False);
     }
 }
示例#4
0
 public GroupOfConflictFiles(string ancestor, string bob, string sally)
 {
     Folder = new TemporaryFolder("ChorusTest");
     // NB: ChorusNotesFileSyncTests::MergeConflictFiles_AncestorDidNotExist feeds an empty string for ancestor,
     // which is not valid in the Palaso CreateXmlFileWithContents method now.
     // So, we have to use the CreateAt method instead.
     AncestorFile = string.IsNullOrEmpty(ancestor)
                         ? TempFileFromFolder.CreateAt(Path.Combine(Folder.Path, "ancestor.lift.ChorusNotes"), ancestor)
                         : TempFileFromFolder.CreateXmlFileWithContents("ancestor.lift.ChorusNotes", Folder, ancestor);
     BobFile   = TempFileFromFolder.CreateXmlFileWithContents("bob.lift.ChorusNotes", Folder, bob);
     SallyFile = TempFileFromFolder.CreateXmlFileWithContents("sally.lift.ChorusNotes", Folder, sally);
 }
示例#5
0
        public void RemoveOldLocks_LockAndHgIsRunning_ReturnsFalse()
        {
            using (var setup = new HgTestSetup())
            {
                //we have to pretent to be hg
                var ourName = Process.GetCurrentProcess().ProcessName;

                using (var file = TempFileFromFolder.CreateAt(setup.Root.Combine(".hg", "store", "lock"), "blah"))
                {
                    Assert.IsFalse(setup.Repository.RemoveOldLocks(ourName, true));
                }
            }
        }
示例#6
0
        public void LiftSynchronizerReadsLift13VersionCorrectly()
        {
            // Setup
            using (var liftProject = new TemporaryFolder("TempProj_LIFT_NOLDML"))
                using (var liftFile = new TempFileFromFolder(liftProject, "proj.lift", TestLift13File))
                {
                    // SUT
                    var syncAdjunct = new LiftSynchronizerAdjunct(liftFile.Path);

                    // Verification
                    Assert.AreEqual("default", syncAdjunct.BranchName, "BranchName should be 'default' for LIFT0.13");
                }
        }
示例#7
0
 public void CorrectlyAppendsLdmlVersion3ToBranchName()
 {
     using (var liftProject = new TemporaryFolder("TempProj_LIFT"))
         using (var liftFile = new TempFileFromFolder(liftProject, "proj.lift", TestLift13File))
         {
             var wsDirectory = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(liftFile.Path), "WritingSystems"));
             using (var writingSystemsDir =
                        TempFileFromFolder.CreateAt(liftProject.Combine("WritingSystems", "lang.ldml"), LdmlContentForTests.Version3("en", "", "", "")))
             {
                 var syncAdjunct = new LiftSynchronizerAdjunct(liftFile.Path);
                 Assert.AreEqual("LIFT0.13_ldml3", syncAdjunct.BranchName, "BranchName should be 'LIFT0.13_ldml3' with version 3 ldml files");
             }
         }
 }
示例#8
0
 public void IsFileLocked_FileExistsAndIsLocked_ReturnsTrue()
 {
     using (var file = new TempFileFromFolder(_parentFolder))
     {
         var stream = File.OpenWrite(file.Path);
         try
         {
             Assert.IsTrue(FileUtils.IsFileLocked(file.Path));
         }
         finally
         {
             stream.Close();
         }
     }
 }
示例#9
0
        public void MANUAL_ReplaceFileWithUserInteractionIfNeeded_DifferentDrives_OK()
        {
            Reporting.ErrorReport.IsOkToInteractWithUser = false;
            using (var source = new TempFile("one"))
                using (var backup = new TempFile("two"))
                {
                    var drives = UsbDriveInfo.GetDrives();
                    Assert.Greater(drives.Count, 0, "This test requires at least one writeable USB drive");

                    var testFolder = Path.Combine(drives[0].RootDirectory.FullName, "PalasoFileUtilsUnitTests");
                    Directory.CreateDirectory(testFolder);
                    using (var folder = TemporaryFolder.TrackExisting(testFolder))
                        using (var destination = new TempFileFromFolder(folder))
                        {
                            FileUtils.ReplaceFileWithUserInteractionIfNeeded(source.Path, destination.Path, backup.Path);
                        }
                }
        }
示例#10
0
        public void GetFilesInRevision_OnlyOneRevisionInRepo_GivesAllFiles()
        {
            using (var testRoot = new TemporaryFolder("ChorusRetrieveTest"))
                using (var f = new TempFileFromFolder(testRoot))
                {
                    File.WriteAllText(f.Path, "one");

                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    var repo = new HgRepository(testRoot.Path, _progress);

                    repo.AddAndCheckinFile(f.Path);
                    repo.Commit(true, "initial");
                    var revisions = repo.GetAllRevisions();
                    Assert.AreEqual(1, revisions.Count);
                    var files = repo.GetFilesInRevision(revisions[0]);
                    Assert.AreEqual(1, files.Count());
                    Assert.AreEqual(f.Path, files.First().FullPath);
                }
        }
示例#11
0
        public void ShowNotesBar()
        {
            using (var folder = new TemporaryFolder("NotesModelTests"))
                using (var dataFile = new TempFileFromFolder(folder, "one.txt", "just a pretend file"))
                    using (new TempFileFromFolder(folder, "one.txt." + AnnotationRepository.FileExtension,
                                                  @"<notes version='0'>
					<annotation ref='somwhere://foo?id=x' class='question'>
						<message guid='123' author='john' status='open' date='2009-07-18T23:53:04Z'>
							Suzie, is this ok?
						</message>
						<message guid='222' author='suzie' status='closed' date='2009-09-19T23:53:04Z'>
							It's fine.
						</message>
					</annotation>
					<annotation ref='lift://name%20with%20space.lift?id=x' class='mergeConflict'>
						<message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'>
							some description of the conflict
						</message>
					</annotation>
					<annotation ref='somwhere://foo2?id=y' class='note'/>
				</notes>"                ))
                    {
                        var chorus = new ChorusSystem(folder.Path);
                        var view   = chorus.WinForms.CreateNotesBar(dataFile.Path, NotesToRecordMapping.SimpleForTest(), _progress);
                        view.Height = 32;
                        view.SetTargetObject("x");

                        TextBox b = new TextBox();
                        b.Location     = new Point(0, 50);
                        b.Text         = "x";
                        b.TextChanged += new EventHandler((s, e) => view.SetTargetObject(b.Text));
                        var form = new Form();
                        form.Size = new Size(700, 600);
                        form.Controls.Add(view);
                        form.Controls.Add(b);

                        Application.EnableVisualStyles();
                        Application.Run(form);
                    }
        }
示例#12
0
        public void MANUAL_ReplaceFileWithUserInteractionIfNeeded_DifferentDrives_OK()
        {
            ErrorReport.IsOkToInteractWithUser = false;
            using (var source = new TempFile("one"))
                using (var backup = new TempFile("two"))
                {
                    // Since UsbDriveInfo was moved to SIL.Core.Desktop, we need to use reflection to access
                    // the drives since we can't add a reference to SIL.Core.Desktop.
                    Assembly   coreDesktopAssembly = Assembly.Load("SIL.Core.Desktop");
                    Type       usbDriveInfoType    = coreDesktopAssembly.GetType("SIL.UsbDrive.UsbDriveInfo");
                    MethodInfo getDrivesMethod     = usbDriveInfoType.GetMethod("GetDrives");
                    dynamic    drives = getDrivesMethod.Invoke(usbDriveInfoType, null);
                    Assert.Greater(drives.Count, 0, "This test requires at least one writeable USB drive");

                    var testFolder = Path.Combine(drives[0].RootDirectory.FullName, "PalasoFileUtilsUnitTests");
                    Directory.CreateDirectory(testFolder);
                    using (var folder = TemporaryFolder.TrackExisting(testFolder))
                        using (var destination = new TempFileFromFolder(folder))
                        {
                            FileUtils.ReplaceFileWithUserInteractionIfNeeded(source.Path, destination.Path, backup.Path);
                        }
                }
        }
示例#13
0
 public void IsFileLocked_FileExistsAndIsNotLocked_ReturnsFalse()
 {
     using (var file = new TempFileFromFolder(_parentFolder))
         Assert.IsFalse(FileUtils.IsFileLocked(file.Path));
 }
示例#14
0
 public IDisposable GetLock()
 {
     return(TempFileFromFolder.CreateAt(Root.Combine(".hg", "store", "lock"), "blah"));
 }
示例#15
0
 public void GetIsStandardPcmAudioFile_SourceHasStandardAudioSuffixButNotExt_ReturnsFalse()
 {
     using (var tempFile = new TempFileFromFolder(_parentFolder, "blah_StandardAudio.mp3", ""))
         Assert.IsFalse(AudioVideoFileTypeBase.GetIsStandardPcmAudioFile(tempFile.Path));
 }