#region Disclaimer / License // Copyright (C) 2012, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using OSGeo.MapGuide.MaestroAPI.Commands; using OSGeo.MapGuide.MaestroAPI.Feature; using System.Collections.Specialized; using OSGeo.MapGuide.MaestroAPI.Internal; namespace MaestroAPITests { [TestFixture(Ignore = TestControl.IgnoreGeoRestTests)] public class GeoRestTests { [Test] 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); } [Test] public void TestInsertNotAllowed() { var conn = ConnectionUtil.CreateTestHttpConnectionWithGeoRest(); var insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature); insert.ClassName = "SHP_Schema:Parcels"; var rec = new MutableRecord(); insert.FeatureSourceId = "Library://Samples/Sheboygan/Data/ParcelsNotAllowed.FeatureSource"; insert.RecordToInsert = rec; //This is not allowed var res = insert.Execute(); Assert.IsAssignableFrom(res.Error); } [Test] 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(res.Error); } [Test] public void TestInsertNonConfigured2() { var conn = ConnectionUtil.CreateTestHttpConnectionWithGeoRest(); var insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature); var rec = new MutableRecord(); insert.ClassName = "SHP_Schema:Foobar"; insert.FeatureSourceId = "Library://Samples/Sheboygan/Data/Parcels.FeatureSource"; insert.RecordToInsert = rec; //This is not configured var res = insert.Execute(); Assert.IsAssignableFrom(res.Error); } } }