Skip to content

Commit 95aeded

Browse files
committed
Update unit test parameter nullability
Signed-off-by: Jon Skeet <[email protected]>
1 parent 4463f8e commit 95aeded

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

test/CloudNative.CloudEvents.UnitTests/CloudEventsSpecVersionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Cloud Native Foundation.
1+
// Copyright 2021 Cloud Native Foundation.
22
// Licensed under the Apache 2.0 license.
33
// See LICENSE file in the project root for full license information.
44

@@ -13,7 +13,7 @@ public class CloudEventsSpecVersionTest
1313
[InlineData(null)]
1414
[InlineData("bogus")]
1515
[InlineData("1")]
16-
public void FromVersionId_Unknown(string versionId) =>
16+
public void FromVersionId_Unknown(string? versionId) =>
1717
Assert.Null(CloudEventsSpecVersion.FromVersionId(versionId));
1818

1919
[Theory]

test/CloudNative.CloudEvents.UnitTests/Core/MimeUtilitiesTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Cloud Native Foundation.
1+
// Copyright 2021 Cloud Native Foundation.
22
// Licensed under the Apache 2.0 license.
33
// See LICENSE file in the project root for full license information.
44

@@ -73,7 +73,7 @@ public void ContentTypeGetEncoding_NoCharSet()
7373
[Theory]
7474
[InlineData(null)]
7575
[InlineData("text/plain")]
76-
public void CreateContentTypeOrNull_WithContentType(string text)
76+
public void CreateContentTypeOrNull_WithContentType(string? text)
7777
{
7878
ContentType? ct = MimeUtilities.CreateContentTypeOrNull(text);
7979
Assert.Equal(text, ct?.ToString());
@@ -88,7 +88,7 @@ public void CreateContentTypeOrNull_WithContentType(string text)
8888
[InlineData("application/cloudeventstrailing", true)]
8989
[InlineData("application/cloudevents-batch", false)]
9090
[InlineData("application/cloudevents-batch+json", false)]
91-
public void IsCloudEventsContentType(string contentType, bool expectedResult) =>
91+
public void IsCloudEventsContentType(string? contentType, bool expectedResult) =>
9292
Assert.Equal(expectedResult, MimeUtilities.IsCloudEventsContentType(contentType));
9393

9494
[Theory]
@@ -101,7 +101,7 @@ public void IsCloudEventsContentType(string contentType, bool expectedResult) =>
101101
// It's not entirely clear that this *should* be true...
102102
[InlineData("application/cloudevents-batchtrailing", true)]
103103
[InlineData("application/cloudevents-batch+json", true)]
104-
public void IsCloudEventsBatchContentType(string contentType, bool expectedResult) =>
104+
public void IsCloudEventsBatchContentType(string? contentType, bool expectedResult) =>
105105
Assert.Equal(expectedResult, MimeUtilities.IsCloudEventsBatchContentType(contentType));
106106
}
107107
}

test/CloudNative.CloudEvents.UnitTests/Http/HttpClientExtensionsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Cloud Native Foundation.
1+
// Copyright 2021 Cloud Native Foundation.
22
// Licensed under the Apache 2.0 license.
33
// See LICENSE file in the project root for full license information.
44

@@ -291,7 +291,7 @@ public async Task HttpBinaryClientSendTest()
291291
var result = await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content);
292292
if (result.StatusCode != HttpStatusCode.NoContent)
293293
{
294-
throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
294+
throw new InvalidOperationException(await result.Content.ReadAsStringAsync());
295295
}
296296
}
297297

@@ -392,7 +392,7 @@ public async Task HttpStructuredClientSendTest()
392392
var result = (await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content));
393393
if (result.StatusCode != HttpStatusCode.NoContent)
394394
{
395-
throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
395+
throw new InvalidOperationException(await result.Content.ReadAsStringAsync());
396396
}
397397
}
398398

