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 IndexModelsWillErrorWithInvalidDirectory() { (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"index --local-repo ./nonexistent_directory/"); Assert.AreEqual(Handlers.ReturnCodes.InvalidArguments, returnCode); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); }
public void ImportModelFileExpandedModelArray(string modelFilePath, string expectedDeps, string expectedPaths, bool strict) { // TODO: Revisit. ResetTestRepoDir(); string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string strictSwitch = strict ? "--strict" : ""; string targetRepo = $"--local-repo \"{testImportRepo.FullName}\""; (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"import --model-file \"{qualifiedModelFilePath}\" {targetRepo} {strictSwitch}"); string[] dtmis = expectedDeps.Split(",", StringSplitOptions.RemoveEmptyEntries); string[] paths = expectedPaths.Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); for (int i = 0; i < dtmis.Length; i++) { Assert.True(standardOut.Contains($"- Importing model \"{dtmis[i]}\"...")); FileInfo modelFile = new FileInfo(Path.GetFullPath(testImportRepo.FullName + "/" + paths[i])); Assert.True(modelFile.Exists); Assert.AreEqual(dtmis[i], ParsingUtils.GetRootId(modelFile)); } }
public void IndexModelsErrorsOnInvalidModelJson() { (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"index -o willfail.json"); Assert.AreEqual(Handlers.ReturnCodes.ProcessingError, returnCode); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); }
public void ExportInvalidDtmiFormatWillError(string dtmi) { (int returnCode, _, string standardError) = ClientInvokator.Invoke($"export --dtmi \"{dtmi}\""); Assert.AreEqual(Handlers.ReturnCodes.InvalidArguments, returnCode); Assert.True(standardError.Contains("Invalid dtmi format")); }
public void IndexModelsSupportsDebugHeaders(string outfilePath) { outfilePath = Path.GetFullPath(outfilePath); (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"index --local-repo {indexableRepoPath} -o {outfilePath} --debug"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.True(standardError.Contains(Outputs.DebugHeader)); }
public void ExpandModelsWillErrorOnInvalidModelJson() { (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"expand --local-repo " + $"{Path.Combine(TestHelpers.TestLocalModelRepository, "dtmi", "expandfail")}"); Assert.AreEqual(Handlers.ReturnCodes.ProcessingError, returnCode); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); }
public void ExportNonDtdlContentWillError(string dtmi) { (int returnCode, _, string standardError) = ClientInvokator.Invoke($"export --dtmi \"{dtmi}\" --repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.ResolutionError, returnCode); Assert.True(standardError.Contains($"{Outputs.DefaultErrorToken} Failure handling \"{dtmi}\".")); }
public void IndexModelsSilentNoStandardOut(string outfilePath) { outfilePath = Path.GetFullPath(outfilePath); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"index --local-repo {indexableRepoPath} -o {outfilePath} --silent"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.True(string.IsNullOrEmpty(standardOut)); }
public void ExportSilentNoStandardOut(string dtmi) { (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"export --silent --dtmi \"{dtmi}\" --repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.AreEqual(string.Empty, standardOut); }
public void ExpandModelsRepoSupportsDebugHeaders() { testExpandableRepo.Create(); (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"expand --local-repo {testExpandableRepo.FullName} --debug"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardError.Contains(Outputs.DebugHeader)); }
public void ImportModelFileErrorNonDtdlContent(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string targetRepo = $"--local-repo \"{testImportRepo.FullName}\""; (int returnCode, _, string standardError) = ClientInvokator.Invoke($"import --model-file \"{qualifiedModelFilePath}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.InvalidArguments, returnCode); Assert.True(standardError.Contains($"{Outputs.DefaultErrorToken} Importing model file contents of kind String is not yet supported.")); }
public void ImportModelFileErrorEmptyJsonArray(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string targetRepo = $"--local-repo \"{testImportRepo.FullName}\""; (int returnCode, _, string standardError) = ClientInvokator.Invoke($"import --model-file \"{qualifiedModelFilePath}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.ValidationError, returnCode); Assert.True(standardError.Contains($"{Outputs.DefaultErrorToken} No models to import.")); }
public void ImportModelFileSilentNoStandardOut(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string targetRepo = $"--local-repo \"{testImportRepo.FullName}\""; (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"import --silent --model-file \"{qualifiedModelFilePath}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.AreEqual(string.Empty, standardOut); }
public void ValidateModelFileErrorEmptyJsonArray(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, _, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.InvalidArguments, returnCode); Assert.True(standardError.Contains($"{Outputs.DefaultErrorToken} No models to validate.")); }
public void ValidateModelFileErrorStrictRuleFilePathRequiresLocalRepo(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, _, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"http://localhost\" --strict"); Assert.AreEqual(Handlers.ReturnCodes.ValidationError, returnCode); Assert.True(standardError.Contains($"{Outputs.DefaultErrorToken} Model file path validation requires a local repository.")); }
public void ExpandModelsRepoSilentNoStandardOut() { TestHelpers.DirectoryCopy( $"{Path.Combine(TestHelpers.TestLocalModelRepository, "indexable")}", testExpandableRepo.FullName, true, true); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"expand --local-repo {testExpandableRepo.FullName} --silent"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.AreEqual(string.Empty, standardOut); }
public void ValidateModelFileSilentNoStandardOut(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"" + $"validate --silent --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.True(!standardError.Contains(Outputs.DefaultErrorToken)); Assert.AreEqual(string.Empty, standardOut); }
public void ImportModelFileErrorResolutionFailure(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string targetRepo = $"--local-repo \"{testImportRepo.FullName}\""; (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"import --model-file \"{qualifiedModelFilePath}\" {targetRepo}"); Assert.AreEqual(Handlers.ReturnCodes.ResolutionError, returnCode); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); }
public void ValidateModelFileErrorIncompleteArrayOfModels(string modelFilePath, string missingReferences) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\" "); Assert.True(standardError.Contains( $"{Outputs.DefaultErrorToken} DtmiResolver failed to resolve requisite references to element(s): " + missingReferences)); Assert.AreEqual(Handlers.ReturnCodes.ResolutionError, returnCode); }
public void ValidateModelFileErrorResolutionFailure(string modelFilePath) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\" "); Assert.AreEqual(Handlers.ReturnCodes.ResolutionError, returnCode); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); }
public void ImportModelFileErrorStrictRuleIdNamespaceConformance(string modelFilePath, string rootDtmi, string violationDtmi) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string targetRepo = $"--local-repo \"{testImportRepo.FullName}\""; (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"import --model-file \"{qualifiedModelFilePath}\" {targetRepo} --strict"); Assert.AreEqual(Handlers.ReturnCodes.ValidationError, returnCode); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); Assert.True(standardOut.Contains($"- Ensuring DTMIs namespace conformance for model \"{rootDtmi}\"...")); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardError.Contains(violationDtmi)); }
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 ValidateModelFileErrorStrictRuleIdFilePath(string modelFilePath, string rootDtmi) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\" --strict"); Assert.AreEqual(Handlers.ReturnCodes.ValidationError, returnCode); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); Assert.True(standardOut.Contains($"- Ensuring DTMIs namespace conformance for model \"{rootDtmi}\"...")); Assert.True(standardOut.Contains($"- Ensuring model file path adheres to DMR path conventions...")); Assert.True(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardError.Contains($"File \"{Path.GetFullPath(qualifiedModelFilePath)}\" does not adhere to DMR path conventions. ")); }
public void ExportOutFile(string dtmi, string outfilePath) { string qualifiedPath = Path.GetFullPath(outfilePath); (int returnCode, _, string standardError) = ClientInvokator.Invoke($"export -o \"{qualifiedPath}\" --dtmi \"{dtmi}\" --repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); FileExtractResult extractResult = ParsingUtils.ExtractModels(new FileInfo(qualifiedPath)); List <string> modelsResult = extractResult.Models; string targetId = ParsingUtils.GetRootId(modelsResult[0]); Assert.AreEqual(dtmi, targetId); }
public void ValidateModelUsingCentralContext(string modelFilePath, int expectedReturnCode) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\" "); Assert.AreEqual(expectedReturnCode, returnCode); if (expectedReturnCode == 2) { Assert.True(standardError.Contains("has value 'geopoint' that is not a DTMI or a DTDL term")); return; } Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); }
public void ValidateModelFileSingleModelObject(string modelFilePath, bool strict) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string strictSwitch = strict ? "--strict" : ""; (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\" " + $"{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 void ExportInvocationWithModelFile(string modelFilePath, string expectedDeps) { string qualifiedModelFilePath = Path.GetFullPath(Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath)); (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"export --model-file \"{qualifiedModelFilePath}\" --repo \"{TestHelpers.TestLocalModelRepository}\""); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode, standardError); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); FileExtractResult extractResult = ParsingUtils.ExtractModels(standardOut); List <string> modelsResult = extractResult.Models; string[] expectedDtmis = 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 ValidateModelFileArrayOfModels(string modelFilePath, bool strict) { string qualifiedModelFilePath = Path.Combine(TestHelpers.TestLocalModelRepository, modelFilePath); string strictSwitch = strict ? "--strict" : ""; (int returnCode, string standardOut, string standardError) = ClientInvokator.Invoke($"" + $"validate --model-file \"{qualifiedModelFilePath}\" " + $"--repo \"{TestHelpers.TestLocalModelRepository}\" " + $"{strictSwitch}"); if (!strict) { Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); Assert.True(standardOut.Contains("- Validating models conform to DTDL...")); return; } // TODO: --strict validation is not fleshed out for an array of models. Assert.True(standardError.Contains($"{Outputs.DefaultErrorToken} Strict validation requires a single root model object.")); Assert.AreEqual(Handlers.ReturnCodes.ValidationError, returnCode); }
public void ExpandModelsRepo() { TestHelpers.DirectoryCopy( $"{Path.Combine(TestHelpers.TestLocalModelRepository, "indexable")}", testExpandableRepo.FullName, true, true); (int returnCode, string _, string standardError) = ClientInvokator.Invoke($"expand --local-repo {testExpandableRepo.FullName}"); Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode); Assert.False(standardError.Contains(Outputs.DefaultErrorToken)); var modelFilePaths = new List <string>(); foreach (string file in Directory.EnumerateFiles(testExpandableRepo.FullName, "*.json", new EnumerationOptions { RecurseSubdirectories = true })) { if (file.EndsWith(".expanded.json")) { continue; } modelFilePaths.Add(file); } foreach (string modelFile in modelFilePaths) { string expandedModelFile = modelFile.Replace(".json", ".expanded.json"); using JsonDocument expandedModelDocument = JsonDocument.Parse(File.ReadAllText(expandedModelFile)); JsonElement root = expandedModelDocument.RootElement; Assert.AreEqual(root.ValueKind, JsonValueKind.Array); JsonElement firstModelElement = root[0]; string modelFileContent = File.ReadAllText(modelFile); Assert.AreEqual(ParsingUtils.GetRootId(modelFileContent), firstModelElement.GetProperty("@id").GetString()); } }