示例#1
0
        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));
 }
示例#3
0
        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));
 }
示例#5
0
        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));
 }
示例#7
0
 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));
 }
示例#8
0
        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));
 }
示例#10
0
        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);
        }
示例#11
0
        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));
        }
示例#12
0
        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."));
        }
示例#13
0
        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."));
        }
示例#14
0
        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);
        }
示例#15
0
        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."));
        }
示例#16
0
        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."));
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
        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..."));
        }
示例#20
0
        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);
        }
示例#21
0
        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..."));
        }
示例#22
0
        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));
        }
示例#23
0
        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));
        }
示例#24
0
        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. "));
        }
示例#25
0
        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);
        }
示例#26
0
        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..."));
        }
示例#27
0
        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..."));
            }
        }
示例#28
0
        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));
            }
        }
示例#29
0
        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);
        }
示例#30
0
        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());
            }
        }