test/CloudNative.CloudEvents.UnitTests/Kafka/KafkaTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Cloud Native Foundation.
1+
// Copyright (c) Cloud Native Foundation.
22
// Licensed under the Apache 2.0 license.
33
// See LICENSE file in the project root for full license information.
44

@@ -135,7 +135,7 @@ public void KafkaBinaryMessageTest()
135135
[InlineData(MediaTypeNames.Application.Xml, "")]
136136
[InlineData(MediaTypeNames.Text.Plain, "")]
137137
[InlineData(null, null)]
138-
public void KafkaBinaryMessageTombstoneTest(string contentType, object? expectedDecodedResult)
138+
public void KafkaBinaryMessageTombstoneTest(string? contentType, object? expectedDecodedResult)
139139
{
140140
var jsonEventFormatter = new JsonEventFormatter();
141141
var cloudEvent = new CloudEvent(Partitioning.AllAttributes)
@@ -253,4 +253,4 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
253253
}
254254
}
255255
}
256-
}
256+
}

test/CloudNative.CloudEvents.UnitTests/NewtonsoftJson/JsonEventFormatterTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ public void DecodeStructuredModeMessage_Null()
706706
[InlineData("application/json")]
707707
[InlineData("text/plain")]
708708
[InlineData("application/binary")]
709-
public void DecodeStructuredModeMessage_NoData(string contentType)
709+
public void DecodeStructuredModeMessage_NoData(string? contentType)
710710
{
711711
var obj = CreateMinimalValidJObject();
712712
if (contentType is object)
@@ -740,7 +740,7 @@ public void DecodeStructuredModeMessage_DataBase64NonString()
740740
[InlineData("application/json")]
741741
[InlineData("text/plain")]
742742
[InlineData("application/binary")]
743-
public void DecodeStructuredModeMessage_Base64(string contentType)
743+
public void DecodeStructuredModeMessage_Base64(string? contentType)
744744
{
745745
var obj = CreateMinimalValidJObject();
746746
if (contentType is object)
@@ -768,7 +768,7 @@ public void DecodeStructuredModeMessage_NonJsonContentType_JsonStringToken(strin
768768
[InlineData(null)]
769769
[InlineData("application/json")]
770770
[InlineData("application/json; charset=utf-8")]
771-
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
771+
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string? contentType)
772772
{
773773
var obj = CreateMinimalValidJObject();
774774
if (contentType is object)
@@ -787,7 +787,7 @@ public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string c
787787
[InlineData("application/json")]
788788
[InlineData("application/xyz+json")]
789789
[InlineData("application/xyz+json; charset=utf-8")]
790-
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
790+
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string? contentType)
791791
{
792792
var obj = CreateMinimalValidJObject();
793793
if (contentType is object)
@@ -1215,4 +1215,4 @@ private static IReadOnlyList<CloudEvent> DecodeBatchModeMessage(JArray array)
12151215
return formatter.DecodeBatchModeMessage(bytes, s_jsonCloudEventContentType, null);
12161216
}
12171217
}
1218-
}
1218+
}

test/CloudNative.CloudEvents.UnitTests/Protobuf/ProtobufEventFormatterTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Cloud Native Foundation.
1+
// Copyright 2022 Cloud Native Foundation.
22
// Licensed under the Apache 2.0 license.
33
// See LICENSE file in the project root for full license information.
44

