Exemple #1
0
        public void CanReplaceEncryptedPasswordNotAtEndOfConnectionString()
        {
            const string connectionString = "Blah=Blah;ENCRYPTED_PASSWORD=abc;Bla=Bla";

            Assert.AreEqual("Blah=Blah;ENCRYPTED_PASSWORD=****;Bla=Bla",
                            WorkspaceUtils.ReplacePassword(connectionString, "****"));
        }
Exemple #2
0
        public void CanReplacePasswordAtWithoutPassword()
        {
            const string connectionString = "Blah=Blah;Bla=Bla";

            Assert.AreEqual(connectionString,
                            WorkspaceUtils.ReplacePassword(connectionString, "****"));
        }
Exemple #3
0
        public void CanReplacePasswordInvalidConnectionString()
        {
            const string connectionString = "Blah=Blah;Password";

            Assert.AreEqual(connectionString,
                            WorkspaceUtils.ReplacePassword(connectionString, "****"));
        }
Exemple #4
0
        public void CanReplacePasswordAtEndOfConnectionString()
        {
            const string connectionString = "Blah=Blah;Password=abc";

            Assert.AreEqual("Blah=Blah;Password=****",
                            WorkspaceUtils.ReplacePassword(connectionString, "****"));
        }
Exemple #5
0
        public void CanReplaceEmptyPassword()
        {
            const string connectionString = "Blah=Blah;Password=;";

            Assert.AreEqual("Blah=Blah;Password=****;",
                            WorkspaceUtils.ReplacePassword(connectionString, "****"));
        }
