Skip to content

Commit cb7628f

Browse files
authored
Support DBNull in netstandard1.3 assembly (#394)
* Support `DBNull` in `netstandard1.3` assembly - available from the System.Data.Common package - extend `DBNull` testing to include `net6.0` - s/NETCOREAPP/NETCOREAPP2_1/ where possible - fix comments in `HttpValueCollectionTest` - comments about `DBNull` there were incorrect * !fixup! Add `$(System.JobId)` to artifact names - `publish` / `PublishPipelineArtifact@1` task doesn't overwrite an existing build artifact - bit different from `PublishBuildArtifacts@1` - follow guidance at <https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml-task#q-can-i-delete-pipeline-artifacts-when-re-running-failed-jobs>
1 parent d56a97f commit cb7628f

File tree

8 files changed

+13
-18
lines changed

8 files changed

+13
-18
lines changed

azure-pipelines.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
displayName: Build
8080

8181
- publish: ./bin/$(_Configuration)/Test/TestResults/
82-
artifact: $(_Configuration) Test Results
82+
artifact: $(_Configuration) Test Results $(System.JobId)
8383
condition: and(always(), ne(variables._BuildTarget, 'Build'))
8484
continueOnError: true
8585
displayName: Upload test results
@@ -95,6 +95,6 @@ jobs:
9595
testRunTitle: $(_Configuration)
9696

9797
- publish: ./artifacts/
98-
artifact: $(_Configuration) Logs
98+
artifact: $(_Configuration) Logs $(System.JobId)
9999
condition: always()
100100
displayName: Upload logs

src/System.Net.Http.Formatting.ns1_3/System.Net.Http.Formatting.ns1_3.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<ItemGroup>
1818
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
1919
<PackageReference Include="System.ComponentModel.EventBasedAsync" Version="4.3.0" />
20+
<PackageReference Include="System.Data.Common" Version="4.3.0" />
2021
<PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
2122
<PackageReference Include="System.Memory" Version="4.5.5" />
2223
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public sealed override int MaxDepth
7373
}
7474
}
7575

76-
#if !NETSTANDARD1_3 // DBNull not supported in netstandard1.3; no need to override there
7776
/// <inheritdoc />
7877
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
7978
{
@@ -101,7 +100,6 @@ public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, H
101100
return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);
102101
}
103102
}
104-
#endif
105103

106104
/// <inheritdoc />
107105
public override object ReadFromStream(Type type, Stream readStream, Encoding effectiveEncoding,
@@ -234,14 +232,13 @@ public override void WriteToStream(Type type, object value, Stream writeStream,
234232

235233
if (value == null)
236234
{
237-
// Cannot serialize null at the top level. Json.Net throws Newtonsoft.Json.JsonWriterException : Error
238-
// writing Null value. BSON must start with an Object or Array. Path ''. Fortunately
235+
// Cannot serialize null at the top level. Json.Net throws Newtonsoft.Json.JsonWriterException : Error
236+
// writing Null value. BSON must start with an Object or Array. Path ''. Fortunately
239237
// BaseJsonMediaTypeFormatter.ReadFromStream(Type, Stream, HttpContent, IFormatterLogger) treats zero-
240238
// length content as null or the default value of a struct.
241239
return;
242240
}
243241

244-
#if !NETSTANDARD1_3 // DBNull not supported in netstandard1.3
245242
if (value == DBNull.Value)
246243
{
247244
// ReadFromStreamAsync() override above converts null to DBNull.Value if given Type is DBNull; normally
@@ -252,7 +249,6 @@ public override void WriteToStream(Type type, object value, Stream writeStream,
252249
// rather than null, and not meet the receiver's expectations.
253250
return;
254251
}
255-
#endif
256252

257253
// See comments in ReadFromStream() above about this special case and the need to include byte[] in it.
258254
// Using runtime type here because Json.Net will throw during serialization whenever it cannot handle the

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_PerhapsJObjec
392392
}
393393
}
394394

395-
#if !Testing_NetStandard1_3 // DBNull not supported in netstandard1.3
396395
// Test alternate null value
397396
[Theory]
398397
[TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AllSingleInstances)]
@@ -408,7 +407,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull(
408407
Assert.Null(readObj);
409408
}
410409

411-
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1 except at top level (using BsonMediaTypeformatter special case).
410+
#if !NETCOREAPP2_1 // DBNull not serializable on .NET Core 2.1 except at top level (using BsonMediaTypeformatter special case).
412411
[Theory]
413412
[TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AsDictionary)]
414413
public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull_Dictionary(Type variationType, object testData)
@@ -512,7 +511,6 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNull()
512511
// Only BSON case where DBNull.Value round-trips
513512
Assert.Equal(testData, readObj);
514513
}
515-
#endif
516514

517515
private class TestBsonMediaTypeFormatter : BsonMediaTypeFormatter
518516
{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_KnownTypes(Ty
159159
}
160160
}
161161

162-
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
162+
#if !NETCOREAPP2_1 // DBNull not serializable on .NET Core 2.1.
163163
// Test alternate null value
164164
[Fact]
165165
public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNull()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync(Type variatio
367367
}
368368
}
369369

370-
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
370+
#if !NETCOREAPP2_1 // DBNull not serializable on .NET Core 2.1.
371371
// Test alternate null value; always serialized as "null"
372372
[Theory]
373373
[TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AllSingleInstances)]

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class XmlMediaTypeFormatterTests : MediaTypeFormatterTestBase<XmlMediaTyp
3636
Int32.MaxValue,
3737
Int64.MinValue,
3838
Int64.MaxValue,
39-
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
39+
#if !NETCOREAPP2_1 // DBNull not serializable on .NET Core 2.1.
4040
DBNull.Value,
4141
#endif
4242
});
@@ -478,7 +478,7 @@ public async Task ReadFromStream_AsyncRoundTripsWriteToStreamUsingDataContractSe
478478
}
479479
}
480480

481-
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
481+
#if !NETCOREAPP2_1 // DBNull not serializable on .NET Core 2.1.
482482
[Fact]
483483
public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsyncUsingDataContractSerializer_DBNull()
484484
{

test/System.Net.Http.Formatting.Test/Internal/HttpValueCollectionTest.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace System.Net.Http.Internal
1212
{
1313
public class HttpValueCollectionTest
1414
{
15-
#if !NETCOREAPP // Unused on .NET Core 2.1.
15+
#if !NETCOREAPP // Unused on .NET Core.
1616
private static readonly int _maxCollectionKeys = 1000;
1717
#endif
1818

@@ -21,7 +21,7 @@ private static HttpValueCollection CreateInstance()
2121
return HttpValueCollection.Create();
2222
}
2323

24-
#if !NETCOREAPP
24+
#if !NETCOREAPP // Unsupported on .NET Core.
2525
private static void RunInIsolation(Action action)
2626
{
2727
AppDomainUtils.RunInSeparateAppDomain(action);
@@ -132,7 +132,7 @@ public void Create_CreatesEmptyCollection()
132132
Assert.Empty(nvc);
133133
}
134134

135-
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
135+
#if !NETCOREAPP // Able to run on a separate AppDomain only on .NET Framework.
136136
// This set of tests requires running on a separate appdomain so we don't
137137
// touch the static property MediaTypeFormatter.MaxHttpCollectionKeys.
138138
[Fact]

0 commit comments

Comments
 (0)