Skip to content

Commit 616aa49

Browse files
committed
CSHARP-2930: Change default GuidRepresentationMode to V3 and default GuidRepresentation to Unspecified.
1 parent 937d88c commit 616aa49

File tree

91 files changed

+1800
-4892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1800
-4892
lines changed

build.cake

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,6 @@ Task("Test")
124124
return; // Legacy tests are exempt from Version API testing
125125
}
126126

127-
var testWithDefaultGuidRepresentationMode = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE");
128-
if (testWithDefaultGuidRepresentationMode != null)
129-
{
130-
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE={testWithDefaultGuidRepresentationMode}");
131-
}
132-
var testWithDefaultGuidRepresentation = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION");
133-
if (testWithDefaultGuidRepresentation != null)
134-
{
135-
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION={testWithDefaultGuidRepresentation}");
136-
}
137127
var mongoX509ClientCertificatePath = Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PATH");
138128
if (mongoX509ClientCertificatePath != null)
139129
{
@@ -168,46 +158,6 @@ Task("TestPlainAuthentication")
168158
action: (BuildConfig buildConfig, Path testProject) =>
169159
RunTests(buildConfig, testProject, filter: "Category=\"PlainMechanism\""));
170160

171-
// currently we are not running this Task on Evergreen (only locally occassionally)
172-
Task("TestAllGuidRepresentations")
173-
.IsDependentOn("Build")
174-
.DoesForEach(
175-
items: GetFiles("./**/*.Tests.csproj")
176-
// .Where(name => name.ToString().Contains("Bson.Tests")) // uncomment to only test Bson
177-
.Where(name => !name.ToString().Contains("Atlas")),
178-
action: (BuildConfig buildConfig, Path testProject) =>
179-
{
180-
var modes = new string[][]
181-
{
182-
new[] { "V2", "Unspecified" },
183-
new[] { "V2", "JavaLegacy" },
184-
new[] { "V2", "Standard" },
185-
new[] { "V2", "PythonLegacy" },
186-
new[] { "V2", "CSharpLegacy" },
187-
new[] { "V3", "Unspecified" }
188-
};
189-
190-
foreach (var mode in modes)
191-
{
192-
var testWithGuidRepresentationMode = mode[0];
193-
var testWithGuidRepresentation = mode[1];
194-
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE={testWithGuidRepresentationMode}");
195-
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION={testWithGuidRepresentation}");
196-
197-
RunTests(
198-
buildConfig,
199-
testProject,
200-
settings =>
201-
{
202-
settings.EnvironmentVariables = new Dictionary<string, string>
203-
{
204-
{ "TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE", testWithGuidRepresentationMode },
205-
{ "TEST_WITH_DEFAULT_GUID_REPRESENTATION", testWithGuidRepresentation }
206-
};
207-
});
208-
}
209-
});
210-
211161
Task("TestAtlasConnectivity")
212162
.IsDependentOn("Build")
213163
.DoesForEach(

src/MongoDB.Bson/BsonDefaults.cs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,9 @@ public static class BsonDefaults
2929
private static IBsonSerializer __dynamicArraySerializer;
3030
private static bool __dynamicDocumentSerializerWasSet;
3131
private static IBsonSerializer __dynamicDocumentSerializer;
32-
private static GuidRepresentation __guidRepresentation = GuidRepresentation.CSharpLegacy;
33-
private static GuidRepresentationMode __guidRepresentationMode = GuidRepresentationMode.V2;
3432
private static int __maxDocumentSize = int.MaxValue;
3533
private static int __maxSerializationDepth = 100;
3634

37-
// static constructor
38-
static BsonDefaults()
39-
{
40-
var testWithDefaultGuidRepresentation = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION");
41-
if (testWithDefaultGuidRepresentation != null)
42-
{
43-
var _ = Enum.TryParse(testWithDefaultGuidRepresentation, out __guidRepresentation); // ignore errors
44-
}
45-
46-
var testWithDefaultGuidRepresentationMode = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE");
47-
if (testWithDefaultGuidRepresentationMode != null)
48-
{
49-
var _ = Enum.TryParse(testWithDefaultGuidRepresentationMode, out __guidRepresentationMode); // ignore errors
50-
}
51-
}
52-
5335
// public static properties
5436
/// <summary>
5537
/// Gets or sets the dynamic array serializer.
@@ -91,51 +73,6 @@ public static IBsonSerializer DynamicDocumentSerializer
9173
}
9274
}
9375

