public void TestCase1914()
        {
            var conn = ConnectionUtil.CreateTestLocalNativeConnection();
            var sw   = new Stopwatch();

            sw.Start();
            conn.ResourceService.ResourceExists("Library://UnitTests/Data/Parcels.FeatureSource");
            sw.Stop();
            Trace.TraceInformation("ResourceExists() executed in {0}ms", sw.ElapsedMilliseconds);
        }
        protected void TestClassDefinitionCaching(string fsName)
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var    conn = ConnectionUtil.CreateTestHttpConnection();
            string fsId = "Library://UnitTests/" + fsName + ".FeatureSource";

            if (!conn.ResourceService.ResourceExists(fsId))
            {
                var fs = ObjectFactory.CreateFeatureSource("OSGeo.SDF");
                fs.SetConnectionProperty("File", "%MG_DATA_FILE_PATH%Sheboygan_Parcels.sdf");
                conn.ResourceService.SaveResourceAs(fs, fsId);
                fs.ResourceID = fsId;
                using (var stream = File.OpenRead("TestData/FeatureService/SDF/Sheboygan_Parcels.sdf"))
                {
                    conn.ResourceService.SetResourceData(fs.ResourceID, "Sheboygan_Parcels.sdf", ResourceDataType.File, stream);
                }
                var res = conn.FeatureService.TestConnection(fsId);
                Assert.True(Convert.ToBoolean(res));
            }
            var pc = (PlatformConnectionBase)conn;

            pc.ResetFeatureSourceSchemaCache();

            var stats = pc.CacheStats;

            Assert.Equal(0, stats.ClassDefinitions);
            Assert.Equal(0, stats.FeatureSources);

            var cls = conn.FeatureService.GetClassDefinition(fsId, "SHP_Schema:Parcels");

            stats = pc.CacheStats;
            Assert.Equal(1, stats.ClassDefinitions);
            Assert.Equal(0, stats.FeatureSources);

            var cls2 = conn.FeatureService.GetClassDefinition(fsId, "SHP_Schema:Parcels");

            stats = pc.CacheStats;
            Assert.Equal(1, stats.ClassDefinitions);
            Assert.Equal(0, stats.FeatureSources);
            //Each cached instance returned is a clone
            Assert.False(object.ReferenceEquals(cls, cls2));
        }
        public virtual void TestEncryptedFeatureSourceCredentials()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            //Sensitive data redacted, nevertheless you can test and verify this by filling in the
            //blanks here and uncommenting the above [Fact] attribute. If the test passes, credential encryption is working
            string server     = "";
            string database   = "";
            string actualUser = "";
            string actualPass = "";
            string bogusUser  = "******";
            string bogusPass  = "******";

            var    conn = ConnectionUtil.CreateTestHttpConnection();
            string fsId = "Library://UnitTests/" + GetTestPrefix() + "EncryptedCredentials.FeatureSource";
            var    fs   = ObjectFactory.CreateFeatureSource("OSGeo.SQLServerSpatial");

            fs.SetConnectionProperty("Username", "%MG_USERNAME%");
            fs.SetConnectionProperty("Password", "%MG_PASSWORD%");
            fs.SetConnectionProperty("Service", server);
            fs.SetConnectionProperty("DataStore", database);
            fs.ResourceID = fsId;
            conn.ResourceService.SaveResource(fs);

            fs.SetEncryptedCredentials(conn, actualUser, actualPass);

            string result = conn.FeatureService.TestConnection(fsId);

            Assert.Equal("TRUE", result.ToUpper());

            //Test convenience method
            fsId = "Library://UnitTests/" + GetTestPrefix() + "EncryptedCredentials2.FeatureSource";
            fs   = ObjectFactory.CreateFeatureSource("OSGeo.SQLServerSpatial");
            fs.SetConnectionProperty("Username", "%MG_USERNAME%");
            fs.SetConnectionProperty("Password", "%MG_PASSWORD%");
            fs.SetConnectionProperty("Service", server);
            fs.SetConnectionProperty("DataStore", database);
            fs.ResourceID = fsId;
            conn.ResourceService.SaveResource(fs);
            fs.SetEncryptedCredentials(conn, actualUser, actualPass);

            result = conn.FeatureService.TestConnection(fsId);
            Assert.Equal("TRUE", result.ToUpper());
            Assert.Equal(actualUser, fs.GetEncryptedUsername(conn));

            //Do not set encrypted credentials
            fsId = "Library://UnitTests/" + GetTestPrefix() + "EncryptedCredentials3.FeatureSource";
            fs   = ObjectFactory.CreateFeatureSource("OSGeo.SQLServerSpatial");
            fs.SetConnectionProperty("Username", "%MG_USERNAME%");
            fs.SetConnectionProperty("Password", "%MG_PASSWORD%");
            fs.SetConnectionProperty("Service", server);
            fs.SetConnectionProperty("DataStore", database);
            fs.ResourceID = fsId;
            conn.ResourceService.SaveResource(fs);

            try
            {
                result = conn.FeatureService.TestConnection(fsId);
                Assert.Equal("FALSE", result.ToUpper());
            }
            catch //Exception or false I can't remember, as long as the result is not "true"
            {
            }

            //Encrypt credentials, but use bogus username/password
            fsId = "Library://UnitTests/" + GetTestPrefix() + "EncryptedCredentials4.FeatureSource";
            fs   = ObjectFactory.CreateFeatureSource("OSGeo.SQLServerSpatial");
            fs.SetConnectionProperty("Username", "%MG_USERNAME%");
            fs.SetConnectionProperty("Password", "%MG_PASSWORD%");
            fs.SetConnectionProperty("Service", server);
            fs.SetConnectionProperty("DataStore", database);
            fs.ResourceID = fsId;
            conn.ResourceService.SaveResource(fs);
            fs.SetEncryptedCredentials(conn, bogusUser, bogusPass);

            try
            {
                result = conn.FeatureService.TestConnection(fsId);
                Assert.Equal("FALSE", result.ToUpper());
            }
            catch
            {
                //Exception or false I can't remember, as long as the result is not "true"
            }
            Assert.Equal(bogusUser, fs.GetEncryptedUsername(conn));
        }
Ejemplo n.º 4
0
 private IServerConnection CreateTestConnection()
 {
     return(ConnectionUtil.CreateTestHttpConnection());
 }
Ejemplo n.º 5
0
 public override IServerConnection CreateTestConnection()
 {
     return(ConnectionUtil.CreateTestLocalConnection());
 }
Ejemplo n.º 6
0
 protected override IServerConnection CreateTestConnection()
 {
     return(ConnectionUtil.CreateTestHttpConnection());
 }
Ejemplo n.º 7
0
 protected override IServerConnection CreateTestConnection()
 {
     return(ConnectionUtil.CreateTestLocalNativeConnection());
 }