Skip to content

Commit a059c7c

Browse files
Nik Kolevrstam
authored andcommitted
CSHARP-610 Invalid server address message.
Fixes the FormatException message in the path in MongoServerAddress::Parse where the provided 'url' does not pass the ::TryParse criteria for correctness. The intent was to provide the offending value in the message, but the developer forgot to fill in the {0} placeholder.
1 parent 8c26ec4 commit a059c7c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Driver/Core/MongoServerAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static MongoServerAddress Parse(string value)
7171
}
7272
else
7373
{
74-
throw new FormatException("'{0}' is not a valid server address.");
74+
throw new FormatException(String.Format("'{0}' is not a valid server address.", value));
7575
}
7676
}
7777

DriverUnitTests/Core/MongoServerAddressTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,21 @@ public void TestParseWithHostAndPort()
8787
Assert.AreEqual("host", credentials.Host);
8888
Assert.AreEqual(123, credentials.Port);
8989
}
90+
91+
[Test]
92+
[ExpectedException(ExpectedException = typeof(FormatException),
93+
ExpectedMessage = "'' is not a valid server address.")]
94+
public void TestParseNullParam()
95+
{
96+
MongoServerAddress.Parse(null);
97+
}
98+
99+
[Test]
100+
[ExpectedException(ExpectedException = typeof(FormatException),
101+
ExpectedMessage = "'' is not a valid server address.")]
102+
public void TestParseEmptyParam()
103+
{
104+
MongoServerAddress.Parse(String.Empty);
105+
}
90106
}
91107
}

0 commit comments

Comments
 (0)