예제 #1
0
        public void TestLoadNoNamespaceClass()
        {
            LibraryLoaded = false;

            string libraryPath = "FFITarget.dll";

            // All we need to do here is to ensure that the target has been loaded
            // at some point, so if it's already thre, don't try and reload it
            if (!libraryServices.IsLibraryLoaded(libraryPath))
            {
                libraryServices.ImportLibrary(libraryPath);
                Assert.IsTrue(LibraryLoaded);
            }

            // Get function groups for global classes with no namespace
            var functions = libraryServices.GetFunctionGroups(libraryPath)
                            .Where(x => x.Functions
                                   .Where(y => string.IsNullOrEmpty(y.Namespace)).Any());

            if (functions.Any())
            {
                var ctorfg = functions.Where(x => x.Functions.Where(y => y.Type == FunctionType.Constructor).Any());
                Assert.IsTrue(ctorfg.Any());
                foreach (var fg in ctorfg)
                {
                    foreach (var ctor in fg.Functions)
                    {
                        Assert.IsTrue(ctor.ClassName == ctor.UnqualifedClassName);
                    }
                }
            }
        }
예제 #2
0
        private IEnumerable <Dynamo.Engine.FunctionGroup> LoadLibraryIntoSearchViewModel(SearchViewModel searchViewModel, string libraryPath)
        {
            LibraryLoaded = false;

            // All we need to do here is to ensure that the target has been loaded
            // at some point, so if it's already here, don't try and reload it
            if (!libraryServices.IsLibraryLoaded(libraryPath))
            {
                libraryServices.ImportLibrary(libraryPath);
                Assert.IsTrue(LibraryLoaded);
            }

            var fgToCompare = libraryServices.GetFunctionGroups(libraryPath);

            foreach (var funcGroup in fgToCompare)
            {
                foreach (var functionDescriptor in funcGroup.Functions)
                {
                    if (functionDescriptor.IsVisibleInLibrary && !functionDescriptor.DisplayName.Contains("GetType"))
                    {
                        searchViewModel.Model.Add(new ZeroTouchSearchElement(functionDescriptor));
                    }
                }
            }

            return(fgToCompare);
        }
예제 #3
0
        public void TestLoadNoNamespaceClass()
        {
            LibraryServices libraryServices = LibraryServices.GetInstance();
            bool            libraryLoaded   = false;

            libraryServices.LibraryLoaded     += (sender, e) => libraryLoaded = true;
            libraryServices.LibraryLoadFailed += (sender, e) => Assert.Fail("Failed to load library: " + e.LibraryPath);

            string libraryPath = "FFITarget.dll";

            libraryServices.ImportLibrary(libraryPath, ViewModel.Model.Logger);
            Assert.IsTrue(libraryLoaded);

            // Get function groups for global classes with no namespace
            var functions = libraryServices.GetFunctionGroups(libraryPath)
                            .Where(x => x.Functions
                                   .Where(y => string.IsNullOrEmpty(y.Namespace)).Any());

            if (functions.Any())
            {
                var ctorfg = functions.Where(x => x.Functions.Where(y => y.Type == FunctionType.Constructor).Any());
                Assert.IsTrue(ctorfg.Any());
                foreach (var fg in ctorfg)
                {
                    foreach (var ctor in fg.Functions)
                    {
                        Assert.IsTrue(ctor.ClassName == ctor.UnqualifedClassName);
                    }
                }
            }
        }
예제 #4
0
        public void TestLoadDSFile()
        {
            LibraryLoaded = false;

            string libraryPath = Path.Combine(TestDirectory, @"core\library\Dummy.ds");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(LibraryLoaded);

            var functions = libraryServices.GetFunctionGroups(libraryPath);

            Assert.IsNotNull(functions);
            Assert.IsTrue(functions.Any());
        }
