Skip to content

Commit ad01e8e

Browse files
Dmitry KovalDmitry Koval
authored andcommitted
AddRouteDestinations fixed: supported addresses with no AddressString
1 parent c86f1af commit ad01e8e

File tree

2 files changed

+100
-18
lines changed

2 files changed

+100
-18
lines changed

route4me-csharp-sdk/Route4MeSDKLibrary/Route4MeManager.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,18 +3080,18 @@ public int[] AddRouteDestinations(string routeId, Address[] addresses, bool opti
30803080
var arrDestinationIds = new List<int>();
30813081

30823082
if (response != null && response.Addresses != null)
3083+
{
30833084
addresses.ForEach(addressNew =>
30843085
{
3085-
response.Addresses.Where(addressResp => addressResp.AddressString == addressNew.AddressString &&
3086-
Math.Abs(addressResp.Latitude - addressNew.Latitude) <
3087-
0.0001 &&
3088-
Math.Abs(addressResp.Longitude - addressNew.Longitude) <
3089-
0.0001 &&
3090-
addressResp.RouteDestinationId != null).ForEach(addrResp =>
3091-
{
3092-
arrDestinationIds.Add((int) addrResp.RouteDestinationId);
3093-
});
3086+
response.Addresses.Where(addressResp =>
3087+
(addressResp.AddressString == addressNew.AddressString ||
3088+
addressNew.AddressString == null) &&
3089+
Math.Abs(addressResp.Latitude - addressNew.Latitude) < 0.0001 &&
3090+
Math.Abs(addressResp.Longitude - addressNew.Longitude) < 0.0001 &&
3091+
addressResp.RouteDestinationId != null)
3092+
.ForEach(addrResp => { arrDestinationIds.Add((int)addrResp.RouteDestinationId); });
30943093
});
3094+
}
30953095

30963096
return arrDestinationIds.ToArray();
30973097
}
@@ -3119,18 +3119,18 @@ public async Task<Tuple<int[], string>> AddRouteDestinationsAsync(string routeId
31193119
var arrDestinationIds = new List<int>();
31203120

31213121
if (response.Item1 != null && response.Item1.Addresses != null)
3122+
{
31223123
addresses.ForEach(addressNew =>
31233124
{
3124-
response.Item1.Addresses.Where(addressResp => addressResp.AddressString == addressNew.AddressString &&
3125-
Math.Abs(addressResp.Latitude - addressNew.Latitude) <
3126-
0.0001 &&
3127-
Math.Abs(addressResp.Longitude - addressNew.Longitude) <
3128-
0.0001 &&
3129-
addressResp.RouteDestinationId != null).ForEach(addrResp =>
3130-
{
3131-
arrDestinationIds.Add((int)addrResp.RouteDestinationId);
3132-
});
3125+
response.Item1.Addresses.Where(addressResp =>
3126+
(addressResp.AddressString == addressNew.AddressString ||
3127+
addressNew.AddressString == null) &&
3128+
Math.Abs(addressResp.Latitude - addressNew.Latitude) < 0.0001 &&
3129+
Math.Abs(addressResp.Longitude - addressNew.Longitude) < 0.0001 &&
3130+
addressResp.RouteDestinationId != null)
3131+
.ForEach(addrResp => { arrDestinationIds.Add((int)addrResp.RouteDestinationId); });
31333132
});
3133+
}
31343134

31353135
return new Tuple<int[], string>(arrDestinationIds.ToArray(), response.Item2);
31363136
}

route4me-csharp-sdk/Route4MeSDKUnitTest/Tests/AddressesGroupTests.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,88 @@ public void AddRouteDestinationsTest()
198198
Assert.That(destinationIds, Is.InstanceOf<int[]>(), "AddRouteDestinationsTest failed. " + errorString);
199199
}
200200

201+
[Test]
202+
public void AddRouteDestinationsWithNoAddressStringTest()
203+
{
204+
var route4Me = new Route4MeManager(c_ApiKey);
205+
206+
var route_id = _tdr.SDRT_route_id;
207+
208+
Assert.IsNotNull(route_id, "rote_id is null.");
209+
210+
// Prepare the addresses
211+
212+
#region Addresses
213+
214+
Address[] addresses =
215+
{
216+
new Address
217+
{
218+
Latitude = 30.143526,
219+
Longitude = -87.240354,
220+
Time = 0
221+
},
222+
223+
new Address
224+
{
225+
Latitude = 30.177852,
226+
Longitude = -87.263535,
227+
Time = 0
228+
}
229+
};
230+
231+
#endregion
232+
233+
// Run the query
234+
var optimalPosition = true;
235+
236+
var destinationIds = route4Me.AddRouteDestinations(
237+
route_id,
238+
addresses,
239+
optimalPosition,
240+
out var errorString);
241+
242+
Assert.That(destinationIds.Length, Is.EqualTo(2));
243+
}
244+
245+
[Test]
246+
public void AddInvalidRouteDestinationsWithNoAddressStringTest()
247+
{
248+
var route4Me = new Route4MeManager(c_ApiKey);
249+
250+
var route_id = _tdr.SDRT_route_id;
251+
252+
Assert.IsNotNull(route_id, "rote_id is null.");
253+
254+
// Prepare the addresses
255+
256+
#region Addresses
257+
258+
Address[] addresses =
259+
{
260+
new Address
261+
{
262+
},
263+
264+
new Address
265+
{
266+
}
267+
};
268+
269+
#endregion
270+
271+
// Run the query
272+
var optimalPosition = true;
273+
274+
var destinationIds = route4Me.AddRouteDestinations(
275+
route_id,
276+
addresses,
277+
optimalPosition,
278+
out var errorString);
279+
280+
Assert.That(errorString, Is.Not.Empty);
281+
}
282+
201283
[Test]
202284
public void AddRouteDestinationInSpecificPositionTest()
203285
{

0 commit comments

Comments
 (0)