Skip to content

Commit 4309cfb

Browse files
committed
CSHARP-2093: fixed testing issue with MongoIncompatibleDriverException.
1 parent 48f899f commit 4309cfb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/MongoDB.Driver.Core/MongoIncompatibleDriverException.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ private static string FormatMessage(ClusterDescription description)
4949
var incompatibleServer = description.Servers
5050
.FirstOrDefault(sd => sd.WireVersionRange != null && !sd.WireVersionRange.Overlaps(Cluster.SupportedWireVersionRange));
5151

52+
if (incompatibleServer == null)
53+
{
54+
return $"This version of the driver requires wire version {Cluster.SupportedWireVersionRange}";
55+
}
56+
5257
if (incompatibleServer.WireVersionRange.Max < Cluster.SupportedWireVersionRange.Min)
5358
{
5459
return $"Server at {EndPointHelper.ToString(incompatibleServer.EndPoint)} reports wire version {incompatibleServer.WireVersionRange.Max},"

tests/MongoDB.Driver.Core.Tests/MongoIncompatibleDriverExceptionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#endif
2121
using FluentAssertions;
2222
using MongoDB.Driver.Core.Clusters;
23+
using MongoDB.Driver.Core.Misc;
2324
using MongoDB.Driver.Core.Servers;
2425
using Xunit;
2526

@@ -36,7 +37,7 @@ public MongoIncompatibleDriverExceptionTests()
3637
var clusterType = ClusterType.Standalone;
3738
var endPoint = new DnsEndPoint("localhost", 27017);
3839
var serverId = new ServerId(clusterId, endPoint);
39-
var server = new ServerDescription(serverId, endPoint);
40+
var server = new ServerDescription(serverId, endPoint, wireVersionRange: new Range<int>(0, 0));
4041
var servers = new[] { server };
4142
_clusterDescription = new ClusterDescription(clusterId, connectionMode, clusterType, servers);
4243
}
@@ -46,8 +47,7 @@ public void constructor_should_initalize_subject()
4647
{
4748
var subject = new MongoIncompatibleDriverException(_clusterDescription);
4849

49-
subject.Message.StartsWith("This version of the driver is not compatible");
50-
subject.Message.EndsWith(":" + _clusterDescription.ToString() + ".");
50+
subject.Message.Should().StartWith("Server at localhost:27017 reports wire version 0");
5151
subject.InnerException.Should().BeNull();
5252
}
5353

0 commit comments

Comments
 (0)