public void ExportInvocation(string dtmi, string expectedDeps, TestHelpers.ClientType clientType) { string targetRepo = string.Empty; if (clientType == TestHelpers.ClientType.Local) { targetRepo = $"--repo \"{TestHelpers.TestLocalModelRepository}\""; } (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"export --dtmi \"{dtmi}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); FileExtractResult extractResult = ParsingUtils.ExtractModels(standardOut); List <string> modelsResult = extractResult.Models; string[] expectedDtmis = $"{dtmi},{expectedDeps}".Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.True(modelsResult.Count == expectedDtmis.Length); foreach (string model in modelsResult) { string targetId = ParsingUtils.GetRootId(model); Assert.True(expectedDtmis.Contains(targetId)); } }
public void ResolveNoneExistentDtmiFileThrowsException(string dtmi, TestHelpers.ClientType clientType) { ResolverClient client = TestHelpers.GetTestClient(clientType); ResolverException re = Assert.ThrowsAsync <ResolverException>(async() => await client.ResolveAsync(dtmi)); Assert.True(re.Message.StartsWith($"Unable to resolve \"{dtmi}\"")); }
public async Task ResolveSingleModelNoDeps(string dtmi, TestHelpers.ClientType clientType) { ResolverClient client = TestHelpers.GetTestClient(clientType); var result = await client.ResolveAsync(dtmi); Assert.True(result.Keys.Count == 1); Assert.True(result.ContainsKey(dtmi)); Assert.True(TestHelpers.ParseRootDtmiFromJson(result[dtmi]) == dtmi); }
public async Task ResolveMultipleModelsNoDeps(string dtmi1, string dtmi2, TestHelpers.ClientType clientType) { ResolverClient client = TestHelpers.GetTestClient(clientType); var result = await client.ResolveAsync(new string[] { dtmi1, dtmi2 }); Assert.True(result.Keys.Count == 2); Assert.True(result.ContainsKey(dtmi1)); Assert.True(result.ContainsKey(dtmi2)); Assert.True(TestHelpers.ParseRootDtmiFromJson(result[dtmi1]) == dtmi1); Assert.True(TestHelpers.ParseRootDtmiFromJson(result[dtmi2]) == dtmi2); }
public void ResolveWithWrongCasingThrowsException(string dtmi, TestHelpers.ClientType clientType) { ResolverClient client = TestHelpers.GetTestClient(clientType); string expectedExMsg = string.Format(StandardStrings.GenericResolverError, "dtmi:com:example:thermostat;1") + string.Format(StandardStrings.IncorrectDtmiCasing, "dtmi:com:example:thermostat;1", "dtmi:com:example:Thermostat;1"); ResolverException re = Assert.ThrowsAsync <ResolverException>(async() => await client.ResolveAsync(dtmi)); Assert.AreEqual(re.Message, expectedExMsg); }
public void ExportNonExistantDtmiWillError(string dtmi, TestHelpers.ClientType clientType) { string targetRepo = string.Empty; if (clientType == TestHelpers.ClientType.Local) { targetRepo = $"--repo \"{TestHelpers.TestLocalModelRepository}\""; } (int returnCode, _, string standardError) = ClientInvokator.Invoke($"export --dtmi \"{dtmi}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.ResolutionError, returnCode); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); }
public void ValidateModelFileSingleModelObjectWithDeps(string modelFilePath, bool strict, TestHelpers.ClientType clientType) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string strictSwitch = strict ? "--strict" : ""; string targetRepo = string.Empty; if (clientType == TestHelpers.ClientType.Local) { targetRepo = $"--repo \"{TestHelpers.TestLocalModelRepository}\""; } (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"validate --model-file \"{qualifiedModelFilePath}\" {targetRepo} {strictSwitch}"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); if (strict) { Assert.True(standardOut.Contains("- Ensuring DTMIs namespace conformance for model")); Assert.True(standardOut.Contains("- Ensuring model file path adheres to DMR path conventions...")); } }
public async Task ResolveSingleModelWithDeps(string dtmi, string expectedDeps, TestHelpers.ClientType clientType) { ResolverClient client = TestHelpers.GetTestClient(clientType); var result = await client.ResolveAsync(dtmi); var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); Assert.True(result.Keys.Count == expectedDtmis.Length); foreach (var id in expectedDtmis) { Assert.True(result.ContainsKey(id)); Assert.True(TestHelpers.ParseRootDtmiFromJson(result[id]) == id); } // TODO: Evaluate using Azure.Core.TestFramework in future iteration. /* * // Verifying log entries for a Process(...) run * _logger.ValidateLog($"{StandardStrings.ClientInitWithFetcher(localClient.RepositoryUri.Scheme)}", LogLevel.Trace, Times.Once()); * * _logger.ValidateLog($"{StandardStrings.ProcessingDtmi("dtmi:com:example:TemperatureController;1")}", LogLevel.Trace, Times.Once()); * _logger.ValidateLog($"{StandardStrings.FetchingContent(DtmiConventions.DtmiToQualifiedPath(expectedDtmis[0], localClient.RepositoryUri.AbsolutePath))}", LogLevel.Trace, Times.Once()); * * _logger.ValidateLog($"{StandardStrings.DiscoveredDependencies(new List<string>() { "dtmi:com:example:Thermostat;1", "dtmi:azure:DeviceManagement:DeviceInformation;1" })}", LogLevel.Trace, Times.Once()); * * _logger.ValidateLog($"{StandardStrings.ProcessingDtmi("dtmi:com:example:Thermostat;1")}", LogLevel.Trace, Times.Once()); * _logger.ValidateLog($"{StandardStrings.FetchingContent(DtmiConventions.DtmiToQualifiedPath(expectedDtmis[1], localClient.RepositoryUri.AbsolutePath))}", LogLevel.Trace, Times.Once()); * * _logger.ValidateLog($"{StandardStrings.ProcessingDtmi("dtmi:azure:DeviceManagement:DeviceInformation;1")}", LogLevel.Trace, Times.Once()); * _logger.ValidateLog($"{StandardStrings.FetchingContent(DtmiConventions.DtmiToQualifiedPath(expectedDtmis[2], localClient.RepositoryUri.AbsolutePath))}", LogLevel.Trace, Times.Once()); */ }
public async Task ResolveSingleModelTryFromExpanded(string dtmi, string expectedDeps, TestHelpers.ClientType clientType) { var expectedDtmis = $"{dtmi},{expectedDeps}".Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); ResolverClientOptions options = new ResolverClientOptions(DependencyResolutionOption.TryFromExpanded); ResolverClient client = TestHelpers.GetTestClient(clientType, options); var result = await client.ResolveAsync(dtmi); Assert.True(result.Keys.Count == expectedDtmis.Length); foreach (var id in expectedDtmis) { Assert.True(result.ContainsKey(id)); Assert.True(TestHelpers.ParseRootDtmiFromJson(result[id]) == id); } // TODO: Evaluate using Azure.Core.TestFramework in future iteration. /* * string expectedPath = DtmiConventions.DtmiToQualifiedPath( * dtmi, * repoType == "local" ? client.RepositoryUri.AbsolutePath : client.RepositoryUri.AbsoluteUri, * fromExpanded: true); * _logger.ValidateLog(StandardStrings.FetchingContent(expectedPath), LogLevel.Trace, Times.Once()); */ }
public async Task ResolveSingleModelWithDepsDisableDependencyResolution(string dtmi, TestHelpers.ClientType clientType) { ResolverClientOptions options = new ResolverClientOptions(DependencyResolutionOption.Disabled); ResolverClient client = TestHelpers.GetTestClient(clientType, options); var result = await client.ResolveAsync(dtmi); Assert.True(result.Keys.Count == 1); Assert.True(result.ContainsKey(dtmi)); Assert.True(TestHelpers.ParseRootDtmiFromJson(result[dtmi]) == dtmi); }