public async Task FetchLocalRepository(bool fetchExpanded) { // Casing is irrelevant for fetchers as they grab content based on file-path // which will always be lowercase. Casing IS important for the resolve flow // and is covered by tests there. string targetDtmi = "dtmi:com:example:temperaturecontroller;1"; ResolverClientOptions options = fetchExpanded ? new ResolverClientOptions(DependencyResolutionOption.TryFromExpanded) : new ResolverClientOptions(); string expectedPath = DtmiConventions.DtmiToQualifiedPath(targetDtmi, _localUri.AbsolutePath, fetchExpanded); LocalModelFetcher localFetcher = new LocalModelFetcher(_logger.Object, options); string fetcherPath = localFetcher.GetPath(targetDtmi, _localUri, fetchExpanded); Assert.AreEqual(fetcherPath, expectedPath); // Resolution correctness is covered in ResolverIntegrationTests FetchResult fetchResult = await localFetcher.FetchAsync(targetDtmi, _localUri); Assert.True(!string.IsNullOrEmpty(fetchResult.Definition)); Assert.True(!string.IsNullOrEmpty(fetchResult.Path)); Assert.AreEqual(fetchResult.FromExpanded, fetchExpanded); _logger.ValidateLog(StandardStrings.FetchingContent(fetcherPath), LogLevel.Trace, Times.Once()); }
public void FetchLocalRepositoryModelDoesNotExist() { string targetDtmi = "dtmi:com:example:thermojax;1"; LocalModelFetcher localFetcher = new LocalModelFetcher(_logger.Object, new ResolverClientOptions()); Assert.ThrowsAsync <FileNotFoundException>(async() => await localFetcher.FetchAsync(targetDtmi, _localUri)); string expectedModelPath = DtmiConventions.DtmiToQualifiedPath(targetDtmi, _localUri.AbsolutePath); _logger.ValidateLog(StandardStrings.ErrorAccessLocalRepositoryModel(expectedModelPath), LogLevel.Warning, Times.Once()); }
public void FetchLocalRepositoryDoesNotExist() { string targetDtmi = "dtmi:com:example:thermostat;1"; Uri invalidFileUri = new Uri("file://totally/fake/path/please"); LocalModelFetcher localFetcher = new LocalModelFetcher(_logger.Object, new ResolverClientOptions()); Assert.ThrowsAsync <DirectoryNotFoundException>(async() => await localFetcher.FetchAsync(targetDtmi, invalidFileUri)); _logger.ValidateLog(StandardStrings.ErrorAccessLocalRepository(invalidFileUri.AbsolutePath), LogLevel.Error, Times.Once()); }