public void CanProperlyCreateCommandLineOptionsForOgr2OgrUsingGeoJSON()
        {
            AssertCustom.IgnoreOnBuildServer();

            // Arrange
            // -------

            var          gdalDataDirectoryInfo = new DirectoryInfo(@"C:\Program Files\GDAL\gdal-data");
            const string sourceLayerName       = "MySourceLayerName";
            var          inputGdbFile          = new FileInfo(@"C:\temp\MyZippedGdbFile.gdb.zip");

            // Act
            // ---
            var actualCommandLineArguments = Ogr2OgrCommandLineRunner.BuildCommandLineArgumentsForFileGdbToGeoJson(
                inputGdbFile,
                gdalDataDirectoryInfo,
                sourceLayerName, CoordinateSystemId, true);

            // Assert
            // ------

            // Expecting a command line something like this:
            //"C:\Program Files\GDAL\ogr2ogr.exe" --config GDAL_DATA "C:\\Program Files\\GDAL\\gdal-data" -t_srs EPSG:4326 -explodecollections -f GeoJSON /dev/stdout "C:\\svn\\sitkatech\\trunk\\Corral\\Source\\Neptune.Web\\Models\\GdalOgr\\SampleFileGeodatabase.gdb.zip"

            var expectedCommandLineArguments = new[] { "--config", "GDAL_DATA", gdalDataDirectoryInfo.FullName, "-t_srs", Ogr2OgrCommandLineRunner.GetMapProjection(CoordinateSystemId), "-explodecollections", "-f", "GeoJSON", "/dev/stdout", inputGdbFile.FullName, string.Format("\"{0}\"", sourceLayerName) };

            Assert.That(actualCommandLineArguments, Is.EquivalentTo(expectedCommandLineArguments), "Should produce expected arguments");

            var expectedCommandLineArgumentsEncodedString = string.Join(" ", expectedCommandLineArguments.Select(ProcessUtility.EncodeArgumentForCommandLine).ToList());
            var actualCommandLineArgumentsEncodedString   = string.Join(" ", actualCommandLineArguments.Select(ProcessUtility.EncodeArgumentForCommandLine).ToList());

            Assert.That(actualCommandLineArgumentsEncodedString, Is.EqualTo(expectedCommandLineArgumentsEncodedString), "Should produce the expected command line argument string in the correct order");
        }
Ejemplo n.º 2
0
        public void SecurityFeaturesMustHaveDescription()
        {
            AssertCustom.IgnoreOnBuildServer();

            var baseFeatureClass = typeof(NeptuneBaseFeature);
            var types            = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => baseFeatureClass.IsAssignableFrom(p) && p.Name != baseFeatureClass.Name && !p.IsAbstract);

            var listOfSecurityFeaturesWithoutDescription = new List <string>();

            foreach (var type in types)
            {
                Attribute[] attributes = Attribute.GetCustomAttributes(type);
                if (!attributes.Any(x => x is SecurityFeatureDescription))
                {
                    listOfSecurityFeaturesWithoutDescription.Add(type.FullName);
                }
                else if (attributes.Where(x => x is SecurityFeatureDescription).Any(attr => ((SecurityFeatureDescription)attr).DescriptionMessage == ""))
                {
                    listOfSecurityFeaturesWithoutDescription.Add(type.FullName); //Also flag anything where the description is blank
                }
            }

            if (listOfSecurityFeaturesWithoutDescription.Count > 0)
            {
                Assert.Fail(Environment.NewLine + Environment.NewLine + String.Join(Environment.NewLine, listOfSecurityFeaturesWithoutDescription));
            }
        }