@@ -201,7 +201,7 @@ public void EncodeBinaryModeData_Bytes()
201201
[InlineData("utf-8")]
202202
[InlineData("iso-8859-1")]
203203
[InlineData(null)]
204-
public void EncodeBinaryModeData_String_TextContentType(string charset)
204+
public void EncodeBinaryModeData_String_TextContentType(string? charset)
205205
{
206206
string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations
207207
var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
@@ -552,7 +552,7 @@ public void ConvertFromProto_Invalid_NoSource()
552552
[InlineData("utf-8")]
553553
[InlineData("iso-8859-1")]
554554
[InlineData(null)]
555-
public void DecodeBinaryModeEventData_Text(string charset)
555+
public void DecodeBinaryModeEventData_Text(string? charset)
556556
{
557557
string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations
558558
var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
@@ -566,7 +566,7 @@ public void DecodeBinaryModeEventData_Text(string charset)
566566
[Theory]
567567
[InlineData("application/json")]
568568
[InlineData(null)]
569-
public void DecodeBinaryModeData_NonTextContentType(string contentType)
569+
public void DecodeBinaryModeData_NonTextContentType(string? contentType)
570570
{
571571
var bytes = Encoding.UTF8.GetBytes("{}");
572572
var data = DecodeBinaryModeEventData(bytes, contentType);
@@ -670,7 +670,7 @@ public void DecodeBatchMode_Multiple()
670670

671671
// Utility methods
672672

673-
private static object? DecodeBinaryModeEventData(byte[] bytes, string contentType)
673+
private static object? DecodeBinaryModeEventData(byte[] bytes, string? contentType)
674674
{
675675
var cloudEvent = new CloudEvent().PopulateRequiredAttributes();
676676
cloudEvent.DataContentType = contentType;

test/CloudNative.CloudEvents.UnitTests/SystemTextJson/JsonEventFormatterTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ public void DecodeStructuredModeMessage_Null()
726726
[InlineData("application/json")]
727727
[InlineData("text/plain")]
728728
[InlineData("application/binary")]
729-
public void DecodeStructuredModeMessage_NoData(string contentType)
729+
public void DecodeStructuredModeMessage_NoData(string? contentType)
730730
{
731731
var obj = CreateMinimalValidJObject();
732732
if (contentType is object)
@@ -760,7 +760,7 @@ public void DecodeStructuredModeMessage_DataBase64NonString()
760760
[InlineData("application/json")]
761761
[InlineData("text/plain")]
762762
[InlineData("application/binary")]
763-
public void DecodeStructuredModeMessage_Base64(string contentType)
763+
public void DecodeStructuredModeMessage_Base64(string? contentType)
764764
{
765765
var obj = CreateMinimalValidJObject();
766766
if (contentType is object)
@@ -788,7 +788,7 @@ public void DecodeStructuredModeMessage_NonJsonContentType_JsonStringToken(strin
788788
[InlineData(null)]
789789
[InlineData("application/json")]
790790
[InlineData("application/json; charset=utf-8")]
791-
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
791+
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string? contentType)
792792
{
793793
var obj = CreateMinimalValidJObject();
794794
if (contentType is object)
@@ -807,7 +807,7 @@ public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string c
807807
[InlineData("application/json")]
808808
[InlineData("application/xyz+json")]
809809
[InlineData("application/xyz+json; charset=utf-8")]
810-
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
810+
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string? contentType)
811811
{
812812
var obj = CreateMinimalValidJObject();
813813
if (contentType is object)
@@ -1227,4 +1227,4 @@ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializer
12271227
writer.WriteStringValue(value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
12281228
}
12291229
}
1230-
}
1230+
}

test/CloudNative.CloudEvents.UnitTests/TestHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Cloud Native Foundation.
1+
// Copyright 2021 Cloud Native Foundation.
22
// Licensed under the Apache 2.0 license.
33
// See LICENSE file in the project root for full license information.
44

@@ -153,7 +153,7 @@ internal static void AssertTimestampsEqual(DateTimeOffset? expected, DateTimeOff
153153
}
154154
if (expected is null || actual is null)
155155
{
156-
Assert.True(false, "Expected both values to be null, or neither to be null");
156+
Assert.Fail("Expected both values to be null, or neither to be null");
157157
}
158158
AssertTimestampsEqual(expected!.Value, actual!.Value);
159159
}

0 commit comments

Comments
 (0)