94-
/// <summary>
95-
/// Gets or sets the default representation to be used in serialization of
96-
/// Guids to the database.
97-
/// <seealso cref="MongoDB.Bson.GuidRepresentation"/>
98-
/// </summary>
99-
[Obsolete("Configure serializers instead.")]
100-
public static GuidRepresentation GuidRepresentation
101-
{
102-
get
103-
{
104-
if (BsonDefaults.GuidRepresentationMode != GuidRepresentationMode.V2)
105-
{
106-
throw new InvalidOperationException("BsonDefaults.GuidRepresentation can only be used when BsonDefaults.GuidRepresentationMode is V2.");
107-
}
108-
return __guidRepresentation;
109-
}
110-
set
111-
{
112-
if (BsonDefaults.GuidRepresentationMode != GuidRepresentationMode.V2)
113-
{
114-
throw new InvalidOperationException("BsonDefaults.GuidRepresentation can only be used when BsonDefaults.GuidRepresentationMode is V2.");
115-
}
116-
__guidRepresentation = value;
117-
}
118-
}
119-
120-
/// <summary>
121-
/// Gets or sets the default representation to be used in serialization of
122-
/// Guids to the database.
123-
/// <seealso cref="MongoDB.Bson.GuidRepresentation"/>
124-
/// </summary>
125-
[Obsolete("This property will be removed in a later release.")]
126-
public static GuidRepresentationMode GuidRepresentationMode
127-
{
128-
get { return __guidRepresentationMode; }
129-
set
130-
{
131-
__guidRepresentationMode = value;
132-
if (value == GuidRepresentationMode.V3)
133-
{
134-
__guidRepresentation = GuidRepresentation.Unspecified;
135-
}
136-
}
137-
}
138-
13976
/// <summary>
14077
/// Gets or sets the default max document size. The default is 4MiB.
14178
/// </summary>

src/MongoDB.Bson/IO/BsonBinaryReader.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,7 @@ public override BsonBinaryData ReadBinaryData()
153153
}
154154

155155
var bytes = _bsonStream.ReadBytes(size);
156-
157-
BsonBinaryData binaryData;
158-
if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
159-
{
160-
GuidRepresentation guidRepresentation;
161-
switch (subType)
162-
{
163-
case BsonBinarySubType.UuidLegacy: guidRepresentation = Settings.GuidRepresentation; break;
164-
case BsonBinarySubType.UuidStandard: guidRepresentation = GuidRepresentation.Standard; break;
165-
default: guidRepresentation = GuidRepresentation.Unspecified; break;
166-
}
167-
binaryData = new BsonBinaryData(bytes, subType, guidRepresentation);
168-
}
169-
else
170-
{
171-
binaryData = new BsonBinaryData(bytes, subType);
172-
}
156+
var binaryData = new BsonBinaryData(bytes, subType);
173157

174158
State = GetNextState();
175159
return binaryData;

src/MongoDB.Bson/IO/BsonBinaryReaderSettings.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ protected override BsonReaderSettings CloneImplementation()
139139
FixOldDateTimeMaxValueOnInput = _fixOldDateTimeMaxValueOnInput,
140140
MaxDocumentSize = _maxDocumentSize
141141
};
142-
#pragma warning disable 618
143-
if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
144-
{
145-
clone.GuidRepresentation = GuidRepresentation;
146-
}
147-
#pragma warning restore 618
148142

149143
return clone;
150144
}

src/MongoDB.Bson/IO/BsonBinaryWriter.cs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -169,39 +169,9 @@ public override void WriteBinaryData(BsonBinaryData binaryData)
169169

170170
var bytes = binaryData.Bytes;
171171
var subType = binaryData.SubType;
172-
switch (subType)
173-
{
174-
case BsonBinarySubType.OldBinary:
175-
if (Settings.FixOldBinarySubTypeOnOutput)
176-
{
177-
subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
178-
}
179-
break;
180-
case BsonBinarySubType.UuidLegacy:
181-
case BsonBinarySubType.UuidStandard:
182-
if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
183-
{
184-
if (Settings.GuidRepresentation != GuidRepresentation.Unspecified)
185-
{
186-
var expectedSubType = GuidConverter.GetSubType(Settings.GuidRepresentation);
187-
if (subType != expectedSubType)
188-
{
189-
var message = string.Format(
190-
"The GuidRepresentation for the writer is {0}, which requires the subType argument to be {1}, not {2}.",
191-
Settings.GuidRepresentation, expectedSubType, subType);
192-
throw new BsonSerializationException(message);
193-
}
194-
var guidRepresentation = binaryData.GuidRepresentation;
195-
if (guidRepresentation != Settings.GuidRepresentation)
196-
{
197-
var message = string.Format(
198-
"The GuidRepresentation for the writer is {0}, which requires the the guidRepresentation argument to also be {0}, not {1}.",
199-
Settings.GuidRepresentation, guidRepresentation);
200-
throw new BsonSerializationException(message);
201-
}
202-
}
203-
}
204-
break;
172+
if (subType == BsonBinarySubType.OldBinary && Settings.FixOldBinarySubTypeOnOutput)
173+
{
174+
subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
205175
}
206176

207177
_bsonStream.WriteBsonType(BsonType.Binary);

src/MongoDB.Bson/IO/BsonBinaryWriterSettings.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ protected override BsonWriterSettings CloneImplementation()
125125
MaxDocumentSize = _maxDocumentSize,
126126
MaxSerializationDepth = MaxSerializationDepth
127127
};
128-
#pragma warning disable 618
129-
if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
130-
{
131-
clone.GuidRepresentation = GuidRepresentation;
132-
}
133-
#pragma warning restore 618
134128
return clone;
135129
}
136130
}