Ejemplo n.º 3
0
        public void CanSerializeAFeatureCollectionAndEnsureItIsValidTest()
        {
            AssertCustom.IgnoreOnBuildServer();

            var fc   = GetTestFeatureCollection();
            var json = JsonConvert.SerializeObject(fc, Formatting.Indented,
                                                   new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            Assert.IsNotNull(json);
            Trace.WriteLine("You can download spatial maps via http://www.naturalearthdata.com/" + "\r\n" + "\r\n");
            Trace.WriteLine(json);

            var buffer = Encoding.UTF8.GetBytes(json);
            var webReq = (HttpWebRequest)WebRequest.Create("http://geojsonlint.com/validate");

            webReq.Method        = "POST";
            webReq.ContentLength = buffer.Length;
            webReq.ContentType   = "application/x-www-form-urlencoded";

            var reqStream = webReq.GetRequestStream();

            reqStream.Write(buffer, 0, buffer.Length);
            reqStream.Close();

            var webRes    = webReq.GetResponse();
            var resStream = webRes.GetResponseStream();
            // ReSharper disable once AssignNullToNotNullAttribute
            var resReader = new StreamReader(resStream);
            var resObj    = JsonConvert.DeserializeObject <GeoJSONLintResult>(resReader.ReadToEnd());

            Assert.AreEqual(resObj.status, "ok");
        }
Ejemplo n.º 4
0
        public void BuildDhtmlxGridHeaderTest()
        {
            AssertCustom.IgnoreOnBuildServer();

            var gridSpec = new TestGridSpec();
            var result   = DhtmlxGridHtmlHelpers.BuildDhtmlxGridHeader(gridSpec, GridName, NeptuneDhtmlxGridHtmlHelpers.ExcelDownloadWithFooterUrl, NeptuneDhtmlxGridHtmlHelpers.ExcelDownloadWithoutFooterUrl);

            Approvals.Verify(result);
        }
Ejemplo n.º 5
0
        public void CreateFilteredExcelDownloadIconHtmlTest()
        {
            AssertCustom.IgnoreOnBuildServer();

            const string gridName = "testGridName";
            var          result   = DhtmlxGridHtmlHelpers.CreateFilteredExcelDownloadIconHtml(gridName, true, NeptuneDhtmlxGridHtmlHelpers.ExcelDownloadWithFooterUrl, NeptuneDhtmlxGridHtmlHelpers.ExcelDownloadWithoutFooterUrl);

            Approvals.Verify(result);
        }
Ejemplo n.º 6
0
        public void TestPyqgisLauncher()
        {
            AssertCustom.IgnoreOnBuildServer();

            var processUtilityResult = QgisRunner.ExecutePyqgisScript(NeptuneWebConfiguration.PathToPyqgisTestScript,
                                                                      NeptuneWebConfiguration.PyqgisWorkingDirectory);

            Assert.That(processUtilityResult.ReturnCode == 0);
        }
Ejemplo n.º 7
0
        public void NotUsingAllowAnonymousAttribute()
        {
            AssertCustom.IgnoreOnBuildServer();
            var allControllerActionMethods = NeptuneBaseController.AllControllerActionMethods;
            var usingAllowAnonymous        = allControllerActionMethods.Where(m => m.GetCustomAttributes().Any(a => a.GetType() == _typeOfAllowAnonymousAttribute || a.GetType().IsSubclassOf(_typeOfAllowAnonymousAttribute))).ToList();

            var x = usingAllowAnonymous.Select(MethodName).ToList();

            Assert.That(x, Is.Empty, string.Format("Found some uses of \"{0}\", should be using types of \"{1}\" only.", _typeOfAllowAnonymousAttribute.FullName, _typeOfNeptuneBaseFeature.FullName));
        }
Ejemplo n.º 8
0
        public void TestProcessing()
        {
            AssertCustom.IgnoreOnBuildServer();

            var processUtilityResult = QgisRunner.ExecutePyqgisScript(
                $"{NeptuneWebConfiguration.PyqgisWorkingDirectory}TestPyqgisProcessing.py",
                @"C:\Windows\System32\");

            Assert.That(processUtilityResult.ReturnCode == 0);
        }
Ejemplo n.º 9
0
        public void CanSerializeAFeatureCollectionTest()
        {
            AssertCustom.IgnoreOnBuildServer();

            var fc   = GetTestFeatureCollection();
            var json = JsonConvert.SerializeObject(fc, Formatting.Indented,
                                                   new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            Approvals.Verify(json);
        }
Ejemplo n.º 10
0
        public void EachControllerActionShouldHaveOneFeature()
        {
            AssertCustom.IgnoreOnBuildServer();
            var allControllerActionMethods = NeptuneBaseController.AllControllerActionMethods;

            var info = allControllerActionMethods.Select(method => new { Name = MethodName(method), FeatureCount = NumberOfNeptuneFeatureAttributesOnMethod(method) }).ToList();

            // Remove exceptions
            info = info.Where(x => x.Name != "JasmineController.Run").ToList();

            Assert.That(info.Where(x => x.FeatureCount == 0).ToList(), Is.Empty, string.Format("All should have at least one {0}", _typeOfNeptuneBaseFeature.Name));
            Assert.That(info.Where(x => x.FeatureCount > 1).ToList(), Is.Empty, string.Format("Should have no more than one{0}", _typeOfNeptuneBaseFeature.Name));
        }
        public void CanExecuteOgr2OgrFromGeoJsonSingleColumnToExistingMsSql()
        {
            AssertCustom.IgnoreOnBuildServer();

            var          gdbFileInfo     = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip");
            const string sourceLayerName = "MySampleFeatureClass";
            // Act
            // ---
            const int    totalMilliseconds        = 110000;
            const string pathToOgr2OgrExecutable  = @"C:\Program Files\GDAL\ogr2ogr.exe";
            var          ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, CoordinateSystemId, totalMilliseconds);
            var          geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true);

            var destinationTableName = "test_table";

            var sqlSelectClause = string.Format("mystringcolumn as attribute, {0} as ProjectID", 77);

            try
            {
                CreateOgrRequiredTables(destinationTableName, null);

                // Act
                // ---
                ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(geoJson, TempDbSqlDatabase.DatabaseConnectionStringToTempDb, destinationTableName, sqlSelectClause);
                var result = ExecAdHocSql(string.Format("select * from {0}", destinationTableName));

                // Assert
                // ------

                Assert.That(result, Is.Not.Null, "Should have found the table imported");
                Assert.That(result.Rows.Count, Is.EqualTo(6), "Should have gotten 6 rows");
            }
            finally
            {
                // Cleanup
                // -------
                try
                {
                    ExecAdHocSql("drop table " + destinationTableName);
                }
                catch
                {
                    // ignored
                }
                try
                {
                    ExecAdHocSql("drop table spatial_ref_sys");
                }
                catch
                {
                    // ignored
                }
                try
                {
                    ExecAdHocSql("drop table geometry_columns");
                }
                catch
                {
                    // ignored
                }
            }
        }