Skip to content

Commit 4a0fa50

Browse files
CSHARP-2824: Collect metadata for legacy API.
1 parent 159d655 commit 4a0fa50

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/MongoDB.Driver.Core/Core/Connections/ClientDocumentHelper.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ internal static BsonDocument CreateDriverDocument()
5959

6060
internal static BsonDocument CreateDriverDocument(string driverVersion)
6161
{
62+
var driverName = "mongo-csharp-driver";
63+
if (IsLegacyLoaded())
64+
{
65+
driverName = $"{driverName}|legacy";
66+
}
67+
6268
return new BsonDocument
6369
{
64-
{ "name", "mongo-csharp-driver" },
70+
{ "name", driverName },
6571
{ "version", driverVersion }
6672
};
73+
74+
bool IsLegacyLoaded()
75+
{
76+
return Type.GetType("MongoDB.Driver.MongoServer, MongoDB.Driver.Legacy") != null;
77+
}
6778
}
6879

6980
internal static BsonDocument CreateOSDocument()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Copyright 2020-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Linq;
17+
using FluentAssertions;
18+
using MongoDB.Bson;
19+
using MongoDB.Bson.TestHelpers.XunitExtensions;
20+
using MongoDB.Driver.Core.Connections;
21+
using Xunit;
22+
23+
namespace MongoDB.Driver.Legacy.Tests
24+
{
25+
public class ClientDocumentHelperTests
26+
{
27+
[Fact]
28+
public void CreateDriverDocument_should_return_expected_result()
29+
{
30+
var result = ClientDocumentHelper.CreateDriverDocument();
31+
32+
result["name"].AsString.Should().Be("mongo-csharp-driver|legacy");
33+
result["version"].BsonType.Should().Be(BsonType.String);
34+
}
35+
36+
[Theory]
37+
[ParameterAttributeData]
38+
public void CreateDriverDocument_with_args_should_return_expected_result(
39+
[Values("2.4.0", "2.4.1")]
40+
string driverVersion)
41+
{
42+
var result = ClientDocumentHelper.CreateDriverDocument(driverVersion);
43+
44+
result.Should().Be($"{{ name : 'mongo-csharp-driver|legacy', version : '{driverVersion}' }}");
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)