public void ProducesCorrectOutputFromCoreDirectory_preloadedbinaries()
        {
            // Arrange
            var testOutputDirName = "TestMdOutput_CoreNodeModels";

            // Act
            tempDirectory = CreateTempOutputDirectory();
            Assert.That(tempDirectory.Exists);

            var opts = new FromDirectoryOptions
            {
                InputFolderPath  = DynamoCoreDir,
                RecursiveScan    = true,
                OutputFolderPath = tempDirectory.FullName,
                Filter           = preloadedLibraryPaths.Concat(new string[]
                                                                { CORENODEMODELS_DLL_NAME, "GeometryUI.dll", "PythonNodeModels.dll", "Watch3dNodeModels.dll", "UnitsUI.dll", "" }),
                ReferencePaths = new List <string>()
            };

            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            var generatedFileNames = tempDirectory.GetFiles().Select(x => x.Name);

            //assert count is correct.
            //TODO this should be 653 - but 2 tsplines nodes have such long signatures the paths are too long for windows.
            Assert.AreEqual(675, generatedFileNames.Count());
        }
Ejemplo n.º 2
0
        internal static string HandleFromDirectory(FromDirectoryOptions opts)
        {
            try
            {
                FromDirectoryCommand.HandleDocumentationFromDirectory(opts);
            }
            catch (Exception e)
            {
                LogExceptionToConsole(e);
            }

            return("");
        }
        public void DictionaryContentIsFoundCorrectlyForCoreNodes()
        {
            // Test output is generated with the following args:
            //
            // NodeDocumentationMarkdownGenerator.exe
            // fromdirectory
            // -i "..\Dynamo\bin\nodes"
            // -o "..\Dynamo\test\Tools\docGeneratorTestFiles\TestMdOutput_CoreNodeModels"
            // -d "..\Dynamo\test\Tools\docGeneratorTestFiles\sampledictionarycontent\Dynamo_Nodes_Documentation.json"
            // -x  "..\Dynamo\test\Tools\docGeneratorTestFiles\testlayoutspec.json"
            // -f "CoreNodeModels.dll"

            // Arrange
            var testOutputDirName = "TestMdOutput_CoreNodeModels";

            var coreNodeModelsDll = Path.Combine(DynamoCoreNodesDir, CORENODEMODELS_DLL_NAME);

            Assert.That(File.Exists(coreNodeModelsDll));

            // Act
            tempDirectory = CreateTempOutputDirectory();
            Assert.That(tempDirectory.Exists);

            var opts = new FromDirectoryOptions
            {
                InputFolderPath     = DynamoCoreNodesDir,
                OutputFolderPath    = tempDirectory.FullName,
                DictionaryDirectory = mockedDictionaryJson,
                LayoutSpecPath      = testLayoutSpecPath,
                Filter = new List <string> {
                    CORENODEMODELS_DLL_NAME
                },
                ReferencePaths = new List <string>(),
                Overwrite      = true
            };

            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            var generatedFileNames = tempDirectory.GetFiles().Select(x => x.FullName);

            //assert that the generated markdown files all contain an "indepth section" from the dictionary entry, which means
            //they were all found.

            Assert.True(generatedFileNames.Where(x => Path.GetExtension(x).Contains("md")).All(x => File.ReadAllText(x).ToLower().Contains("in depth")));
        }
        public void ProducesCorrectOutputFromCoreDirectory_dsFiles()
        {
            // Arrange
            var testOutputDirName = "TestMdOutput_CoreNodeModels";

            var expectedFileNames = new List <string>
            {
                "LoopWhile.md",
                "List.Equals.md",
                "List.GroupByFunction.md",
                "List.MaximumItemByKey.md",
                "List.MinimumItemByKey.md",
                "List.Rank.md",
                "List.RemoveIfNot.md",
                "List.SortByFunction.md",
                "List.TrueForAll.md",
                "List.TrueForAny.md"
            };

            // Act
            tempDirectory = CreateTempOutputDirectory();
            Assert.That(tempDirectory.Exists);

            var opts = new FromDirectoryOptions
            {
                InputFolderPath  = DynamoCoreDir,
                OutputFolderPath = tempDirectory.FullName,
                Filter           = new List <string> {
                    "FunctionObject.ds",
                    "BuiltIn.ds",
                },
                ReferencePaths = new List <string>()
            };

            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            var generatedFileNames = tempDirectory.GetFiles().Select(x => x.Name);

            //assert count is correct.
            Assert.AreEqual(10, generatedFileNames.Count());
            CollectionAssert.AreEquivalent(expectedFileNames, generatedFileNames);
        }
        public void ProducesCorrectOutputFromDirectory()
        {
            // Test output is generated with the following args:
            //
            // NodeDocumentationMarkdownGenerator.exe
            // fromdirectory
            // -i "..\Dynamo\bin\nodes"
            // -o "..\Dynamo\test\Tools\docGeneratorTestFiles\TestMdOutput_CoreNodeModels"
            // -f "CoreNodeModels.dll"

            // Arrange
            var testOutputDirName       = "TestMdOutput_CoreNodeModels";
            var expectedOutputDirectory = new DirectoryInfo(Path.Combine(toolsTestFilesDirectory, testOutputDirName));

            Assert.That(expectedOutputDirectory.Exists);

            var coreNodeModelsDll = Path.Combine(DynamoCoreNodesDir, CORENODEMODELS_DLL_NAME);

            Assert.That(File.Exists(coreNodeModelsDll));

            // Act
            tempDirectory = CreateTempOutputDirectory();
            Assert.That(tempDirectory.Exists);

            var opts = new FromDirectoryOptions
            {
                InputFolderPath  = DynamoCoreNodesDir,
                OutputFolderPath = tempDirectory.FullName,
                Filter           = new List <string> {
                    CORENODEMODELS_DLL_NAME
                },
                ReferencePaths = new List <string>()
            };

            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            var generatedFileNames = tempDirectory.GetFiles().Select(x => x.Name);

            // Assert file names are correct.
            CollectionAssert.AreEquivalent(expectedOutputDirectory.GetFiles().Select(x => x.Name), generatedFileNames);
        }
        public void DictionaryImagesAreCompressed()
        {
            // Arrange
            var testOutputDirName      = "TestMdOutput_CoreNodeModels";
            var sizesBeforeCompression = new DirectoryInfo(mockedDictionaryRoot).GetFiles("*.*", SearchOption.AllDirectories).Where(
                x => x.Extension.ToLower().Contains("gif") || x.Extension.ToLower().Contains("jpg")).OrderBy(x => x.FullName).Select(f => File.ReadAllBytes(f.FullName).Length).ToArray();

            var coreNodeModelsDll = Path.Combine(DynamoCoreNodesDir, CORENODEMODELS_DLL_NAME);

            Assert.That(File.Exists(coreNodeModelsDll));

            // Act
            tempDirectory = CreateTempOutputDirectory();
            Assert.That(tempDirectory.Exists);

            var opts = new FromDirectoryOptions
            {
                InputFolderPath     = DynamoCoreNodesDir,
                OutputFolderPath    = tempDirectory.FullName,
                DictionaryDirectory = mockedDictionaryJson,
                LayoutSpecPath      = testLayoutSpecPath,
                Filter = new List <string> {
                    CORENODEMODELS_DLL_NAME
                },
                ReferencePaths = new List <string>(),
                Overwrite      = true,
                CompressGifs   = true,
                CompressImages = true,
                Verbose        = true
            };

            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            var generatedFileImages = tempDirectory.GetFiles().Where(
                x => x.Extension.ToLower().Contains("gif") || x.Extension.ToLower().Contains("jpg")).OrderBy(x => x.FullName);
            var generatedFileSizes = generatedFileImages.Select(x => File.ReadAllBytes(x.FullName).Length);

            //check all files were larger before in bytes.
            Assert.IsTrue(generatedFileSizes.Select((x, i) => sizesBeforeCompression[i] >= x).All(x => x));
        }
        public void ReferencesFlagAddsReferencePaths()
        {
            // Arrange
            //using the dynamosamples package as a reference because it's not in the default bin paths.
            var packageName      = "Dynamo Samples";
            var packageDirectory = Path.GetFullPath(Path.Combine(toolsTestFilesDirectory, @"..\..\pkgs", packageName));;
            var opts             = new FromDirectoryOptions
            {
                InputFolderPath = DynamoCoreNodesDir,
                Filter          = new string[] { "doesnotexist.dll" },
                ReferencePaths  = new List <string> {
                    packageDirectory
                }
            };


            // Act
            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);


            // Assert
            Assert.IsTrue(Program.ReferenceAssemblyPaths.Select(x => new FileInfo(x).Name).Contains("SampleLibraryUI.dll"));
        }
        public void CanOverWriteExistingFiles()
        {
            // Arrange
            var originalOutDirName = "TestMdOutput_CoreNodeModels";
            var originalOutDir     = new DirectoryInfo(Path.Combine(toolsTestFilesDirectory, originalOutDirName));

            // Act
            tempDirectory = CreateTempOutputDirectory();
            Assert.That(tempDirectory.Exists);

            CopyFilesRecursively(originalOutDir, tempDirectory);

            var lastWriteTimeBefore = tempDirectory
                                      .GetFiles()
                                      .Select(x => x.LastWriteTime)
                                      .ToList();

            var opts = new FromDirectoryOptions
            {
                InputFolderPath  = DynamoCoreNodesDir,
                OutputFolderPath = tempDirectory.FullName,
                Filter           = new List <string> {
                    CORENODEMODELS_DLL_NAME
                },
                ReferencePaths = new List <string>(),
                Overwrite      = false
            };

            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            tempDirectory.Refresh();
            var lastWriteTimeAfterCommandWithoutOverwrite = tempDirectory
                                                            .GetFiles()
                                                            .Select(x => x.LastWriteTime)
                                                            .ToList();

            opts.Overwrite = true;
            FromDirectoryCommand.HandleDocumentationFromDirectory(opts);

            tempDirectory.Refresh();
            var lastWriteTimeAfterCommandWithOverwrite = tempDirectory
                                                         .GetFiles()
                                                         .Select(x => x.LastWriteTime)
                                                         .ToList();

            // Assert
            Assert.IsTrue(lastWriteTimeAfterCommandWithOverwrite.Count() == lastWriteTimeBefore.Count());

            // Compare last write times on original files
            // and new files without overwrite (-w)
            for (int i = 0; i < lastWriteTimeBefore.Count(); i++)
            {
                // as overwrite has not been specified here
                // it is expected that last write time will
                // be the same for all the files
                Assert.That(DateTime.Compare(lastWriteTimeBefore[i], lastWriteTimeAfterCommandWithoutOverwrite[i]) == 0);
            }

            // Compare last write times on original files
            // and new files with overwrite (-w)
            for (int i = 0; i < lastWriteTimeBefore.Count(); i++)
            {
                // if Compare returns less than 0 first element
                // is earlier then 2nd
                Assert.That(DateTime.Compare(lastWriteTimeBefore[i], lastWriteTimeAfterCommandWithOverwrite[i]) < 0);
            }

            CollectionAssert.AreEquivalent(
                originalOutDir.GetFiles().Select(x => x.Name),
                tempDirectory.GetFiles().Select(x => x.Name));
        }