Example #1
0
        public void TestInsert()
        {
            var conn = ConnectionUtil.CreateTestHttpConnectionWithGeoRest();
            var insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);
            insert.ClassName = "SHP_Schema:Parcels";

            var rec = new MutableRecord();
            insert.RecordToInsert = rec;
            insert.FeatureSourceId = "Library://Samples/Sheboygan/Data/Parcels.FeatureSource";
            var dr = conn.FeatureService.AggregateQueryFeatureSource(
                insert.FeatureSourceId,
                "SHP_Schema:Parcels",
                null,
                new NameValueCollection()
                {
                    { "TOTAL", "COUNT(Autogenerated_SDF_ID)" }
                });

            long lBefore = 0L;
            if (dr.ReadNext())
            {
                lBefore = dr.GetInt64("TOTAL");
            }
            dr.Close();

            var wktReader = new FixedWKTReader();

            rec.PutValue("RNAME", new StringValue("Hello World"));
            rec.PutValue("Geometry", new GeometryValue(wktReader.Read("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))")));

            var res = insert.Execute();
            Assert.Null(res.Error);

            long lAfter = lBefore;
            dr = conn.FeatureService.AggregateQueryFeatureSource(
                insert.FeatureSourceId,
                "SHP_Schema:Parcels",
                null,
                new NameValueCollection()
                {
                    { "TOTAL", "COUNT(Autogenerated_SDF_ID)" }
                });
            if (dr.ReadNext())
                lAfter = dr.GetInt64("TOTAL");
            dr.Close();

            Assert.AreEqual(lBefore + 1L, lAfter);
        }
Example #2
0
        public void TestInsertNonConfigured()
        {
            var conn = ConnectionUtil.CreateTestHttpConnectionWithGeoRest();
            var insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);

            var rec = new MutableRecord();
            insert.ClassName = "SHP_Schema:Rail";
            insert.FeatureSourceId = "Library://Samples/Sheboygan/Data/Rail.FeatureSource";
            insert.RecordToInsert = rec;

            //This is not configured
            var res = insert.Execute();
            Assert.IsAssignableFrom<InvalidOperationException>(res.Error);
        }
Example #3
0
        protected void PopulateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);
            insert.ClassName = cls.Name;
            insert.FeatureSourceId = fsId;
            var feat = new MutableRecord();

            var reader = new FixedWKTReader();

            //Initialize this record
            feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)")));
            feat.PutValue("NAME", new StringValue("Test1"));

            //Attach to command.
            insert.RecordToInsert = feat;

            var res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (0 1)"));
            feat.SetString("NAME", "Test2");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 1)"));
            feat.SetString("NAME", "Test3");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 0)"));
            feat.SetString("NAME", "Test4");

            res = insert.Execute();
        }
Example #4
0
        public virtual void TestInsertFeatures()
        {
            var conn = CreateTestConnection();
            var fsId = "Library://UnitTests/Data/Test" + GetTestPrefix() + "InsertFeatures.FeatureSource";
            ClassDefinition cls = null;
            FeatureSchema schema = null;
            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);
            insert.ClassName = cls.Name;
            insert.FeatureSourceId = fsId;
            var feat = new MutableRecord();

            var reader = new FixedWKTReader();

            //Initialize this record
            feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)")));
            feat.PutValue("NAME", new StringValue("Test1"));

            Assert.True(feat.PropertyExists("GEOM"));
            Assert.True(feat.PropertyExists("NAME"));

            //Attach to command.
            insert.RecordToInsert = feat;

            var res = insert.Execute();
            Assert.Null(res.Error);

            feat.SetGeometry("GEOM", reader.Read("POINT (0 1)"));
            feat.SetString("NAME", "Test2");

            res = insert.Execute();
            Assert.Null(res.Error);

            feat.SetGeometry("GEOM", reader.Read("POINT (1 1)"));
            feat.SetString("NAME", "Test3");

            res = insert.Execute();
            Assert.Null(res.Error);

            feat.SetGeometry("GEOM", reader.Read("POINT (1 0)"));
            feat.SetString("NAME", "Test4");

            res = insert.Execute();
            Assert.Null(res.Error);

            int count = 0;
            using (var rdr = conn.FeatureService.QueryFeatureSource(fsId, cls.Name))
            {
                while (rdr.ReadNext())
                {
                    count++;
                }
                rdr.Close();
            }

            Assert.AreEqual(4, count);
        }