src/MongoDB.Bson/IO/BsonDocumentReaderSettings.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ public BsonDocumentReaderSettings()
3434
{
3535
}
3636

37-
/// <summary>
38-
/// Initializes a new instance of the BsonDocumentReaderSettings class.
39-
/// </summary>
40-
/// <param name="guidRepresentation">The representation for Guids.</param>
41-
[Obsolete("Configure serializers instead.")]
42-
public BsonDocumentReaderSettings(GuidRepresentation guidRepresentation)
43-
: base(guidRepresentation)
44-
{
45-
}
46-
4737
// public static properties
4838
/// <summary>
4939
/// Gets or sets the default settings for a BsonDocumentReader.
@@ -79,12 +69,6 @@ public static BsonDocumentReaderSettings Defaults
7969
protected override BsonReaderSettings CloneImplementation()
8070
{
8171
var clone = new BsonDocumentReaderSettings();
82-
#pragma warning disable 618
83-
if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
84-
{
85-
clone.GuidRepresentation = GuidRepresentation;
86-
}
87-
#pragma warning restore 618
8872
return clone;
8973
}
9074
}

src/MongoDB.Bson/IO/BsonDocumentWriterSettings.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ public BsonDocumentWriterSettings()
3434
{
3535
}
3636

37-
/// <summary>
38-
/// Initializes a new instance of the BsonDocumentWriterSettings class.
39-
/// </summary>
40-
/// <param name="guidRepresentation">The representation for Guids.</param>
41-
[Obsolete("Configure serializers instead.")]
42-
public BsonDocumentWriterSettings(GuidRepresentation guidRepresentation)
43-
: base(guidRepresentation)
44-
{
45-
}
46-
4737
// public static properties
4838
/// <summary>
4939
/// Gets or sets the default BsonDocumentWriter settings.
@@ -82,12 +72,6 @@ protected override BsonWriterSettings CloneImplementation()
8272
{
8373
MaxSerializationDepth = MaxSerializationDepth
8474
};
85-
#pragma warning disable 618
86-
if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
87-
{
88-
clone.GuidRepresentation = GuidRepresentation;
89-
}
90-
#pragma warning restore 618
9175
return clone;
9276
}
9377
}

src/MongoDB.Bson/IO/BsonReaderSettings.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ namespace MongoDB.Bson.IO
2424
public abstract class BsonReaderSettings
2525
{
2626
// private fields
27-
#pragma warning disable 618
28-
private GuidRepresentation _guidRepresentation = BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2 ? BsonDefaults.GuidRepresentation : GuidRepresentation.Unspecified;
29-
#pragma warning restore 618
3027
private bool _isFrozen;
3128

3229
// constructors
@@ -37,46 +34,6 @@ protected BsonReaderSettings()
3734
{
3835
}
3936

40-
/// <summary>
41-
/// Initializes a new instance of the BsonReaderSettings class.
42-
/// </summary>
43-
/// <param name="guidRepresentation">The representation for Guids.</param>
44-
[Obsolete("Configure serializers instead.")]
45-
protected BsonReaderSettings(GuidRepresentation guidRepresentation)
46-
{
47-
if (BsonDefaults.GuidRepresentationMode != GuidRepresentationMode.V2)
48-
{
49-
throw new InvalidOperationException("BsonReaderSettings constructor with GuidRepresentation can only be used when GuidRepresentationMode is V2.");
50-
}
51-
_guidRepresentation = guidRepresentation;
52-
}
53-
54-
// public properties
55-
/// <summary>
56-
/// Gets or sets the representation for Guids.
57-
/// </summary>
58-
[Obsolete("Configure serializers instead.")]
59-
public GuidRepresentation GuidRepresentation
60-
{
61-
get
62-
{
63-
if (BsonDefaults.GuidRepresentationMode != GuidRepresentationMode.V2)
64-
{
65-
throw new InvalidOperationException("BsonReaderSettings.GuidRepresentation can only be used when GuidRepresentationMode is V2.");
66-
}
67-
return _guidRepresentation;
68-
}
69-
set
70-
{
71-
if (_isFrozen) { ThrowFrozenException(); }
72-
if (BsonDefaults.GuidRepresentationMode != GuidRepresentationMode.V2)
73-
{
74-
throw new InvalidOperationException("BsonReaderSettings.GuidRepresentation can only be used when GuidRepresentationMode is V2.");
75-
}
76-
_guidRepresentation = value;
77-
}
78-
}
79-
8037
/// <summary>
8138
/// Gets whether the settings are frozen.
8239
/// </summary>

0 commit comments

Comments
 (0)