public void GivenTwoDirectories_ThenGetModulesReturnsTwoModules() { GivenFiles("module-a/1.js", "module-b/2.js"); var source = new DirectorySource<Module>("module-a", "module-b"); var result = source.GetModules(moduleFactory, application); result.Count().ShouldEqual(2); }
public void GivenDirectoryWithFile_ThenGetModulesReturnsModuleWithAsset() { GivenFiles("module-a/1.js"); var source = new DirectorySource<Module>("module-a"); var result = source.GetModules(moduleFactory, application); result.Count().ShouldEqual(1); result.First().Assets.Count.ShouldEqual(1); }
public void UseFileArtifactSource() { var fa = new DirectorySource(_testPath); fa.Mask = "*.xml|*.xsd"; var names = fa.ListArtifactNames(); Assert.AreEqual(3, names.Count()); Assert.IsTrue(names.Contains("extension-definitions.xml")); Assert.IsTrue(names.Contains("flag.xsd")); Assert.IsFalse(names.Contains("patient.sch")); using (var stream = fa.LoadArtifactByName("TestPatient.xml")) { var pat = new FhirXmlParser().Parse <Resource>(SerializationUtil.XmlReaderFromStream(stream)); Assert.IsNotNull(pat); } }
public void StartStopTest() { string filter = "*.*"; using (MemoryLogger logger = new MemoryLogger("memory")) { DirectorySource <string, LogContext> watcher = new DirectorySource <string, LogContext>( TestUtility.GetTestHome(), filter, 1000, new PluginContext(null, logger, null), new SingeLineRecordParser()); watcher.Start(); Assert.Equal($"DirectorySource id {null} watching directory {TestUtility.GetTestHome()} with filter {filter} started.", logger.LastEntry); watcher.Stop(); Assert.Equal($"DirectorySource id {null} watching directory {TestUtility.GetTestHome()} with filter {filter} stopped.", logger.LastEntry); } }
public void TestTimestampWithIncludeSubdirectories() { string sourceId = "TestTimestampWithIncludeSubdirectories"; var subDir1 = "CPU"; var subDir2 = "Memory"; var subdirectories = new string[] { subDir1, subDir2 }; Setup(sourceId, subdirectories); WriteLogs("A", 1, subDir1); Thread.Sleep(200); DateTime timestamp = DateTime.Now; Thread.Sleep(1000); WriteLogs("A", 2, subDir1); WriteLogs("B", 3, subDir2); ListEventSink logRecords = new ListEventSink(); var config = TestUtility.GetConfig("Sources", "IncludeSubdirectories"); DirectorySource <IDictionary <string, string>, LogContext> watcher = CreateDirectorySource(sourceId, "log_?.log", logRecords, config); watcher.InitialPosition = InitialPositionEnum.Timestamp; watcher.InitialPositionTimestamp = timestamp; watcher.Start(); Thread.Sleep(2000); watcher.Stop(); Assert.Equal(5, logRecords.Count); logRecords.Clear(); WriteLogs("B", 1, subDir1); WriteLogs("C", 5, subDir2); watcher.Start(); WriteLogs("D", 7, subDir1); Thread.Sleep(2000); watcher.Stop(); Assert.Equal(13, logRecords.Count); }
public ScanResources(string existingSDpath, string newSDpath, string outputProfileBaseUri, string publisher) { _publisher = publisher; _outputProfileBaseUri = outputProfileBaseUri; _outputProfilePath = newSDpath; ds = new DirectorySource(_outputProfilePath, new DirectorySourceSettings() { IncludeSubDirectories = true }); sourceSD = new CachedResolver( new MultiResolver( ds, new DirectorySource(existingSDpath, new DirectorySourceSettings() { IncludeSubDirectories = true }), new ZipSource(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "specification.zip")) ) ); }
public void TestSourceSpeedTest() { var jsonSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData"), includeSubdirectories: false) { Mask = "*.json", Includes = new[] { "profiles-types.json" } }; Assert.IsNotNull(jsonSource.LoadArtifactByName("profiles-types.json")); var xmlSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), includeSubdirectories: false) { Mask = "*.xml", Includes = new[] { "profiles-types.xml" } }; Assert.IsNotNull(xmlSource.LoadArtifactByName("profiles-types.xml")); var duration = runTest(jsonSource); Assert.IsTrue(duration < 1000); duration = runTest(xmlSource); Assert.IsTrue(duration < 500); long runTest(DirectorySource s) { var sw = new Stopwatch(); sw.Start(); for (var repeat = 0; repeat < 10; repeat++) { s.Refresh(); // force reload of whole file s.ListResourceUris().Count(); } sw.Stop(); return(sw.ElapsedMilliseconds); } }
public void ResolveByCanonicalFromZip() { var extDefn = source.ResolveByCanonicalUri("http://hl7.org/fhir/StructureDefinition/data-absent-reason"); Assert.IsNotNull(extDefn); Assert.IsInstanceOfType(extDefn, typeof(StructureDefinition)); extDefn = source.ResolveByCanonicalUri("http://hl7.org/fhir/StructureDefinition/Patient"); Assert.IsNotNull(extDefn); Assert.IsInstanceOfType(extDefn, typeof(StructureDefinition)); extDefn = source.ResolveByCanonicalUri("http://hl7.org/fhir/StructureDefinition/Patient"); Assert.IsNotNull(extDefn); Assert.IsInstanceOfType(extDefn, typeof(StructureDefinition)); var dirSource = new DirectorySource(@"TestData\validation"); extDefn = dirSource.ResolveByCanonicalUri("http://example.com/StructureDefinition/patient-telecom-reslice-ek|1.0"); Assert.ThrowsException <ArgumentException>(() => dirSource.ResolveByCanonicalUri("http://example.com/StructureDefinition/patient-telecom-reslice-ek|1.0|")); }
private async Task CreateAndRunWatcher <TData>(string testName, string filter, IConfiguration config, Func <List <IEnvelope>, Task> testBody, IRecordParser <TData, LogContext> recordParser) { //Create a distinct directory based on testName so that tests can run in parallel string testDir = Path.Combine(TestUtility.GetTestHome(), testName); //The following will creates all directories and subdirectories in the specified path unless they already exist. Directory.CreateDirectory(testDir); //Clean up before the test rather than after so that we can inspect the files DeleteFiles(testDir, "*.*"); ListEventSink logRecords = new ListEventSink(); DirectorySource <TData, LogContext> watcher = new DirectorySource <TData, LogContext> (testDir, filter, 1000, new PluginContext(config, NullLogger.Instance, null), recordParser, DirectorySourceFactory.CreateLogSourceInfo); watcher.Subscribe(logRecords); watcher.Start(); await testBody(logRecords); watcher.Stop(); }
public List <SysUserMdl> GetUsersBy(string userName) { var users = new DirectorySource <User>(root, SearchScope.Subtree); string queryParams = string.Empty; if (userName.Equals(string.Empty)) { queryParams = userName + "*"; } else { queryParams = "*" + userName + "*"; } var res1 = (from usr in users where usr.SamAccountName == queryParams || usr.DisplayName == queryParams select new SysUserMdl() { emid = usr.SamAccountName, urnm = usr.DisplayName, isck = false, urid = usr.SamAccountName }); return(res1.ToList <SysUserMdl>()); }
public void TestTimestamp() { string sourceId = "TestDirectorySourceTimestamp"; Setup(sourceId); WriteLogs("A", 1); Thread.Sleep(200); DateTime timestamp = DateTime.Now; Thread.Sleep(1000); WriteLogs("A", 2); WriteLogs("B", 3); ListEventSink logRecords = new ListEventSink(); DirectorySource <IDictionary <string, string>, LogContext> watcher = CreateDirectorySource(sourceId, logRecords); watcher.InitialPosition = InitialPositionEnum.Timestamp; watcher.InitialPositionTimestamp = timestamp; watcher.Start(); Thread.Sleep(2000); watcher.Stop(); Assert.Equal(5, logRecords.Count); logRecords.Clear(); WriteLogs("B", 1); WriteLogs("C", 5); watcher.Start(); WriteLogs("D", 7); Thread.Sleep(2000); watcher.Stop(); Assert.Equal(13, logRecords.Count); }
private void Setup() { logger = MockRepository.GenerateStub <ILogger>(); filesList1 = new[] { @"somedir1\file1.txt", @"somedir1\file2.txt", @"somedir1\file3.txt" }; filesList2 = new[] { @"somedir2\file1.txt", @"somedir2\file2.txt", @"somedir2\file3.txt", @"somedir2\subdir\filex.txt" }; ConvertToFullPath(filesList1); ConvertToFullPath(filesList2); package = new StandardPackageDef(); directoryFilesLister = MockRepository.GenerateMock <IDirectoryFilesLister>(); directoryFilesLister.Expect(x => x.ListFiles( Path.GetFullPath("somedir1"), true)).Return(filesList1); directoryFilesLister.Expect(x => x.ListFiles( Path.GetFullPath("somedir2"), true)).Return(filesList2); DirectorySource dir1 = new DirectorySource( logger, directoryFilesLister, "console", "somedir1"); dir1.SetFilter(new RegexFileFilter("File3")); package.AddFilesSource(dir1); DirectorySource dir2 = new DirectorySource( logger, directoryFilesLister, "win.service", "somedir2"); package.AddFilesSource(dir2); copier = MockRepository.GenerateMock <ICopier>(); }
public void OptimizeZipTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp/test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp/test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp/output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp/test.zip"), new FullPath("tmp/output"), true, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); using (ZipArchive archive = ZipFile.OpenRead("tmp/test.zip")) { Assert.Equal(4, archive.Entries.Count); var list = archive.Entries.ToList <ZipArchiveEntry>(); Assert.Contains(list, x => x.FullName == "_zipmetadata.json"); Assert.Contains(list, x => x.FullName == $"test{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test2.txt"); } }
public void TestDirectorySourceMetricsOnSubscribe() { IConfiguration config = GetConfig("directorySourceTest"); string id = config[ConfigConstants.ID]; MemoryLogger logger = new MemoryLogger(null); KinesisTapMetricsSource metrics = new KinesisTapMetricsSource(new PluginContext(null, null, null, null, null)); DirectorySource <string, LogContext> source = new DirectorySource <string, LogContext>( TestUtility.GetTestHome(), "*.*", 1000, new PluginContext(config, logger, metrics), new SingeLineRecordParser()); MockMetricsSink metricsSink = new MockMetricsSink(3600, new PluginContext(config, logger, metrics)); source.Start(); metrics.Subscribe(metricsSink); metricsSink.Stop(); source.Stop(); Assert.Equal(2, metricsSink.AccumlatedValues.Count); Assert.Equal(0, TestUtility.GetMetricsCount(metricsSink.AccumlatedValues)); }
public static Validator GetValidator() { var structureDefinitions = GetStructureDefinitionsPath(); var includeSubDirectories = new DirectorySourceSettings { IncludeSubDirectories = true }; var directorySource = new DirectorySource(structureDefinitions, includeSubDirectories); var cachedResolver = new CachedResolver(directorySource); var coreSource = new CachedResolver(ZipSource.CreateValidationSource()); var combinedSource = new MultiResolver(cachedResolver, coreSource); var settings = new ValidationSettings { EnableXsdValidation = true, GenerateSnapshot = true, Trace = true, ResourceResolver = combinedSource, ResolveExternalReferences = true, SkipConstraintValidation = false }; var validator = new Validator(settings); return(validator); }
public async Task TestJsonLog(string sourceId) { var config = TestUtility.GetConfig("Sources", sourceId); var dir = config["Directory"]; Directory.CreateDirectory(dir); var logFile = Path.Combine(dir, $"{Guid.NewGuid()}.log"); File.WriteAllText(logFile, LOG); try { var source = new DirectorySource <JObject, LogContext>(dir, config["FileNameFilter"], 1000, new PluginContext(config, NullLogger.Instance, null), new SingleLineJsonParser(config["TimestampField"], config["TimestampFormat"], NullLogger.Instance)) { InitialPosition = InitialPositionEnum.BOS }; var sink = new ListEventSink(); source.Subscribe(sink); source.Start(); await Task.Delay(2000); Assert.Equal(2, sink.Count); var record0 = sink[0] as LogEnvelope <JObject>; Assert.Equal(new DateTime(2018, 9, 21, 8, 38, 50, 972), record0.Timestamp); Assert.Equal("UserProfile", record0.Data["ul-log-data"]["method_name"]); Assert.Equal("INFO", record0.Data["ul-tag-status"]); } finally { File.Delete(logFile); } }
protected override int DoExecute(ITaskContextInternal context) { if (_sourcePackagingInfos.Count == 0) { return(0); } if (string.IsNullOrEmpty(_destinationRootDir)) { _destinationRootDir = context.Properties.GetOutputDir(); } FullPath df = new FullPath(_destinationRootDir); ICopier copier = new Copier(context, _logFiles); IZipper zipper = new Zipper(context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); CopyProcessor copyProcessor = new CopyProcessor(context, copier, df); List <string> sourceIds = new List <string>(); foreach (var sourceToPackage in _sourcePackagingInfos) { string sourceId; if (sourceToPackage.SourceType == SourceType.Directory) { var sourceFullPath = new FullPath(sourceToPackage.SourcePath); sourceId = sourceFullPath.GetHashCode().ToString(); DirectorySource directorySource = new DirectorySource(context, directoryFilesLister, sourceId, sourceFullPath, sourceToPackage.Recursive, sourceToPackage.DirectoryFilters); directorySource.SetFileFilter(sourceToPackage.FileFilters); packageDef.AddFilesSource(directorySource); } else { var fileFullPath = new FileFullPath(sourceToPackage.SourcePath); sourceId = fileFullPath.GetHashCode().ToString(); SingleFileSource fileSource = new SingleFileSource(sourceId, fileFullPath); packageDef.AddFilesSource(fileSource); } copyProcessor.AddTransformation(sourceId, sourceToPackage.DestinationPath); sourceIds.Add(sourceId); } IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); if (ShouldPackageBeZipped) { string zipFile = _zipFileName; if (string.IsNullOrEmpty(zipFile)) { zipFile = _zipPrefix; _addVersionAsPostFixToZipFileName = true; _versionFieldCount = 3; } if (zipFile.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) { zipFile = zipFile.Substring(0, zipFile.Length - 4); } string tmp = _addVersionAsPostFixToZipFileName ? $"{zipFile}_{context.Properties.GetBuildVersion().Version.ToString(_versionFieldCount)}.zip" : $"{zipFile}.zip"; zipFile = Path.Combine(_destinationRootDir, tmp); DoLogInfo($"Creating zip file {zipFile}"); ZipProcessor zipProcessor = new ZipProcessor(context, zipper, new FileFullPath(zipFile), df, _optimizeZip, sourceIds, _logFiles); zipProcessor.Process(copiedPackageDef); } return(0); }
public void TestAccessPermissions() { // var (testPath, numFiles) = prepareExampleDirectory(); var(testPath, numFiles) = (_testPath, _numFiles); // Additional temporary folder without read permissions var subPath2 = Path.Combine(testPath, "sub2"); var forbiddenDir = Directory.CreateDirectory(subPath2); // Additional temporary folder with ordinary permissions var subPath3 = Path.Combine(testPath, "sub3"); Directory.CreateDirectory(subPath3); string srcPath = Path.Combine("TestData", "snapshot-test", "WMR"); const string srcFile1 = "MyBasic.structuredefinition.xml"; const string srcFile2 = "MyBundle.structuredefinition.xml"; const string profileUrl1 = @"http://example.org/fhir/StructureDefinition/MyBasic"; const string profileUrl2 = @"http://example.org/fhir/StructureDefinition/MyBundle"; // Create test file in inaccessible subfolder; should be ignored copy(srcPath, srcFile1, subPath2); // Create hidden test file in accessible subfolder; should also be ignored copy(srcPath, srcFile1, subPath3); var filePath = Path.Combine(subPath3, srcFile1); var attr = File.GetAttributes(filePath); File.SetAttributes(filePath, attr | FileAttributes.Hidden); // Create regular test file in accessible subfolder; should be included copy(srcPath, srcFile2, subPath3); numFiles++; bool initialized = false; try { // Abort unit test if we can't access folder permissions var ds = forbiddenDir.GetAccessControl(); // Revoke folder read permissions for the current user string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; var rule = new ssac.FileSystemAccessRule(userName, ssac.FileSystemRights.Read, ssac.AccessControlType.Deny); ds.AddAccessRule(rule); Debug.Print($"Removing read permissions from folder: '{subPath2}' ..."); // Abort unit test if we can't modify file permissions forbiddenDir.SetAccessControl(ds); try { var forbiddenFile = new FileInfo(Path.Combine(subPath2, srcFile1)); // Abort unit test if we can't access file permissions var fs = forbiddenFile.GetAccessControl(); // Revoke file read permissions for the current user fs.AddAccessRule(rule); Debug.Print($"Removing read permissions from fole: '{forbiddenFile}' ..."); // Abort unit test if we can't modify file permissions forbiddenFile.SetAccessControl(fs); initialized = true; try { // Note: we still have write permissions... var dirSource = new DirectorySource(testPath, new DirectorySourceSettings() { IncludeSubDirectories = true }); // [WMR 20170823] Test ListArtifactNames => prepareFiles() var names = dirSource.ListArtifactNames(); Assert.AreEqual(numFiles, names.Count()); Assert.IsFalse(names.Contains(srcFile1)); Assert.IsTrue(names.Contains(srcFile2)); // [WMR 20170823] Also test ListResourceUris => prepareResources() var profileUrls = dirSource.ListResourceUris(ResourceType.StructureDefinition); // Materialize the sequence var urlList = profileUrls.ToList(); Assert.IsFalse(urlList.Contains(profileUrl1)); Assert.IsTrue(urlList.Contains(profileUrl2)); } // API *should* grafecully handle security exceptions catch (UnauthorizedAccessException ex) { Assert.Fail($"Failed! Unexpected UnauthorizedAccessException: {ex.Message}"); } finally { var result = fs.RemoveAccessRule(rule); Assert.IsTrue(result); Debug.Print($"Restoring file read permissions..."); forbiddenFile.SetAccessControl(fs); Debug.Print($"Succesfully restored file read permissions."); // We should be able to delete the file File.Delete(forbiddenFile.FullName); } } finally { var result = ds.RemoveAccessRule(rule); Assert.IsTrue(result); Debug.Print($"Restoring folder read permissions..."); forbiddenDir.SetAccessControl(ds); Debug.Print($"Succesfully restored folder read permissions."); // We should be able to delete the subdirectory Directory.Delete(subPath2, true); } } // If acl initialization failed, then consume the exception and return success // Preferably, skip this unit test / return unknown result - how? catch (Exception ex) when(!initialized) { Debug.Print($"[{nameof(TestAccessPermissions)}] Could not modify directory access permissions: '{ex.Message}'. Skip unit test..."); } }
public void TestGetPathDirectories(string pathEnvironmentVariable, IEnumerable<string> expectedDirectories) { IEnumerable<string> result = new DirectorySource().GetPathDirectories(pathEnvironmentVariable, DirectorySource.PathSeparator); Assert.That(result, Is.EquivalentTo(expectedDirectories)); }
public void TestSourceSpeedTest() { var jsonSource = new DirectorySource( Path.Combine(DirectorySource.SpecificationDirectory, "TestData"), new DirectorySourceSettings() { Mask = "*.json", Includes = new[] { "profiles-types.json" }, IncludeSubDirectories = false }); using (var stream = jsonSource.LoadArtifactByName("profiles-types.json")) { Assert.IsNotNull(stream); } var xmlSource = new DirectorySource( Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), new DirectorySourceSettings() { Mask = "*.xml", Includes = new[] { "profiles-types.xml" }, IncludeSubDirectories = false }); using (var stream = xmlSource.LoadArtifactByName("profiles-types.xml")) { Assert.IsNotNull(stream); } var xmlSourceLarge = new DirectorySource( Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), new DirectorySourceSettings() { Mask = "*.xml", IncludeSubDirectories = true }); using (var stream = xmlSourceLarge.LoadArtifactByName("profiles-types.xml")) { Assert.IsNotNull(stream); } runTest("profiles-types.json", jsonSource, false, 1000); runTest("profiles-types.xml", xmlSource, false, 500); runTest("all xml examples", xmlSourceLarge, false, 10000); runTest("profiles-types.json", jsonSource, true, 1000); runTest("profiles-types.xml", xmlSource, true, 500); runTest("all xml examples", xmlSourceLarge, true, 10000); void runTest(string title, DirectorySource s, bool multiThreaded, long maxDuration) { var sw = new Stopwatch(); sw.Start(); int cnt = 0; s.MultiThreaded = multiThreaded; for (var repeat = 0; repeat < 10; repeat++) { s.Refresh(); // force reload of whole file cnt = s.ListResourceUris().Count(); } sw.Stop(); Console.WriteLine($"{title} : {(multiThreaded ? "multi" : "single")} threaded, {cnt} resources, duration {sw.ElapsedMilliseconds} ms"); Assert.IsTrue(sw.ElapsedMilliseconds < maxDuration); } }
public void LoadDirectories(ISource source) { if (source.Children.Count() == 1) { //var proxy = source.Children.FirstOrDefault() as ProxySource; //if (proxy != null) // source.RemoveChild(proxy); if (Directory.Exists(source.Path)) { var directory = new DirectoryInfo(source.Path); foreach (var subDirectory in directory.GetDirectories()) { var child = source.Children.Where(x => x.Path == subDirectory.FullName).FirstOrDefault(); if (child == null) { child = new DirectorySource() { Name = subDirectory.Name, Path = subDirectory.FullName, Parent = source }; source.AddChild(child); } //LoadDirectories(child); } foreach (var file in directory.GetFiles("*.mp3")) { try { var track = trackController.Search(new Dictionary <string, object> { { "Path", file.FullName } }).FirstOrDefault(); if (track == null) { track = trackController.ReadFromTag(file.FullName); trackController.Save(track); } var item = GetPlaylistItem(source, track); source.AddChild(item); } catch (Exception ex) { log.Error("SourceController.LoadDirectories: Could not load MP3 file. path=" + file.FullName, ex); } } foreach (var file in directory.GetFiles("*.wav")) { try { var track = trackController.Search(new Dictionary <string, object> { { "Path", file.FullName } }).FirstOrDefault(); if (track == null) { track = new OldTrack { Path = file.FullName, Title = file.Name }; trackController.Save(track); } var item = GetPlaylistItem(source, track); source.AddChild(item); } catch (Exception ex) { log.Error("SourceController.LoadDirectories: Could not load WAV file. path=" + file.FullName, ex); } } } } }
public void TestSourceSpeedTest() { // var jsonSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData"), includeSubdirectories: false) var jsonSource = new DirectorySource( Path.Combine(DirectorySource.SpecificationDirectory, "TestData"), new DirectorySourceSettings() { Mask = "*.json", Includes = new[] { "profiles-types.json" }, IncludeSubDirectories = false }); Assert.IsNotNull(jsonSource.LoadArtifactByName("profiles-types.json")); // var xmlSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), includeSubdirectories: false) var xmlSource = new DirectorySource( Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), new DirectorySourceSettings() { Mask = "*.xml", Includes = new[] { "profiles-types.xml" }, IncludeSubDirectories = false }); Assert.IsNotNull(xmlSource.LoadArtifactByName("profiles-types.xml")); // var xmlSourceLarge = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), includeSubdirectories: true) var xmlSourceLarge = new DirectorySource( Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), new DirectorySourceSettings() { Mask = "*.xml", IncludeSubDirectories = true }); Assert.IsNotNull(xmlSourceLarge.LoadArtifactByName("profiles-types.xml")); (var duration, var count) = runTest(jsonSource); Debug.WriteLine($"jsonSource: {count} resources, duration {duration} ms"); Assert.IsTrue(duration < 1000); (duration, count) = runTest(xmlSource); Debug.WriteLine($"xmlSource: {count} resources, duration {duration} ms"); Assert.IsTrue(duration < 500); (duration, count) = runTest(xmlSourceLarge); Debug.WriteLine($"xmlSourceLarge: {count} resources, duration {duration} ms"); Assert.IsTrue(duration < 10000); (long duration, int count) runTest(DirectorySource s) { var sw = new Stopwatch(); sw.Start(); int cnt = 0; for (var repeat = 0; repeat < 10; repeat++) { s.Refresh(); // force reload of whole file cnt = s.ListResourceUris().Count(); } sw.Stop(); return(sw.ElapsedMilliseconds, cnt); } }