Skip to content

Commit 388abe1

Browse files
committed
React to Newtonsoft.Json changes
- react to `BsonReader`, `BsonWriter` deprecation - one of our `DateTime` tests now consistently hits `5` errors - `s/True/true/` also consistent now in another test
1 parent 1585561 commit 388abe1

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,13 @@ public override JsonReader CreateJsonReader(Type type, Stream readStream, Encodi
200200
throw Error.ArgumentNull("effectiveEncoding");
201201
}
202202

203+
#if !NEWTONSOFTJSON10
204+
#pragma warning disable CS0618 // Type or member is obsolete
205+
#endif
203206
BsonReader reader = new BsonReader(new BinaryReader(readStream, effectiveEncoding));
207+
#if !NEWTONSOFTJSON10
208+
#pragma warning restore CS0618 // Type or member is obsolete
209+
#endif
204210

205211
try
206212
{
@@ -297,7 +303,13 @@ public override JsonWriter CreateJsonWriter(Type type, Stream writeStream, Encod
297303
throw Error.ArgumentNull("effectiveEncoding");
298304
}
299305

306+
#if !NEWTONSOFTJSON10
307+
#pragma warning disable CS0618 // Type or member is obsolete
308+
#endif
300309
return new BsonWriter(new BinaryWriter(writeStream, effectiveEncoding));
310+
#if !NEWTONSOFTJSON10
311+
#pragma warning restore CS0618 // Type or member is obsolete
312+
#endif
301313
}
302314

303315
// Return true if Json.Net will likely convert value of given type to a Json primitive, not JsonArray nor

test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ public async Task FormatterThrowsOnReadWithInvalidContent()
340340
stream.Seek(0L, SeekOrigin.Begin);
341341

342342
// Act & Assert
343-
await Assert.ThrowsAsync<OverflowException>(
343+
await Assert.ThrowsAsync<JsonReaderException>(
344344
() => formatter.ReadFromStreamAsync(variationType, stream, content, null),
345-
"Value was either too large or too small for a Decimal.");
345+
"Could not convert to decimal: 7.92281625142643E+28. Path 'Value'.");
346346
}
347347

348348
[Theory]

test/System.Net.Http.Formatting.Test/Formatting/JsonNetValidationTest.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ public static TheoryDataSet<string, Type, int> Theories
2828
{"\"foo\"", typeof(DateTime), 1},
2929

3030
{"[\"a\",\"b\",\"45\",34]", typeof(int[]), 2},
31-
{
32-
"[\"a\",\"b\",\"45\",34]",
33-
typeof(DateTime[]),
34-
#if NEWTONSOFTJSON10 // Json.NET 10 detects an additional error over earlier versions.
35-
5
36-
#else
37-
4
38-
#endif
39-
},
31+
{"[\"a\",\"b\",\"45\",34]", typeof(DateTime[]), 5},
4032

4133
// Required members
4234

test/System.Web.Http.Test/Tracing/Tracers/FormatterParameterBindingTracerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public async Task ExecuteBindingAsync_Traces_And_Invokes_Inner_ReadAsync()
125125

126126
// Assert
127127
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
128-
Assert.Equal("True", actionContext.ActionArguments["paramName"]);
128+
Assert.Equal("true", actionContext.ActionArguments["paramName"]);
129129
}
130130

131131
[Fact]

0 commit comments

Comments
 (0)