public void Constructor_ParentFolderDoesNotExist_Throws() { var path = _parentFolder.Combine("NotThere", "foo", "foo." + Project.ProjectSettingsFileExtension); Assert.Throws <ArgumentException>(() => new Project(path, _projectContext.ResolveForTests <ElementRepository <Session> .Factory>(), _projectContext.ResolveForTests <SessionFileType>())); }
public void Setup() { _rootFolder = new TemporaryFolder("~FamousPainters~"); var italiansFolder = _rootFolder.Combine("~Italians~"); Directory.CreateDirectory(italiansFolder); var imgFileType = new ImageFileType(() => null, null); var audioFileType = new AudioFileType(null, () => null, () => null); var path = _rootFolder.Combine("PierreAugusteRenoir.jpg"); _imgFile1 = SetupData(path, imgFileType, "Claude", "Monet", "1840", "1840"); path = Path.Combine(italiansFolder, "SistineChapel.jpg"); _imgFile2 = SetupData(path, imgFileType, "Michelangelo", "di Lodovico Buonarroti Simoni", "1475", "1564"); path = _rootFolder.Combine("OntheTerrace.mp3"); _audioFile1 = SetupData(path, audioFileType, "Pierre-Auguste", "Renoir", "1841", "1919"); path = Path.Combine(italiansFolder, "TheLastSupper.mp3"); _audioFile2 = SetupData(path, audioFileType, "Leonardo", "da Vinci", "1452", "1519"); _updater = FieldUpdater.CreateMinimalFieldUpdaterForTests(_rootFolder.Path); }
public void Run_GroupHasDoDeletePolicy_DeletionIsPropagated() { using (var from = new TemporaryFolder("synctest_source")) using (var to = new TemporaryFolder("synctest_dest")) { File.WriteAllText(from.Combine("test1.txt"), "Blah blah"); var source = new RawDirectoryGroup("1", from.Path, null, null) { NormallyPropogateDeletions = true }; var groups = new List <FileGroup>(new[] { source }); var controller = new MirrorController(to.Path, groups, 100, new NullProgress()); controller.Run(); //should be there at the destination AssertFileExists(controller, source, to, "test1.txt"); File.Delete(from.Combine("test1.txt")); File.WriteAllText(from.Combine("test2.txt"), "Blah blah"); controller = new MirrorController(to.Path, groups, 100, new NullProgress()); controller.Run(); AssertFileDoesNotExist(controller, source, to, "test1.txt"); } }
private string WriteTestWav(string contents) { var path = _folder.Combine("test.wav"); File.WriteAllText(path, contents); return(path); }
public void Setup() { _folder = new TemporaryFolder("StatisticsViewModelTests"); Directory.CreateDirectory(_folder.Combine("people")); Directory.CreateDirectory(_folder.Combine("sessions")); SIL.Reporting.ErrorReport.IsOkToInteractWithUser = false; }
public void Syncronhize_FileLocked_OtherFileCopied() { using (var from = new TemporaryFolder("synctest_source")) using (var to = new TemporaryFolder("synctest_dest")) { System.IO.File.WriteAllText(from.Combine("test1.txt"), "Blah blah"); System.IO.File.WriteAllText(from.Combine("test2.txt"), "Blah blah blah"); var source = new RawDirectoryGroup("1", from.Path, null, null); var groups = new List <FileGroup>(new[] { source }); var progress = new StringBuilderProgress() { ShowVerbose = true }; var sync = new Synchronizer(to.Path, groups, 100, progress); using (File.OpenWrite(from.Combine("test2.txt"))) //lock it up { sync.GatherPreview(); sync.DoSynchronization(); } AssertFileExists(sync, source, to, "test1.txt"); AssertFileDoesNotExist(sync, source, to, "test2.txt"); Assert.That(progress.ErrorEncountered); } }
public void LaunchDialog_SimulatedUsb_ProjectAlreadyExists() { using (var targetComputer = new TemporaryFolder("clonetest-targetComputer")) using (var usb = new TemporaryFolder("clonetest-Usb")) { Directory.CreateDirectory(usb.Combine("repo1")); HgRepository.CreateRepositoryInExistingDir(usb.Combine("repo1"), new NullProgress()); //ok, the point here is that we already haved something called "repo1" Directory.CreateDirectory(targetComputer.Combine("repo1")); using (var dlg = new GetCloneFromUsbDialog(targetComputer.Path)) { var drives = new List <IUsbDriveInfo>(); drives.Add(new UsbDriveInfoForTests(usb.Path)); //don't look at the actual drives, look at our simulations dlg.Model.DriveInfoRetriever = new RetrieveUsbDriveInfoForTests(drives); if (DialogResult.OK != dlg.ShowDialog()) { return; } } } }
public void DoSynchronization_FileRemovedAndGroupHasDefaultDeletePolicy_FileIsDeletedFromDest() { using (var from = new TemporaryFolder("synctest_source")) using (var to = new TemporaryFolder("synctest_dest")) { File.WriteAllText(from.Combine("test1.txt"), "Blah blah"); var source = new RawDirectoryGroup("1", from.Path, null, null); //ensure this is the defualt Assert.IsFalse(source.NormallyPropogateDeletions); var groups = new List <FileGroup>(new[] { source }); var sync = new Synchronizer(to.Path, groups, 100, new NullProgress()); sync.DoSynchronization(); string destFile = to.Combine(sync.DestinationRootForThisUser, source.Name, "test1.txt"); Assert.IsTrue(File.Exists(destFile)); File.Delete(from.Combine("test1.txt")); sync = new Synchronizer(to.Path, groups, 100, new NullProgress()); Assert.IsTrue(File.Exists(destFile)); sync.DoSynchronization(); Assert.IsFalse(File.Exists(to.Combine("test1.txt"))); } }
public void SaveSettings_PreexistsAndWeSave_MovesCredentials([Values(true, false)] bool isResumable) { ServerSettingsModel.PasswordForSession = Settings.Default.LanguageForgePass = Settings.Default.LanguageForgeUser = null; using (var folder = new TemporaryFolder("ServerSettingsModel")) { const string user = "******"; const string pass = "******"; var subdomain = isResumable ? "resumable" : "hg-public"; var oldHost = $"{subdomain}.languagedepot.org/tpi"; var oldUrl = $"https://{user}:{pass}@{oldHost}"; const string newDomainAndProj = ".languageforge.org/tpi"; var newUrl = $"https://{subdomain}{newDomainAndProj}"; var newUrlWithCredentials = $"https://{user}:{pass}@{subdomain}{newDomainAndProj}"; // Precondition is some url that is not our default from the ServerSettingsModel var original = HgRepository.CreateOrUseExisting(folder.Path, new NullProgress()); original.SetKnownRepositoryAddresses(new[] { new HttpRepositoryPath("languageForge.org [legacy sync]", oldUrl, false) }); var m = new ServerSettingsModel(); m.InitFromProjectPath(folder.Path); m.SaveSettings(); Assert.AreEqual(user, Settings.Default.LanguageForgeUser); Assert.AreEqual(pass, ServerSettingsModel.DecryptPassword(Settings.Default.LanguageForgePass)); Assert.That(folder.Combine(".hg"), Does.Exist); Assert.That(folder.Combine(".hg", "hgrc"), Does.Exist); var repo = HgRepository.CreateOrUseExisting(folder.Path, new NullProgress()); var address = repo.GetDefaultNetworkAddress <HttpRepositoryPath>(); Assert.AreEqual(newUrl, address.URI); Assert.AreEqual(isResumable ? newUrl : newUrlWithCredentials, address.GetPotentialRepoUri(null, null, null), "The new 'potential' URI should contain credentials only when non-resumable"); } }
private string WriteTestWavWithSidecar(string contents) { var path = _folder.Combine("test.wav"); File.WriteAllText(path, contents); File.WriteAllText(path + ".meta", contents); return(path); }
public void TryChangeIdAndSave_FolderRenamed() { var newEvent = CreateSession(); SaveAndChangeIdShouldSucceed(newEvent); Assert.IsTrue(Directory.Exists(_parentFolder.Combine("newId"))); Assert.IsFalse(Directory.Exists(_parentFolder.Combine("xyz"))); }
public void SetBookName_NameIsNotValidFileName_UsesSanitizedName() { var storage = GetInitialStorage(); storage.SetBookName("/b?loom*test/"); Assert.IsTrue(Directory.Exists(_fixtureFolder.Combine("b loom test"))); Assert.IsTrue(File.Exists(_fixtureFolder.Combine("b loom test", "b loom test.htm"))); }
public void LaunchDialog_CustomSourceWillBeFound() { using (var source = new TemporaryFolder("CloneDialogTest")) { Directory.CreateDirectory(source.Combine("repo1")); HgRepository.CreateRepositoryInExistingDir(source.Combine("repo1"), new NullProgress()); LaunchCustomUrl(source.Combine("repo1")); } }
public void LaunchDialog_CustomUrlSourceWontBeFound() //gives HTTP Error 404: Not Found { using (var source = new TemporaryFolder("CloneDialogTest")) { Directory.CreateDirectory(source.Combine("repo1")); HgRepository.CreateRepositoryInExistingDir(source.Combine("repo1"), new NullProgress()); LaunchCustomUrl(@"somewhereElse"); } }
public void WavToMp3_NonExistentFolder() { using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName())) { string newDestination = tempDirPath.Combine(tempDirPath.Path, "New/new/abu2.mp3"); string directory = tempDirPath.Combine(tempDirPath.Path, "New"); WavConverter.WavToMp3(_goodWavFile, newDestination); Assert.IsTrue(Directory.Exists(directory), "SaveBytes did not create the previously nonexistent folder."); } }
public void NewStringsAdded() { using (var testDir = new TemporaryFolder(GetType().Name)) { var poFile = testDir.Combine("mesages.de.po"); File.WriteAllText(poFile, DePoData); var stringsFile = testDir.Combine("strings-de.xml"); File.WriteAllText(stringsFile, DeStringsData); // SUT PoToXml.StoreLocalizedStrings(poFile, stringsFile, null); var result = File.ReadAllText(stringsFile); // The resulting file should contain the 5 original groups plus 3 new (attributes, literals, context help) AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath("/strings/group", 8); const string attGroupXpath = "/strings/group[@id='LocalizedAttributes']"; AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(attGroupXpath, 1); const string attStringXpath = attGroupXpath + "/string"; AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(attStringXpath, 6); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( attStringXpath + "[@id='Abbreviation (Best Analysis)' and @txt='Abkürzung (Bestes Analyse)']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( attStringXpath + "[@id='Allomorph' and @txt='Allomorph']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( attStringXpath + "[@id='Choose {0}' and @txt='{0} wählen']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( attStringXpath + "[@id='Comment' and @txt='Kommentar']", 1); const string litGroupXpath = "/strings/group[@id='LocalizedLiterals']"; AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(litGroupXpath, 1); const string litStringXpath = litGroupXpath + "/string"; AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(litStringXpath, 2); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( litStringXpath + "[@id='Allomorph' and @txt='Allomorph']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( litStringXpath + "[@id='Analysis ' and @txt='Analyse ']", 1); const string helpGroupXpath = "/strings/group[@id='LocalizedContextHelp']"; AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(helpGroupXpath, 1); const string helpStringXpath = helpGroupXpath + "/string"; AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(helpStringXpath, 5); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( helpStringXpath + "[@id='AllomorphAdjacency']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( helpStringXpath + "[@id='AllomorphAdjacency' and @txt='Klicken Sie auf die Taste.']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( helpStringXpath + "[@id='CmdInsertCustomItem' and @txt='Ein neues {0} erstellen.']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( helpStringXpath + "[@id='CmdInsertLexEntryType' and @txt='Ein neues {0} erstellen.']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( helpStringXpath + "[@id='CmdInsertPossibility' and @txt='Ein neues {0} erstellen.']", 1); AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath( helpStringXpath + "[@id='CmdCreateProjectShortcut' and @txt='Eine Desktop-Verknüpfung zu diesem Projekt erstellen.']", 1); } }
public void Save_NewlyCreated_CreatesMetaDataFile() { using (var person = CreatePerson()) { person.Save(); Assert.IsTrue(File.Exists(_parentFolder.Combine("xyz", "xyz.person"))); Assert.AreEqual(1, Directory.GetFiles(_parentFolder.Combine("xyz")).Length); } }
public void GetDirectoriesWithMecurialRepos_OneDriveOneRepo_ReturnsRepoPath() { using (var usb = new TemporaryFolder("clonetestUsb")) { Directory.CreateDirectory(usb.Combine("test")); Directory.CreateDirectory(usb.Combine("testrepo", ".hg")); var model = new CloneFromUsb(); var drives = new List <IUsbDriveInfo>(); drives.Add(new UsbDriveInfoForTests(usb.Path)); model.DriveInfoRetriever = new RetrieveUsbDriveInfoForTests(drives); Assert.AreEqual(1, model.GetDirectoriesWithMecurialRepos().Count()); Assert.AreEqual(usb.Combine("testrepo"), model.GetDirectoriesWithMecurialRepos().First()); } }
public void AddAndCheckinFile(string fileName, string contents) { var p = ProjectFolder.Combine(fileName); File.WriteAllText(p, contents); Repository.AddAndCheckinFile(p); }
public void GetNewOutputFileName_OutputFileExists_ReturnsNameWithNumberedSuffix() { File.OpenWrite(_tempFolder.Combine("test.mp3")).Close(); Assert.AreEqual("test_01.mp3", _model.GetNewOutputFileName(true)); File.OpenWrite(_tempFolder.Combine("test_01.mp3")).Close(); Assert.AreEqual("test_02.mp3", _model.GetNewOutputFileName(true)); File.OpenWrite(_tempFolder.Combine("test_02.mp3")).Close(); Assert.AreEqual("test_03.mp3", _model.GetNewOutputFileName(true)); File.Delete(_tempFolder.Combine("test_01.mp3")); Assert.AreEqual("test_01.mp3", _model.GetNewOutputFileName(true)); }
public void CreateBookOnDiskFromTemplate_FromFactoryTemplate_SameNameAlreadyUsed_FindsUsableNumberSuffix() { Directory.CreateDirectory(_projectFolder.Combine("My Book")); Directory.CreateDirectory(_projectFolder.Combine("My Book1")); Directory.CreateDirectory(_projectFolder.Combine("My Book3")); var source = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections", "Templates", "Basic Book"); var path = _starter.CreateBookOnDiskFromTemplate(source, _projectFolder.Path); Assert.AreEqual("My Book2", Path.GetFileName(path)); Assert.IsTrue(Directory.Exists(path)); Assert.IsTrue(File.Exists(Path.Combine(path, "My Book2.htm"))); }
public void Run_ToldToSkipDirectory_DoesNotCopyDirectoryOrChildren() { CreateSourceDirectoriesAndGenericFile("fruit", "skipMe", "treefruit", "apple.txt"); var path = CreateSourceDirectoriesAndGenericFile("fruit", "vinefruit", "rasberry.txt"); _maker.StartingDirectory += ((o, args) => { if (args.Path.Contains("skip")) { args.PendingAction = MirrorAction.Skip; } }); _maker.Run(); AssertCorrespondingFileExists(path); AssertCorrespondingDirectoryDoesNotExist(_sourceTempFolder.Combine("fruit", "skipMe")); }
public void MoveToRecycleBin_MoveBothFileAndMetaFile_MovesFiles() { var f = CreateComponentFile("abc.zzz"); Assert.IsTrue(ComponentFile.MoveToRecycleBin(f, false)); Assert.IsFalse(File.Exists(_parentFolder.Combine("abc.zzz"))); Assert.IsFalse(File.Exists(_parentFolder.Combine("abc.zzz.meta"))); }
public void Load_AfterSave_IsoPreserved() { string settingsPath = _parentFolder.Combine("foo." + Project.ProjectSettingsFileExtension); var project = new Project(settingsPath, GetSessionRepo, _projectContext.ResolveForTests <SessionFileType>()); project.Iso639Code = "abc"; project.Save(); var project2 = new Project(settingsPath, _projectContext.ResolveForTests <ElementRepository <Session> .Factory>(), _projectContext.ResolveForTests <SessionFileType>()); Assert.AreEqual("abc", project2.Iso639Code); }
public RepositorySetup(string cloneName, RepositorySetup sourceToClone) { Init(cloneName); string pathToProject = RootFolder.Combine(ProjectNameForTest); ProjectFolderConfig = sourceToClone.ProjectFolderConfig.Clone(); ProjectFolderConfig.FolderPath = pathToProject; sourceToClone.MakeClone(pathToProject); ProjectFolder = TemporaryFolder.TrackExisting(RootFolder.Combine(ProjectNameForTest)); var hg = new HgRepository(pathToProject, Progress); hg.SetUserNameInIni(cloneName, Progress); }
public void MakeListItemWhenAlreadyHaveProjectName_MakesDisabledItem() { using (var usb = new TemporaryFolder("clonetestUsb")) { var path = usb.Combine("test1"); Directory.CreateDirectory(path); var testFile = Path.Combine(path, "test.file"); File.WriteAllText(testFile, @"exist"); var repo = HgRepository.CreateRepositoryInExistingDir(path, new NullProgress()); repo.AddAndCheckinFile(testFile); var model = new CloneFromUsb { ExistingProjects = new HashSet <string> { "test1" } }; var item = model.CreateListItemFor(path); Assert.That(item, Is.Not.Null, "model should have made a list item"); Assert.That(item.Text, Is.EqualTo("test1")); Assert.That(item.Tag, Is.EqualTo(path)); var last = File.GetLastWriteTime(path); var expectedSubitem = last.ToShortDateString() + " " + last.ToShortTimeString(); // Not a great test, basically duplicates the impl Assert.That(item.SubItems[1].Text, Is.EqualTo(expectedSubitem)); Assert.That(item.ToolTipText, Is.EqualTo(CloneFromUsb.ProjectWithSameNameExists)); Assert.That(item.ImageIndex, Is.EqualTo(2)); Assert.That(item.ForeColor, Is.EqualTo(CloneFromUsb.DisabledItemForeColor)); } }
public void GetDirectoriesWithMecurialRepos_TwoRepos_ReturnsOnlyUnfilteredPath() { using (var usb = new TemporaryFolder("clonetestUsb")) { Directory.CreateDirectory(usb.Combine("test1")); Directory.CreateDirectory(usb.Combine("test1", ".hg")); Directory.CreateDirectory(usb.Combine("testSKIP")); Directory.CreateDirectory(usb.Combine("testSKIP", ".hg")); var model = new CloneFromUsb(); var drives = new List <IUsbDriveInfo>(); drives.Add(new UsbDriveInfoForTests(usb.Path)); model.DriveInfoRetriever = new RetrieveUsbDriveInfoForTests(drives); model.ProjectFilter = path => !path.Contains("SKIP"); Assert.AreEqual(1, model.GetDirectoriesWithMecurialRepos().Count()); } }
public void LaunchDialog_SimulatedUsb_USBHasInvalidRepo() { using (var targetComputer = new TemporaryFolder("clonetest-targetComputer")) using (var usb = new TemporaryFolder("clonetest-Usb")) { var badRepoDir = usb.Combine("badrepo"); CreateInvalidRepoInDir(badRepoDir); //ok, the point here is that we already haved something called "repo1" Directory.CreateDirectory(targetComputer.Combine("repo1")); using (var dlg = new GetCloneFromUsbDialog(targetComputer.Path)) { var drives = new List <IUsbDriveInfo>(); drives.Add(new UsbDriveInfoForTests(usb.Path)); //don't look at the actual drives, look at our simulations dlg.Model.DriveInfoRetriever = new RetrieveUsbDriveInfoForTests(drives); if (DialogResult.OK != dlg.ShowDialog()) { return; } } } }
public void Play_GiveThaiFileName_ShouldHearTwoSounds() { using (var d = new TemporaryFolder("palaso media test")) { var soundPath = d.Combine("ก.wav"); File.Create(soundPath).Close(); using (var f = TempFile.TrackExisting(soundPath)) { var w = new BackgroundWorker(); // ReSharper disable once RedundantDelegateCreation w.DoWork += new DoWorkEventHandler((o, args) => SystemSounds.Exclamation.Play()); using (var x = AudioFactory.CreateAudioSession(f.Path)) { x.StartRecording(); w.RunWorkerAsync(); Thread.Sleep(2000); x.StopRecordingAndSaveAsWav(); } using (var y = AudioFactory.CreateAudioSession(f.Path)) { y.Play(); Thread.Sleep(1000); y.StopPlaying(); } } } }
internal static void AddBook(TemporaryFolder collectionFolder, string bookTitle) { string path = collectionFolder.Combine(bookTitle); Directory.CreateDirectory(path); File.WriteAllText(Path.Combine(path, $"{bookTitle}.htm"), @"<html></html>"); }