예제 #5
0
        public void TestLoadDSFile()
        {
            bool libraryLoaded = false;

            libraryServices.LibraryLoaded     += (sender, e) => libraryLoaded = true;
            libraryServices.LibraryLoadFailed += (sender, e) => Assert.Fail("Failed to load library: " + e.LibraryPath);

            string libraryPath = Path.Combine(GetTestDirectory(), @"core\library\Dummy.ds");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(libraryLoaded);

            var functions = libraryServices.GetFunctionGroups(libraryPath);

            Assert.IsNotNull(functions);
            Assert.IsTrue(functions.Any());
        }
예제 #6
0
        public void TestLoadLibrary()
        {
            LibraryServices libraryServices = LibraryServices.GetInstance();
            bool            libraryLoaded   = false;

            libraryServices.LibraryLoaded     += (sender, e) => libraryLoaded = true;
            libraryServices.LibraryLoadFailed += (sender, e) => Assert.Fail("Failed to load library: " + e.LibraryPath);

            string libraryPath = Path.Combine(GetTestDirectory(), @"core\library\MultiReturnTest.dll");

            libraryServices.ImportLibrary(libraryPath);
            Assert.IsTrue(libraryLoaded);

            var functions = libraryServices.GetFunctionGroups(libraryPath);

            Assert.IsNotNull(functions);
            Assert.IsTrue(functions.Any());
        }
예제 #7
0
        public void DumpLibraryToXmlZeroTouchTest()
        {
            var searchViewModel = new SearchViewModel(new NodeSearchModel());

            LibraryLoaded = false;

            string libraryPath = "DSOffice.dll";

            // All we need to do here is to ensure that the target has been loaded
            // at some point, so if it's already here, don't try and reload it
            if (!libraryServices.IsLibraryLoaded(libraryPath))
            {
                libraryServices.ImportLibrary(libraryPath);
                Assert.IsTrue(LibraryLoaded);
            }

            var fgToCompare = libraryServices.GetFunctionGroups(libraryPath);

            foreach (var funcGroup in fgToCompare)
            {
                foreach (var functionDescriptor in funcGroup.Functions)
                {
                    if (functionDescriptor.IsVisibleInLibrary && !functionDescriptor.DisplayName.Contains("GetType"))
                    {
                        searchViewModel.Model.Add(new ZeroTouchSearchElement(functionDescriptor));
                    }
                }
            }

            var document = searchViewModel.Model.ComposeXmlForLibrary(ExecutingDirectory);

            Assert.AreEqual("LibraryTree", document.DocumentElement.Name);

            XmlNode node, subNode;

            foreach (var functionGroup in fgToCompare)
            {
                foreach (var function in functionGroup.Functions)
                {
                    // Obsolete, not visible and "GetType" functions are not presented in UI tree.
                    // So they are should not be presented in dump.
                    if (function.IsObsolete || !function.IsVisibleInLibrary || function.FunctionName.Contains("GetType"))
                    {
                        continue;
                    }

                    var category = function.Category;
                    var group    = SearchElementGroup.Action;
                    category = searchViewModel.Model.ProcessNodeCategory(category, ref group);

                    node = document.SelectSingleNode(string.Format(
                                                         "//{0}[FullCategoryName='{1}' and Name='{2}']",
                                                         typeof(ZeroTouchSearchElement).FullName, category, function.FunctionName));
                    Assert.IsNotNull(node);

                    subNode = node.SelectSingleNode("Group");
                    Assert.IsNotNull(subNode.FirstChild);
                    Assert.AreEqual(group.ToString(), subNode.FirstChild.Value);

                    // 'FullCategoryName' is already checked.
                    // 'Name' is already checked.

                    subNode = node.SelectSingleNode("Description");
                    Assert.IsNotNull(subNode.FirstChild);

                    // No check Description on text equality because for some reason
                    // function.Descriptions are different in real executing Dynamo and
                    // Dynamo started from tests.
                    //
                    // For example:
                    // tests  function.Description: Excel.ReadFromFile (file: FileInfo, sheetName: string): var[][]
                    // normal function.Description: Excel.ReadFromFile (file: var, sheetName: string): var[][]
                }
            }
        }