Exemple #6
0
        public void CanGetUnqualifiedVersionName()
        {
            string name =
                WorkspaceUtils.GetUnqualifiedVersionName(@"""ESRI-DE\USERNAME"".MyVersion");

            Assert.AreEqual("MyVersion", name);
        }
Exemple #7
0
        public void CanReplacePasswordNotAtEndOfConnectionStringWithBlanks()
        {
            const string connectionString = "Blah = Blah ; Password = abc ; Bla = Bla";

            Assert.AreEqual("Blah = Blah ; Password =****; Bla = Bla",
                            WorkspaceUtils.ReplacePassword(connectionString, "****"));
        }
Exemple #8
0
        public async Task When_Building_From_Subject()
        {
            using (var workspace = WorkspaceUtils.GetSubjectSolution())
            {
                var project     = workspace.CurrentSolution.Projects.Single(p => p.Name == "SubjectSolution");
                var compilation = await project.GetCompilationAsync();

                var someClassTree = compilation.SyntaxTrees.Single(t => Path.GetFileName(t.FilePath) == "SomeClass.cs");
                var rootNode      = await someClassTree.GetRootAsync();

                var model = compilation.GetSemanticModel(someClassTree);

                var classSymbol = rootNode.GetAllDeclaredTypes(model).First();
                Assert.AreEqual("SomeClass", classSymbol.Name);

                var graph = await NodeGraph.BuildGraph(CompilationCache.CacheWithSolution(workspace.CurrentSolution), ct : default);

                var root = graph.GetNodeForType(classSymbol);
                Assert.AreEqual(classSymbol.ToIdentifier(), root.Identifier);
                Assert.AreEqual(4, root.ForwardLinks.Count);
                AssertEx.Contains(root.ForwardLinkNodes, n => (n as TypeNode)?.Identifier.Name == "SomeEnumeratedClass");
                AssertEx.Contains(root.ForwardLinkNodes, n => (n as TypeNode)?.Identifier.Name == "SomeClassCore");
                var someOtherClassNode = AssertEx.Contains(root.ForwardLinkNodes, n => (n as TypeNode)?.Identifier.Name == "SomeOtherClass") as TypeNode;

                CollectionAssert.Contains(someOtherClassNode.BackLinkNodes, root);
                AssertEx.Contains(someOtherClassNode.BackLinkNodes, n => (n as TypeNode)?.Identifier.Name == "SomeCircularClass");
                AssertEx.Contains(someOtherClassNode.ForwardLinkNodes, n => (n as TypeNode)?.Identifier.Name == "SomeClassInArray");
                AssertEx.Contains(someOtherClassNode.ForwardLinkNodes, n => (n as TypeNode)?.Identifier.Name == "SomeDeeperClass");

                AssertConsistentState(graph);
            }
        }
Exemple #9
0
        public static string GetDateLiteral(DateTime dateTime,
                                            [NotNull] IWorkspace workspace)
        {
            Assert.ArgumentNotNull(workspace, nameof(workspace));

            switch (workspace.Type)
            {
            case esriWorkspaceType.esriLocalDatabaseWorkspace:
                if (WorkspaceUtils.IsFileGeodatabase(workspace))
                {
                    return(GetFGDBDateLiteral(dateTime));
                }

                if (WorkspaceUtils.IsPersonalGeodatabase(workspace))
                {
                    return(GetPGDBDateLiteral(dateTime));
                }

                throw new ArgumentOutOfRangeException(
                          string.Format("Unsupported local database workspace type: {0}",
                                        workspace.PathName));

            case esriWorkspaceType.esriRemoteDatabaseWorkspace:
                var connectionInfo = (IDatabaseConnectionInfo2)workspace;
                return(GetDateLiteral(dateTime, connectionInfo.ConnectionDBMS));

            default:
                throw new ArgumentOutOfRangeException(
                          string.Format("Unsupported workspace type: {0}", workspace.Type));
            }
        }
        public async Task When_Two_Roots()
        {
            using (var workspace = WorkspaceUtils.GetSubjectSolution())
            {
                var project = workspace.CurrentSolution.Projects.Single(p => p.Name == "SubjectSolution");

                var graph = await NodeGraph.BuildGraph(CompilationCache.CacheWithSolution(workspace.CurrentSolution), ct : default);

                var someClassNode         = graph.Nodes[TypeNodeKey.GetFromFullName("SubjectSolution.SomeClass")];
                var someCircularClassNode = graph.Nodes[TypeNodeKey.GetFromFullName("SubjectSolution.SomeCircularClass")];

                var roots = new HashSet <Node>();
                roots.Add(someClassNode);
                roots.Add(someCircularClassNode);

                var paths = NodeGraphExtensions.GetMultiDependencyRootPaths(graph, roots).ToArray();
                var path  = paths.Single();

                Assert.AreEqual(someClassNode, path.Source);
                Assert.AreEqual(someCircularClassNode, path.Target);
                Assert.AreEqual(2, path.Intermediates.Count);
                Assert.AreEqual("SomeOtherClass", (path.Intermediates[0] as TypeNode).Identifier.Name);
                Assert.AreEqual("SomeDeeperClass", (path.Intermediates[1] as TypeNode).Identifier.Name);
            }
        }
Exemple #11
0
        public async Task When_Root_With_BackLinks()
        {
            using (var workspace = WorkspaceUtils.GetSubjectSolution())
            {
                var project     = workspace.CurrentSolution.Projects.Single(p => p.Name == "SubjectSolution");
                var compilation = await project.GetCompilationAsync();

                var someClassTree = compilation.SyntaxTrees.Single(t => Path.GetFileName(t.FilePath) == "SomeOtherClass.cs");
                var rootNode      = await someClassTree.GetRootAsync();

                var model = compilation.GetSemanticModel(someClassTree);

                var classSymbol = rootNode.GetAllDeclaredTypes(model).First();
                Assert.AreEqual("SomeOtherClass", classSymbol.Name);

                var graph = await NodeGraph.BuildGraph(CompilationCache.CacheWithSolution(workspace.CurrentSolution), ct : default);

                var root = graph.GetNodeForType(classSymbol);
                Assert.AreEqual(classSymbol.ToIdentifier(), root.Identifier);

                Assert.AreEqual(3, root.ForwardLinks.Count);
                Assert.AreEqual(2, root.BackLinks.Count);

                AssertConsistentState(graph);
            }
        }
Exemple #12
0
        private static IList <QaError> GetErrors([NotNull] string tableName,
                                                 int maximumLength)
        {
            var    locator = TestDataUtils.GetTestDataLocator();
            string path    = locator.GetPath("QaSchemaTests.mdb");

            IFeatureWorkspace workspace = WorkspaceUtils.OpenPgdbFeatureWorkspace(path);

            const int  minimumValueCount             = 1;
            const int  minimumNonEqualNameValueCount = 1;
            const bool allowEmptyName = false;

            ITable table = workspace.OpenTable(tableName);
            var    test  = new QaSchemaFieldDomainCodedValues(table, maximumLength,
                                                              UniqueStringsConstraint.UniqueAnyCase,
                                                              minimumValueCount,
                                                              minimumNonEqualNameValueCount,
                                                              allowEmptyName);

            var runner = new QaTestRunner(test);

            runner.Execute();

            return(runner.Errors);
        }
Exemple #13
0
        public async Task When_Implemented_Interface()
        {
            using (var workspace = WorkspaceUtils.GetSubjectSolution())
            {
                var fullGraph = await NodeGraph.BuildGraph(CompilationCache.CacheWithSolution(workspace.CurrentSolution), ct : default);

                var implementingClassNode = fullGraph.Nodes.Values.Single(n => (n as TypeNode)?.Identifier.Name == "SomeBaseClass");
                AssertImplements(implementingClassNode, "ISomeInheritedInterface");
                AssertImplements(implementingClassNode, "ISomeStillOtherInterface");
                AssertImplements(implementingClassNode, "ISomeGenericInterface<T>");

                void AssertImplements(Node implementer, string interfaceName)
                {
                    var interfaceLink = AssertEx.ContainsSingle(implementer.ForwardLinks, l => (l.Dependency as TypeNode)?.Identifier.Name == interfaceName);

                    Assert.AreEqual(LinkType.ImplementsInterface, interfaceLink.LinkType);
                }

                ;
                //var baseClassLink = AssertEx.ContainsSingle(inheritedClassNode.ForwardLinks, l => (l.Dependency as TypeNode)?.Identifier.Name == "SomeBaseClass");
                //Assert.AreEqual(LinkType.InheritsFromClass, baseClassLink.LinkType);
                //var derivedClassLink = AssertEx.ContainsSingle(inheritedClassNode.BackLinks, l => (l.Dependent as TypeNode)?.Identifier.Name == "SomeInheritedClassDepth2");
                //Assert.AreEqual(LinkType.InheritsFromClass, baseClassLink.LinkType);
            }
        }
Exemple #14
0
        public void LearningTestSQLSyntaxPGDB()
        {
            IWorkspace workspace =
                WorkspaceUtils.OpenPgdbWorkspace(TestData.GetGdb1Path());

            LogSqlSyntax(workspace);
        }
Exemple #15
0
        private static IDictionary <AttributeRole, string> GetFieldNames(
            [NotNull] IFeatureWorkspace featureWorkspace)
        {
            var workspace = (IWorkspace)featureWorkspace;

            if (WorkspaceUtils.IsFileGeodatabase(workspace))
            {
                return(new Dictionary <AttributeRole, string>
                {
                    { AttributeRole.Description, "Description" },
                    { AttributeRole.FeatureSource, "DataSource" },
                    { AttributeRole.WhereClause, "WhereClause" },
                    { AttributeRole.BufferDistance, "BufferDistance" },
                    { AttributeRole.GeneralizationTolerance, "GeneralizationTolerance" }
                });
            }

            if (WorkspaceUtils.IsShapefileWorkspace(workspace))
            {
                return(new Dictionary <AttributeRole, string>
                {
                    { AttributeRole.Description, "Descript" },
                    { AttributeRole.FeatureSource, "DataSource" },
                    { AttributeRole.WhereClause, "Where" },
                    { AttributeRole.BufferDistance, "BufferDist" },
                    { AttributeRole.GeneralizationTolerance, "GeneralTol" }
                });
            }

            throw new ArgumentException(
                      string.Format(
                          "Unsupported workspace for writing area of interest feature class: {0}",
                          WorkspaceUtils.GetConnectionString(workspace, true)));
        }
Exemple #16
0
        public void CanHandleZeroLengthEndSegments()
        {
            const string featureClassName = "TLM_STEHENDES_GEWAESSER";

            var    locator = TestDataUtils.GetTestDataLocator();
            string path    = locator.GetPath("QaBorderSense.gdb");

            IFeatureWorkspace workspace = WorkspaceUtils.OpenFileGdbFeatureWorkspace(path);

            IFeatureClass featureClass = workspace.OpenFeatureClass(featureClassName);

            // expect counter-clockwise: 0 errors
            var runnerCounterClockwise = new QaContainerTestRunner(1000,
                                                                   new QaBorderSense(
                                                                       featureClass, false));

            Assert.AreEqual(0, runnerCounterClockwise.Execute());

            // expect clockwise: 1 error
            var runnerClockwise = new QaContainerTestRunner(1000,
                                                            new QaBorderSense(featureClass,
                                                                              true));

            Assert.AreEqual(1, runnerClockwise.Execute());
        }
        public static IEnumerable <IObjectClass> GetIssueObjectClasses(
            [NotNull] IFeatureWorkspace issueRepositoryWorkspace)
        {
            Assert.ArgumentNotNull(issueRepositoryWorkspace, nameof(issueRepositoryWorkspace));

            foreach (string objectClassName in IssueDatasetUtils.ObjectClassNames)
            {
                IObjectClass objectClass;
                try
                {
                    objectClass = DatasetUtils.OpenObjectClass(issueRepositoryWorkspace,
                                                               objectClassName);
                }
                catch (COMException e)
                {
                    _msg.DebugFormat("Unable to open object class {0} from {1}: {2}",
                                     objectClassName,
                                     WorkspaceUtils.GetWorkspaceDisplayText(
                                         (IWorkspace)issueRepositoryWorkspace),
                                     e.Message);
                    continue;
                }

                yield return(objectClass);
            }
        }
Exemple #18
0
        public void CanOpenFromConnectionString()
        {
            string catalogPath = GetWorkspaceCatalogPath();

            IWorkspace workspace;

            try
            {
                workspace = WorkspaceUtils.OpenPgdbWorkspace(catalogPath);
            }
            catch (Exception)
            {
                // TODO: Move test data to different format
                if (EnvironmentUtils.Is64BitProcess)
                {
                    Console.WriteLine("Expected exception: PGDB is not supported on x64");
                    return;
                }

                throw;
            }

            string connectionString = WorkspaceUtils.GetConnectionString(workspace);

            var dataSource = new DataSource("test", "test")
            {
                WorkspaceAsText = connectionString
            };

            IWorkspace openedWorkspace = dataSource.OpenWorkspace();

            Assert.IsNotNull(openedWorkspace);
            Assert.AreEqual(workspace, openedWorkspace);
        }
Exemple #19
0
        public static IWorkspace OpenOsaWorkspaceOracle([NotNull] string repositoryName = "SDE")
        {
            IWorkspace workspace = WorkspaceUtils.OpenSDEWorkspace(
                repositoryName, DirectConnectDriver.Oracle11g, OracleDbNameSde);

            return(workspace);
        }
Exemple #20
0
        public static IWorkspace OpenPgdb(string testDataPath)
        {
            string     fullPath = GetFullPath(testDataPath);
            IWorkspace ws       = WorkspaceUtils.OpenPgdbWorkspace(fullPath);

            return(ws);
        }
Exemple #21
0
        public async Task When_MultiDependency_Edge()
        {
            using (var workspace = WorkspaceUtils.GetSubjectSolution())
            {
                var project = workspace.CurrentSolution.Projects.Single(p => p.Name == "SubjectSolution");

                var graph = await NodeGraph.BuildGraph(CompilationCache.CacheWithSolution(workspace.CurrentSolution), ct : default);

                var someClassNode = graph.Nodes[TypeNodeKey.GetFromFullName("SubjectSolution.SomeClass")];
                var deepClassNode = graph.Nodes[TypeNodeKey.GetFromFullName("SubjectSolution.SomeClassDepth5")];

                var roots = new HashSet <Node>();
                roots.Add(someClassNode);
                roots.Add(deepClassNode);

                var paths = NodeGraphExtensions.GetMultiDependencyRootPaths(graph, roots).ToArray();
                var path  = paths.Single();

                var displayGraph = graph.GetDisplaySubgraph(subgraphNodes: roots, pinnedNodes: SetUtils.GetEmpty <NodeKey>());

                var multiEdges = displayGraph.Edges.OfType <MultiDependencyDisplayEdge>();

                AssertEx.ContainsSingle(multiEdges, m => m.Source.DisplayString.EndsWith("SomeClass") && m.Target.DisplayString.EndsWith("SomeClassDepth5"));
            }
        }
Exemple #22
0
        public void LearningTestSQLSyntaxFGDB()
        {
            IWorkspace workspace =
                WorkspaceUtils.OpenFileGdbWorkspace(TestData.GetGdbTableJointUtilsPath());

            LogSqlSyntax(workspace);
        }
Exemple #23
0
        public async Task When_Display_Graph_Two_Roots_No_Extension()
        {
            using (var workspace = WorkspaceUtils.GetSubjectSolution())
            {
                var project     = workspace.CurrentSolution.Projects.Single(p => p.Name == "SubjectSolution");
                var compilation = await project.GetCompilationAsync();

                var someClassTree         = compilation.SyntaxTrees.Single(t => Path.GetFileName(t.FilePath) == "SomeClass.cs");
                var someCircularClassTree = compilation.SyntaxTrees.Single(t => Path.GetFileName(t.FilePath) == "SomeCircularClass.cs");

                var roots =
                    new[] {
                    (await someClassTree.GetRootAsync()).GetAllDeclaredTypes(compilation.GetSemanticModel(someClassTree)).First(),
                    (await someCircularClassTree.GetRootAsync()).GetAllDeclaredTypes(compilation.GetSemanticModel(someCircularClassTree)).First()
                };


                var fullGraph = await NodeGraph.BuildGraph(CompilationCache.CacheWithSolution(workspace.CurrentSolution),
                                                           ct : default);

                var displayGraph = fullGraph.GetDisplaySubgraph(roots);
                Assert.AreEqual(2, displayGraph.VertexCount);
                var simpleEdges = displayGraph.Edges.OfType <SimpleDisplayEdge>().ToArray();
                var multiEdges  = displayGraph.Edges.OfType <MultiDependencyDisplayEdge>().ToArray();
                Assert.AreEqual(0, simpleEdges.Length);
                Assert.AreEqual(1, multiEdges.Length);
            }
        }
Exemple #24
0
        private static IIssueTableFields GetTargetFields(
            [NotNull] ICollection <IObjectClass> targetExceptionClasses,
            bool ensureRequiredFields = true)
        {
            IWorkspace workspace =
                Assert.NotNull(DatasetUtils.GetUniqueWorkspace(targetExceptionClasses));

            IIssueTableFieldManagement fields =
                IssueTableFieldsFactory.GetIssueTableFields(
                    addExceptionFields: true,
                    useDbfFieldNames: WorkspaceUtils.IsShapefileWorkspace(workspace),
                    addManagedExceptionFields: true);

            if (ensureRequiredFields)
            {
                using (_msg.IncrementIndentation("Ensuring required target fields"))
                {
                    int addedFields = EnsureTargetFields(targetExceptionClasses, fields);

                    if (addedFields == 0)
                    {
                        _msg.Info("All required fields exist in target datasets");
                    }
                }
            }

            return(fields);
        }
        public void CanSortByStringField()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");

            const string operatorFieldName = "OPERATEUR";
            ICursor      cursor            = TableSortUtils.GetSortedTableCursor(table, operatorFieldName);

            int fieldIndex = cursor.FindField(operatorFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            string lastValue = null;
            IRow   row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty field");

                var currentValue = (string)value;
                Console.WriteLine(currentValue);

                if (lastValue != null)
                {
                    Assert.False(currentValue.CompareTo(lastValue) < 0, "Not sorted");
                }

                lastValue = currentValue;
            }
        }
        public void TableSortOnFgdbGuidsPerformance()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());
            //IFeatureWorkspace featureWs = OpenTestWorkspace();

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");
            //ITable table = DatasetUtils.OpenTable(featureWs, "TOPGIS_TLM.TLM_NUTZUNGSAREAL");

            const string uuidFieldName = "UUID";

            var watch = new Stopwatch();

            watch.Start();

            ICursor cursor = TableSortUtils.GetSortedTableCursor(table, uuidFieldName);

            LoopAndWrite(cursor, uuidFieldName);

            watch.Stop();
            long standardSort = watch.ElapsedMilliseconds;

            //featureWs = OpenTestWorkspace();
            //table = DatasetUtils.OpenTable(featureWs, "TOPGIS_TLM.TLM_NUTZUNGSAREAL");

            watch = new Stopwatch();
            watch.Start();

            cursor = TableSortUtils.GetGuidFieldSortedCursor(table, uuidFieldName);
            LoopAndWrite(cursor, uuidFieldName);

            watch.Stop();
            Console.WriteLine(@"Standard Sorter: {0}", standardSort);
            Console.WriteLine(@"Guid Sorter: {0}", watch.ElapsedMilliseconds);
        }
Exemple #27
0
        public static IWorkspace OpenDDxWorkspaceOracle()
        {
            IWorkspace workspace = WorkspaceUtils.OpenSDEWorkspace(
                "SDE", DirectConnectDriver.Oracle11g, OracleDbNameDdx,
                "unittest", "unittest");

            return(workspace);
        }
Exemple #28
0
        public static IWorkspace OpenSDEWorkspaceOracle()
        {
            IWorkspace workspace = WorkspaceUtils.OpenSDEWorkspace(
                "SDE", DirectConnectDriver.Oracle11g, OracleDbNameSde,
                "sde", "sde");

            return(workspace);
        }
Exemple #29
0
        public void CanGetWorkspaceDisplayTextForOracle()
        {
            IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle();

            string text = WorkspaceUtils.GetWorkspaceDisplayText(workspace);

            Console.WriteLine(text);
        }
        public void TestGetCodedValues()
        {
            IWorkspace workspace = WorkspaceUtils.OpenPgdbWorkspace(_simpleGdbPath);
            SortedDictionary <int, string> list = DomainUtils.GetCodedValueMap <int>(
                workspace, "TestCodedValueDomain");

            Assert.AreEqual(5, list.Count);
            Assert.AreEqual("Value7", list[7]);
        }