Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization bug #46666

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/maps/Azure.Maps.Routing/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/maps/Azure.Maps.Routing",
"Tag": "net/maps/Azure.Maps.Routing_54064ae0c1"
"Tag": "net/maps/Azure.Maps.Routing_0755b0a67d"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private async ValueTask<Response<RouteMatrixResult>> WaitForCompletionAsync(bool
_id = paths[paths.Length - 1];
}

RouteMatrixResult result = null;
return Response.FromValue(result, response);
return await WaitForCompletionAsync(async, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable

using System.Text.Json;

namespace Azure.Maps.Routing.Models
{
public partial class RouteMatrix
{
internal static RouteMatrix DeserializeRouteMatrix(JsonElement element)
{
if (element.ValueKind == JsonValueKind.Null)
{
return null;
}
int? statusCode = default;
RouteMatrixResultResponse response = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("statusCode"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
statusCode = property.Value.GetInt32();
continue;
}
if (property.NameEquals("response"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
if (statusCode == 200) {
response = RouteMatrixResultResponse.DeserializeRouteMatrixResultResponse(property.Value);
} else {
response = new RouteMatrixResultResponse(null);
}
continue;
}
}
return new RouteMatrix(statusCode, response);
}

/// <summary> Deserializes the model from a raw response. </summary>
/// <param name="response"> The response to deserialize the model from. </param>
internal static RouteMatrix FromResponse(Response response)
{
using var document = JsonDocument.Parse(response.Content);
return DeserializeRouteMatrix(document.RootElement);
}
}
}
11 changes: 8 additions & 3 deletions sdk/maps/Azure.Maps.Routing/tests/RouteMatrixTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -27,15 +28,19 @@ public async Task CanSyncRequestRouteMatrix()
new GeoPosition(123.751, 45.9375),
new GeoPosition(123.791, 45.96875)
},
Destinations = new List<GeoPosition>() { new GeoPosition(123.767, 45.90625) },
Destinations = new List<GeoPosition>()
{
new GeoPosition(1, 13.5471),
new GeoPosition(123.767, 45.90625),
},
};
var result = await client.GetImmediateRouteMatrixAsync(routeMatrixQuery);

Assert.AreEqual("0.0.1", result.Value.FormatVersion);
Assert.AreEqual(2, result.Value.Matrix.Count);
Assert.AreEqual(1, result.Value.Matrix[0].Count);
Assert.AreEqual(2, result.Value.Matrix[0].Count);
Assert.AreEqual(2, result.Value.Summary.SuccessfulRoutes);
Assert.AreEqual(2, result.Value.Summary.TotalRoutes);
Assert.AreEqual(4, result.Value.Summary.TotalRoutes);
}

[RecordedTest]
Expand Down
Loading