Beispiel #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));
            }
        }
Beispiel #2
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));
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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));
            }
        }
Beispiel #5
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());
            }
        }
Beispiel #6
0
        public void ImportModelFileSingleModelObject(string _, string modelFilePath, string expectedDtmi, bool strict)
        {
            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}");

            Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode);
            Assert.False(standardError.Contains(Outputs.DefaultErrorToken));

            Assert.True(standardOut.Contains("- Validating models conform to DTDL..."));
            Assert.True(standardOut.Contains($"- Importing model \"{expectedDtmi}\"..."));

            FileInfo modelFile = new FileInfo(Path.GetFullPath(testImportRepo.FullName + "/" + modelFilePath));

            Assert.True(modelFile.Exists);
            DateTime lastWriteTimeUtc = modelFile.LastWriteTimeUtc;

            Assert.AreEqual(expectedDtmi, ParsingUtils.GetRootId(modelFile));

            if (strict)
            {
                Assert.True(standardOut.Contains("- Ensuring DTMIs namespace conformance for model"));
            }

            // Import the same model to ensure its skipped.
            (returnCode, standardOut, _) =
                ClientInvokator.Invoke($"import --model-file \"{qualifiedModelFilePath}\" {targetRepo} {strictSwitch}");

            Assert.AreEqual(Handlers.ReturnCodes.Success, returnCode);
            modelFile = new FileInfo(Path.GetFullPath(testImportRepo.FullName + "/" + modelFilePath));
            Assert.AreEqual(lastWriteTimeUtc, modelFile.LastWriteTimeUtc);
            Assert.True(standardOut.Contains($"Skipping \"{expectedDtmi}\". Model file already exists in repository."));
        }