public void LoadAllFromDirectory() { using (var reader = new TypefaceReader()) { var path = System.Environment.CurrentDirectory; path = Path.Combine(path, ValidateHelvetica.UrlPath); //Get the parent directory var file = new FileInfo(path); var dir = file.Directory; var all = reader.ReadAllTypefaces(dir); Assert.AreEqual(6, all.Length); } }
public void LoadAllFroUris() { var uri = new Uri(ValidateHelvetica.RootUrl); using (var reader = new TypefaceReader(uri)) { List <Uri> uris = new List <Uri>(); uris.Add(new Uri(ValidateHelvetica.UrlPath, UriKind.Relative)); uris.Add(new Uri(ValidateOpenSans.UrlPath, UriKind.Relative)); uris.Add(new Uri(ValidateRoboto.RootUrl + "fonts/subfolder/Roboto.ttf", UriKind.Absolute)); var all = reader.ReadAllTypefaces(uris); //4 fonts match the pattern(s) in the root //+1 in the subfolder int expected = 3; Assert.AreEqual(expected, all.Length); } }
public void LoadAllForPaths() { var parent = new DirectoryInfo(System.Environment.CurrentDirectory); using (var reader = new TypefaceReader(parent)) { List <FileInfo> paths = new List <FileInfo>(); paths.Add(new FileInfo(ValidateHelvetica.UrlPath)); paths.Add(new FileInfo(ValidateOpenSans.UrlPath)); paths.Add(new FileInfo(System.Environment.CurrentDirectory + "/fonts/subfolder/Roboto.ttf")); var all = reader.ReadAllTypefaces(paths); //4 fonts match the pattern(s) in the root //+1 in the subfolder int expected = 3; Assert.AreEqual(expected, all.Length); } }
public void LoadAllFromDirectoryWithMatch() { using (var reader = new TypefaceReader()) { var path = System.Environment.CurrentDirectory; path = Path.Combine(path, ValidateHelvetica.UrlPath); //Get the parent directory var file = new FileInfo(path); var dir = file.Directory; var match = "*.ttf"; var all = reader.ReadAllTypefaces(dir, match); //only 3 fonts match the pattern int expected = 3; Assert.AreEqual(expected, all.Length); } }
public void LoadAllFromDirectoryAndSubdirectories() { using (var reader = new TypefaceReader()) { var path = System.Environment.CurrentDirectory; path = Path.Combine(path, ValidateHelvetica.UrlPath); //Get the parent directory var file = new FileInfo(path); var dir = file.Directory; var match = ""; //should ignore null or empty strings var includeSubs = true; Assert.ThrowsException <TypefaceReadException>(() => { //Becase we have an unsupported woff2 in here and we are not capturing errors then we should fail. var all = reader.ReadAllTypefaces(dir, match, includeSubs); }); } }
public void LoadAllFromDirectoryWithMultipleMatchAndSubdirectories() { using (var reader = new TypefaceReader()) { var path = System.Environment.CurrentDirectory; path = Path.Combine(path, ValidateHelvetica.UrlPath); //Get the parent directory var file = new FileInfo(path); var dir = file.Directory; var match = "*.ttf| *.otf"; var includeSubs = true; var all = reader.ReadAllTypefaces(dir, match, includeSubs); //4 fonts match the pattern(s) in the root //+1 in the subfolder int expected = 5; Assert.AreEqual(expected, all.Length); } }
public void LoadAllFromDirectoryAndSubdirectoriesWithErrors() { using (var reader = new TypefaceReader()) { var path = System.Environment.CurrentDirectory; path = Path.Combine(path, ValidateHelvetica.UrlPath); //Get the parent directory var file = new FileInfo(path); var dir = file.Directory; var match = ""; //should ignore null or empty strings var includeSubs = true; var captureErrors = true; var all = reader.ReadAllTypefaces(dir, match, includeSubs, captureErrors); //6 fonts match the pattern(s) in the root //+1 in the subfolder //+1 unsupported int expected = 8; Assert.AreEqual(expected, all.Length); var error = "unsupported/Festive.woff2"; var found = false; foreach (var info in all) { if (!string.IsNullOrEmpty(info.ErrorMessage)) { Assert.IsTrue(info.Source.EndsWith(error)); Assert.IsFalse(found, "We should be the one and only error"); found = true; } } } }