/// <summary> /// Returns the path for the given filetype. /// </summary> /// <param name="filetype">The <see cref="DicewareFileType"/> to get the path for.</param> /// <returns></returns> public string GetPathForFileType(DicewareFileType filetype) { string filename = Filenames[(int)filetype]; string path = Path.Combine(this.Basepath, filename); /* The default path should return a URI style file:\c\foo path, * check for that, and if not, fall back to to regular path handling. */ if (path.StartsWith("file:", StringComparison.Ordinal)) { try { return(new Uri(path).LocalPath); } catch (UriFormatException) { /* Neither windows nor Linux provide "well formed" URIs * as far as C# is concerned, but the Linux ones cause a * format exception, so let's catch that and try to correct * the formatting error. */ path = path.Replace("file:", "file://"); return(new Uri(path).LocalPath); } } return(Path.GetFullPath(path)); }
public void TestMake(DicewareFileType filetype) { this.userConfig.Wordlist = filetype; var result = this.factory.Make(this.util); Assert.IsInstanceOf(typeof(IPhraseRepository), result, "Assert the returned repository type matches expectations."); }
public void TestGetRandom(DicewareFileType fileType, DicewareIndexLength index, int count) { var repo = new FilePhraseRepository(this.sysConfig.GetPathForFileType(fileType), index, this.util); var result = repo.GetRandom(count); Assert.AreEqual(count, result.Count, "Assert that the returned number of items matches expectations."); }
/// <summary> /// Load the repository's file source. /// </summary> /// <param name="type">The type of Diceware file to load.</param> protected void PopulateData(DicewareFileType type) { if (this.Data.Count > 0) { return; } foreach (string line in File.ReadLines(this.Path)) { string[] parts = line.Split('\t'); this.Data.Add(parts[0], parts[1]); } }
public void TestUserConfig(DicewareFileType fileType) { this.config.Wordlist = fileType; var result = this.repo.GetRandom(1); var wordPool = PresentationPhraseRepositoryTest.shortWords; if (fileType == DicewareFileType.Long) { wordPool = PresentationPhraseRepositoryTest.longWords; } Assert.Contains(result[0], wordPool, "Assert that the returned result is contained in the expected word pool."); }
public void TestInvalidRange(DicewareFileType fileType, DicewareIndexLength index) { var repo = new FilePhraseRepository(this.sysConfig.GetPathForFileType(fileType), index, this.util); Assert.Throws <ArgumentOutOfRangeException>(() => repo.GetRandom(0), "Assert that the count value must be greater than zero."); }