GIS Converter - Converters Tests Coverage

Dani_S 5,261 Reputation points
2025-12-17T08:59:28.8633333+00:00

Hi Michel,

First thank you very much for your help.

In continue to : https://learn.microsoft.com/en-us/answers/questions/5658105/gis-convert-from-one-format-to-any-formats

1.Can you please look on the Converters tests and see if I cover all the needed tests ?

If not can you please give me the missing info and code?

2.Files:

Converters -Code

GitConverter.Lib.md.txt

Converter

README.md.txt

IConverter.cs.txt

UniversalGisConverter.cs.txt

ConverterUtils.cs.txt

JsonFormatDetector.cs.txt

Converters -Tests

# GitConverter.TestsApp.txt

Converters

README.md.txt

ConverterUtilsTests.cs.txt

JsonFormatDetectorTests.cs.txt

UniversalGisConverterTests.txt

ShapefileConverterIntegrationTests.cs.txt

CsvConverterIntegrationTests.cs.txt

GmlConversionIntegrationTests.cs.txt

Thanks in advance,

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 7,785 Reputation points Microsoft External Staff Moderator
    2025-12-22T08:31:37.47+00:00

    Hello @Dani_S ,

    There are several improvements could be made.

    JsonFormatDetectorTests.cs

    Add the following new test methods to cover edge cases with conflicting format markers and malformed JSON:

    [Fact(DisplayName = "Detect_ConflictingMarkers_ReturnsConsistentResult")]
    public void Detect_ConflictingMarkers_ReturnsConsistentResult()
    {
        var json = @"{ ""type"": ""FeatureCollection"", ""spatialReference"":  { ""wkid"": 4326 }, ""features"":  [] }";
        var path = Write("conflicting.json", json);
        var result = DetectFromFile(path);
        Assert.Equal(Format.GeoJson, result);
    }
    
    [Fact(DisplayName = "Detect_SeverelyMalformed_ReturnsUnknown")]
    public void Detect_SeverelyMalformed_ReturnsUnknown()
    {
        var json = @"{ ""type"": ""FeatureCollection"", ""features"": [{ ""type"": ""Feature"" "; // truncated/malformed
        var path = Write("malformed.json", json);
        var result = DetectFromFile(path);
        Assert.Equal(Format.Unknown, result);
    }
    

    UniversalGisConverterTests.cs

    Add tests for partial archive extraction failures and Aspose conversion failures:

    [Fact(DisplayName = "Convert_ArchiveMissingRequiredComponent_ReturnsFailure")]
    public void Convert_ArchiveMissingRequiredComponent_ReturnsFailure()
    {
        var zipPath = Path. Combine(_root, "incomplete. zip");
        var tempDir = Path.Combine(_root, "ztemp");
        Directory.CreateDirectory(tempDir);
    
        File.WriteAllText(Path. Combine(tempDir, "data.shp"), "shp");
        File.WriteAllText(Path.Combine(tempDir, "data.shx"), "shx");
        // Missing . dbf file
        ZipFile.CreateFromDirectory(tempDir, zipPath);
    
        var conv = new UniversalGisConverter();
        var outDir = Path.Combine(_root, "out");
        var temp = Path.Combine(_root, "temp");
        var res = conv.Convert(zipPath, "Shapefile", "GeoJson", outDir, temp);
    
        Assert.Equal(ConversionStatus.Failure, res.Status);
        Assert.Contains("missing", res.Message, StringComparison. OrdinalIgnoreCase);
    }
    
    [Fact(DisplayName = "Convert_InvalidGeometry_ReturnsFailure")]
    public void Convert_InvalidGeometry_ReturnsFailure()
    {
        if (!IntegrationEnabled()) return;
    
        var conv = new UniversalGisConverter();
        var badGeo = Path.Combine(_root, "invalid.geojson");
        File.WriteAllText(badGeo, @"{ ""type"":  ""FeatureCollection"", ""features"": [{ ""type"": ""Feature"", ""geometry"": { ""type"": ""Point"", ""coordinates"": [""invalid"", ""data""] }}]}");
    
        var res = conv.Convert(badGeo, "GeoJson", "Shapefile", Path.Combine(_root, "out"), Path.Combine(_root, "temp"));
    
        Assert.Equal(ConversionStatus. Failure, res.Status);
        Assert.False(string.IsNullOrWhiteSpace(res.Message));
    }
    

    All test Dispose methods (across all test files)

    Update the silent exception handling to include debug output:

    public void Dispose()
    {
        try 
        { 
            if (Directory. Exists(_root)) 
                Directory.Delete(_root, true); 
        } 
        catch (Exception ex) 
        { 
            System.Diagnostics.Debug.WriteLine($"Cleanup failed for {_root}: {ex.Message}");
        }
    }
    

    UniversalGisConverter.cs

    Fix the logging inconsistency where the class references "CsvConverter" in log messages. Change line:

    Log.Debug($"CsvConverter. Convert params: gisInputFilePath='{gisInputFilePath}'... 
    

    to:

    Log.Debug($"UniversalGisConverter.Convert params: gisInputFilePath='{gisInputFilePath}'... 
    

    And similarly for other log messages in that file that incorrectly reference "CsvConverter".

    Happy holidays.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.