public void CanThrowNotNullMsg() { const object dummy = null; NUnit.Framework.Assert.Throws <AssertionException>( () => Assert.NotNull(dummy, "{0} {1}", "arg1", "arg")); }
public void CanThrowNotNullForNullable() { int?dummy = null; NUnit.Framework.Assert.Throws <AssertionException>( () => Assert.NotNull(dummy)); }
public void CanGetExistingRowsFastEnough() { IFeatureWorkspace ws = OpenTestWorkspace(); ITable fc = ws.OpenTable("TOPGIS_TLM.TLM_WANDERWEG"); const int max = 100; IDictionary <int, IRow> rows = GetFirstNRows(fc, max); var watch = new Stopwatch(); watch.Start(); foreach (int oid in rows.Keys) { Assert.NotNull(GdbQueryUtils.GetRow(fc, oid)); _msg.Info($"Oid {oid} time: {watch.ElapsedMilliseconds}"); } watch.Stop(); double msPerIteration = watch.ElapsedMilliseconds / (double)rows.Count; _msg.InfoFormat(@"GetRow() per iteration: {0} ms", msPerIteration); Assert.True(msPerIteration < 50, "GetFeature with existing feature takes too long ({0} ms, {1} rows)", msPerIteration, rows.Count); }
public void CanCreateSpatialFilterWithNonZSimpleGeometry() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); IEnvelope nonZSimpleEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000, 2700000, 1300000); GeometryUtils.MakeZAware(nonZSimpleEnvelope); Assert.False(((IZAware)nonZSimpleEnvelope).ZSimple, "Must be non-Z-simple"); ISpatialReference spatialReference = Assert.NotNull(DatasetUtils.GetSpatialReference(fc)); IGeometry validGeometry; string message; Assert.False(GdbQueryUtils.IsValidFilterGeometry( nonZSimpleEnvelope, SpatialReferenceUtils.GetXyResolution(spatialReference), out validGeometry, out message), "Search geometry should not be valid"); Assert.NotNull(validGeometry); IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter(fc, nonZSimpleEnvelope); Assert.True(GdbQueryUtils.GetFeatures(fc, filter, true).Any(), "No features found"); }
public void CanGetRowsNotInUUIDList() { IFeatureWorkspace ws = OpenTestWorkspace(); ITable tbl = ws.OpenTable("TOPGIS_TLM.TLM_STRASSE"); var nRows = 0; IQueryFilter filter = new QueryFilterClass(); foreach ( // ReSharper disable once UnusedVariable IRow row in GdbQueryUtils.GetRowsNotInList(tbl, filter, true, "UUID", new[] { "{8C5517C9-B19F-4CC1-A6A1-D3DD317BCDD1}" })) { nRows++; } filter.WhereClause = "UUID not in ('{8C5517C9-B19F-4CC1-A6A1-D3DD317BCDD1}')"; int n = tbl.RowCount(filter); Assert.AreEqual(n, nRows, ""); }
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 Learning_CanFindFeaturesWithNonZSimpleSearchGeometry() { // 10.2.1: Test fails (correct) with COM Exception on OpenCursor // 10.4.1: Test fails (correct) with COM Exception on OpenCursor // 10.6.1: Test passes (incorrectly!), no features found IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); IEnvelope nonZSimpleEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000, 2700000, 1300000); GeometryUtils.MakeZAware(nonZSimpleEnvelope); Assert.False(((IZAware)nonZSimpleEnvelope).ZSimple, "Must be non-Z-simple"); ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc); nonZSimpleEnvelope.SpatialReference = spatialReference; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.GeometryField = fc.ShapeFieldName; spatialFilter.set_GeometryEx(nonZSimpleEnvelope, true); spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; Assert.AreEqual(0, GdbQueryUtils.GetFeatures(fc, spatialFilter, true).Count(), "Behaviour changed: Now features are found even with non-Z-simple search geometry."); }
public void CanGetRowsInLongList() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); // fill list const int max = 2000; Dictionary <int, IRow> dic = GetFirstNRows((ITable)fc, max); var selList = new List <int>(max); foreach (IRow row in GdbQueryUtils.GetRowsInList((ITable)fc, fc.OIDFieldName, dic.Keys, false, null)) { selList.Add(row.OID); IRow origRow = dic[row.OID]; Assert.AreEqual(origRow.OID, row.OID, ""); //dic[row.OID] = null; REMARK: this changes list dic.Keys and leads to an error in foreach } Assert.AreEqual(dic.Count, selList.Count, "List counts differ"); var oidList = new List <int>(dic.Keys); oidList.Sort(); selList.Sort(); for (var i = 0; i < oidList.Count; i++) { Assert.AreEqual(oidList[i], selList[i], "{0}th element differs", i); } }
public void CanThrowNotNull() { const object dummy = null; NUnit.Framework.Assert.Throws <AssertionException>( () => Assert.NotNull(dummy)); }
public void CanGetNullForNonExistingRow() { IFeatureWorkspace ws = OpenTestWorkspace(); ITable table = ws.OpenTable("TOPGIS_TLM.TLM_WANDERWEG"); Assert.Null(GdbQueryUtils.GetRow(table, 999999999)); }
public void CanGetNullForNonExistingFeatureFastEnough() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); const int iterations = 200; var watch = new Stopwatch(); watch.Start(); for (var iteration = 0; iteration < iterations; iteration++) { int oid = 999999999 + iteration; Assert.Null(GdbQueryUtils.GetFeature(fc, oid)); } watch.Stop(); double msPerIteration = watch.ElapsedMilliseconds / (double)iterations; _msg.InfoFormat(@"GetFeature() per iteration: {0} ms", msPerIteration); const int maxMilliseconds = 35; Assert.True(msPerIteration < maxMilliseconds, "GetFeature with non-existing feature takes too long ({0} ms)", msPerIteration); }
public void CanGetNullForNonExistingFeatureByGetRow() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); Assert.Null(GdbQueryUtils.GetRow((ITable)fc, 999999999)); }
private static void AssertFilteredRowCount( int expectedCount, [NotNull] string expression, params IFeature[] features) { TableView view = CreateTableView(expression, features); Assert.AreEqual(expectedCount, view.FilteredRowCount, "Unexpected filtered row count"); }
public void TableSortGuidFileGdb() { IFeatureWorkspace featureWs = WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath()); //IFeatureWorkspace featureWs = OpenTestWorkspace(); ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL"); ITableSort tableSort = new TableSortClass(); tableSort.Table = table; tableSort.Fields = "UUID"; tableSort.Sort(null); ICursor cursor = tableSort.Rows; IRow row; Guid lastValue = Guid.Empty; while ((row = cursor.NextRow()) != null) { object value = row.get_Value(1); Assert.False(value == DBNull.Value, "Empty UUID field"); var currentGuid = new Guid((string)value); IComparable currentValue = currentGuid; Console.WriteLine(currentValue); if (lastValue != Guid.Empty) { // ITableSort on a GUID field in a file GDB does not sort the byte array or at least not in an obvious way byte[] currentGuidAsByteArray = currentGuid.ToByteArray(); byte[] lastGuidAsByteArray = lastValue.ToByteArray(); int byteArrayCompare = ByteArrayCompare(currentGuidAsByteArray, lastGuidAsByteArray); //Assert.True(byteArrayCompare > 0, "Different compare algorithm from byte array"); // ITableSort on a GUID field in a file GDB does not sort the same way as SqlGuid in .NET (i.e. SQL Server sorting) var sqlGuid = new SqlGuid(currentGuid); int sqlGuidCompare = sqlGuid.CompareTo(new SqlGuid(lastValue)); //Assert.True(sqlGuidCompare < 0, "Different compare algorithm from sql server"); // ITableSort on a GUID field in a file GDB does not sort the same way as Guid in .NET IComparable comparableGuid = lastValue; int guidCompare = comparableGuid.CompareTo(currentValue); //Assert.True(guidCompare < 0, "Different compare algorithm from .Net."); } lastValue = currentGuid; } }
private static IFeature GetFeatureUsingGetFeatures( [NotNull] IFeatureClass featureClass, int oid) { var singleOidList = new List <int> { oid }; IList <IFeature> features = new List <IFeature>( GdbQueryUtils.GetFeatures(featureClass, singleOidList, false)); Assert.AreEqual(1, features.Count, "unexpected feature count"); return(features[0]); }
public void CanCreateSpatialFilterWithSubResolutionEnvelope() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); IEnvelope subResolutionEnv = GeometryFactory.CreateEnvelope(2600000, 1200000, 2600000.0001, 1200000.0001); ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc); subResolutionEnv.SpatialReference = spatialReference; double xyResolution = SpatialReferenceUtils.GetXyResolution(Assert.NotNull(spatialReference)); IGeometry validGeometry; string message; Assert.False(GdbQueryUtils.IsValidFilterGeometry( subResolutionEnv, xyResolution, out validGeometry, out message), "Sub-resolution polygon should not be valid"); Assert.NotNull(validGeometry); Assert.False(subResolutionEnv == validGeometry, "Corrected geometry must be different to input"); Assert.True(GdbQueryUtils.IsValidFilterGeometry( validGeometry, xyResolution, out validGeometry, out message), "Corrected geometry should be valid"); IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter( fc, subResolutionEnv, esriSpatialRelEnum.esriSpatialRelIntersects, false, spatialReference); IFeatureCursor cursor = fc.Search(filter, true); Marshal.ReleaseComObject(cursor); IEnvelope linearEnv = GeometryFactory.CreateEnvelope(2600000, 1200000, 2600000.0001, 1201010); linearEnv.SpatialReference = ((IGeoDataset)fc).SpatialReference; filter = GdbQueryUtils.CreateSpatialFilter( fc, linearEnv, esriSpatialRelEnum.esriSpatialRelIntersects, true, null); cursor = fc.Search(filter, true); Marshal.ReleaseComObject(cursor); }
private static void AssertFilteredMultiViewRowCount( int expectedCount, [NotNull] string expression, [NotNull] IFeatureClass featureClass, [NotNull] IFeature feature, [NotNull] ITable table, [NotNull] IRow row) { MultiTableView view = TableViewFactory.Create(new[] { (ITable)featureClass, table }, new[] { "F", "T" }, expression); view.Add(feature, row); Assert.AreEqual(expectedCount, view.FilteredRowCount, "Unexpected filtered row count"); }
public void CanCreateSpatialFilterWithEmptyPolygon() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); IPolygon emptyPoly = new PolygonClass(); emptyPoly.SpatialReference = ((IGeoDataset)fc).SpatialReference; IGeometry validGeometry; string message; Assert.False(GdbQueryUtils.IsValidFilterGeometry( emptyPoly, 0.001, out validGeometry, out message), "Empty polygon should not be valid"); Assert.Null(validGeometry); if (RuntimeUtils.Is10_4orHigher) { NUnit.Framework.Assert.Catch <Exception>( () => GdbQueryUtils.CreateSpatialFilter(fc, emptyPoly)); } ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.GeometryField = fc.ShapeFieldName; spatialFilter.set_GeometryEx(emptyPoly, true); spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor cursor = null; if (RuntimeUtils.Is10_1 || RuntimeUtils.Is10_2 || RuntimeUtils.Is10_3 || RuntimeUtils.Is10_4orHigher) { NUnit.Framework.Assert.Throws <NullReferenceException>( () => cursor = fc.Search(spatialFilter, true)); } else { cursor = fc.Search(spatialFilter, true); } if (cursor != null) { Marshal.ReleaseComObject(cursor); } }
private static int ByteArrayCompare(byte[] a1, byte[] a2) { Assert.AreEqual(a1.Length, a2.Length, "Length difference"); for (int i = 0; i < a1.Length; i++) { int compareValue = a1[i].CompareTo(a2[i]); if (compareValue != 0) { return(compareValue); } } return(0); }
private static TableView CreateTableView([NotNull] string expression, params IFeature[] features) { Assert.ArgumentCondition(features.Length > 0, "no feature"); var table = (ITable)features[0].Class; const bool useAsConstraint = true; TableView view = TableViewFactory.Create(table, expression, useAsConstraint); foreach (IFeature feature in features) { view.Add(feature); } return(view); }
public void CanResolvePartialTemplate() { const string templatePath = "C:\\Program Files (x86)\\ProSuite\\bin\\config\\template.html.tpl"; const string partialName = "partial_name"; string templateDirectory = Assert.NotNull(Path.GetDirectoryName(Path.GetFullPath(templatePath))); var fileSystem = new LocalFileSystem(templateDirectory); string result = fileSystem.FullPath(partialName); Console.WriteLine(result); NUnit.Framework.Assert.AreEqual(Path.Combine(templateDirectory, $"_{partialName}.liquid"), result); }
private static void LoopAndWrite(ICursor cursor, string uuidFieldName) { int fieldIndex = cursor.FindField(uuidFieldName); Assert.True(fieldIndex >= 0, "Field not found"); IRow row; while ((row = cursor.NextRow()) != null) { object value = row.get_Value(fieldIndex); Assert.False(value == DBNull.Value, "Empty UUID field"); var currentGuid = new Guid((string)value); IComparable currentValue = currentGuid; // value as IComparable; // currentGuid; Console.WriteLine(currentValue); } }
public void CanGetRowsNotInIntList() { IFeatureWorkspace ws = OpenTestWorkspace(); ITable tbl = ws.OpenTable("TOPGIS_TLM.TLM_STRASSE"); var nRows = 0; IQueryFilter filter = new QueryFilterClass(); foreach ( // ReSharper disable once UnusedVariable IRow row in GdbQueryUtils.GetRowsNotInList(tbl, filter, true, "OBJEKTART", new object[] { 1, 2, 3 })) { nRows++; } filter.WhereClause = "OBJEKTART not in (1, 2, 3)"; int n = tbl.RowCount(filter); Assert.AreEqual(n, nRows, ""); }
public void CanGetRowsNotInStringList() { IFeatureWorkspace ws = OpenTestWorkspace(); ITable tbl = ws.OpenTable("TOPGIS_TLM.TLM_STRASSE"); var nRows = 0; IQueryFilter filter = new QueryFilterClass(); foreach ( // ReSharper disable once UnusedVariable IRow row in GdbQueryUtils.GetRowsNotInList(tbl, filter, true, "OPERATEUR", new[] { "STR_Imp" })) { nRows++; } filter.WhereClause = "OPERATEUR not in ('STR_Imp')"; int n = tbl.RowCount(filter); Assert.AreEqual(n, nRows, ""); }
public void CanCreateSpatialFilterWithMultipatch() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc); IEnvelope largeEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000, 2601000, 1201000, 445, spatialReference); IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(GeometryFactory.CreatePolygon(largeEnvelope)); double xyResolution = SpatialReferenceUtils.GetXyResolution(Assert.NotNull(spatialReference)); // NOTE: Multipatch implements IRelationalOperator since a while! IGeometry validGeometry; string message; Assert.True(GdbQueryUtils.IsValidFilterGeometry( multiPatch, xyResolution, out validGeometry, out message), "Multipatch should be valid"); Assert.NotNull(validGeometry); Assert.True(multiPatch == validGeometry, "Multipatch should be valid"); Assert.True(GdbQueryUtils.IsValidFilterGeometry( validGeometry, xyResolution, out validGeometry, out message), "Corrected geometry should be valid"); IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter( fc, multiPatch, esriSpatialRelEnum.esriSpatialRelIntersects, false, spatialReference); Assert.True(GdbQueryUtils.GetFeatures(fc, filter, true).Any(), "No features found."); }
public void OrderByGuidFileGdb() { IFeatureWorkspace featureWs = WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath()); ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL"); IQueryFilter queryFilter = new QueryFilterClass(); var queryFilterDef = (IQueryFilterDefinition)queryFilter; queryFilterDef.PostfixClause = "ORDER BY UUID"; foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, true)) { object value = row.get_Value(1); Assert.False(value == DBNull.Value, "Empty UUID field"); var currentGuid = new Guid((string)value); Console.WriteLine(currentGuid); } }
public void CanSortOnFgdbGuids() { 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"; ICursor cursor = TableSortUtils.GetGuidFieldSortedCursor(table, uuidFieldName); int fieldIndex = cursor.FindField(uuidFieldName); Assert.True(fieldIndex >= 0, "Field not found"); Guid lastGuid = Guid.Empty; IRow row; while ((row = cursor.NextRow()) != null) { object value = row.get_Value(fieldIndex); Assert.False(value == DBNull.Value, "Empty UUID field"); var currentGuid = new Guid((string)value); Console.WriteLine(currentGuid); if (lastGuid != Guid.Empty) { Assert.False(currentGuid.CompareTo(lastGuid) < 0, "Not sorted"); } lastGuid = currentGuid; } }
public void CantAssertNotAssignableFrom2() { NUnit.Framework.Assert.Throws <AssertionException>( () => Assert.IsAssignableFrom(typeof(SubClass), typeof(SuperClass))); }
public void CanAssertAssignableFrom() { Assert.IsAssignableFrom(typeof(SuperClass), typeof(SubClass)); }
public void CantAssertNotAssignable1() { NUnit.Framework.Assert.Throws <AssertionException>( () => Assert.IsAssignable(new OtherClass(), typeof(SuperClass))); }