Update unit test parameter nullability

Signed-off-by: Jon Skeet <jonskeet@google.com>
This commit is contained in:
Jon Skeet 2024-08-02 08:43:07 +01:00 committed by Jon Skeet
parent 4463f8e1ea
commit 95aeded775
8 changed files with 29 additions and 29 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2021 Cloud Native Foundation. // Copyright 2021 Cloud Native Foundation.
// Licensed under the Apache 2.0 license. // Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
@ -13,7 +13,7 @@ namespace CloudNative.CloudEvents.UnitTests
[InlineData(null)] [InlineData(null)]
[InlineData("bogus")] [InlineData("bogus")]
[InlineData("1")] [InlineData("1")]
public void FromVersionId_Unknown(string versionId) => public void FromVersionId_Unknown(string? versionId) =>
Assert.Null(CloudEventsSpecVersion.FromVersionId(versionId)); Assert.Null(CloudEventsSpecVersion.FromVersionId(versionId));
[Theory] [Theory]

View File

@ -1,4 +1,4 @@
// Copyright 2021 Cloud Native Foundation. // Copyright 2021 Cloud Native Foundation.
// Licensed under the Apache 2.0 license. // Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
@ -73,7 +73,7 @@ namespace CloudNative.CloudEvents.Core.UnitTests
[Theory] [Theory]
[InlineData(null)] [InlineData(null)]
[InlineData("text/plain")] [InlineData("text/plain")]
public void CreateContentTypeOrNull_WithContentType(string text) public void CreateContentTypeOrNull_WithContentType(string? text)
{ {
ContentType? ct = MimeUtilities.CreateContentTypeOrNull(text); ContentType? ct = MimeUtilities.CreateContentTypeOrNull(text);
Assert.Equal(text, ct?.ToString()); Assert.Equal(text, ct?.ToString());
@ -88,7 +88,7 @@ namespace CloudNative.CloudEvents.Core.UnitTests
[InlineData("application/cloudeventstrailing", true)] [InlineData("application/cloudeventstrailing", true)]
[InlineData("application/cloudevents-batch", false)] [InlineData("application/cloudevents-batch", false)]
[InlineData("application/cloudevents-batch+json", false)] [InlineData("application/cloudevents-batch+json", false)]
public void IsCloudEventsContentType(string contentType, bool expectedResult) => public void IsCloudEventsContentType(string? contentType, bool expectedResult) =>
Assert.Equal(expectedResult, MimeUtilities.IsCloudEventsContentType(contentType)); Assert.Equal(expectedResult, MimeUtilities.IsCloudEventsContentType(contentType));
[Theory] [Theory]
@ -101,7 +101,7 @@ namespace CloudNative.CloudEvents.Core.UnitTests
// It's not entirely clear that this *should* be true... // It's not entirely clear that this *should* be true...
[InlineData("application/cloudevents-batchtrailing", true)] [InlineData("application/cloudevents-batchtrailing", true)]
[InlineData("application/cloudevents-batch+json", true)] [InlineData("application/cloudevents-batch+json", true)]
public void IsCloudEventsBatchContentType(string contentType, bool expectedResult) => public void IsCloudEventsBatchContentType(string? contentType, bool expectedResult) =>
Assert.Equal(expectedResult, MimeUtilities.IsCloudEventsBatchContentType(contentType)); Assert.Equal(expectedResult, MimeUtilities.IsCloudEventsBatchContentType(contentType));
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright 2021 Cloud Native Foundation. // Copyright 2021 Cloud Native Foundation.
// Licensed under the Apache 2.0 license. // Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
@ -291,7 +291,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
var result = await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content); var result = await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content);
if (result.StatusCode != HttpStatusCode.NoContent) if (result.StatusCode != HttpStatusCode.NoContent)
{ {
throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult()); throw new InvalidOperationException(await result.Content.ReadAsStringAsync());
} }
} }
@ -392,7 +392,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
var result = (await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content)); var result = (await httpClient.PostAsync(new Uri(ListenerAddress + "ep"), content));
if (result.StatusCode != HttpStatusCode.NoContent) if (result.StatusCode != HttpStatusCode.NoContent)
{ {
throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult()); throw new InvalidOperationException(await result.Content.ReadAsStringAsync());
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) Cloud Native Foundation. // Copyright (c) Cloud Native Foundation.
// Licensed under the Apache 2.0 license. // Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
@ -135,7 +135,7 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
[InlineData(MediaTypeNames.Application.Xml, "")] [InlineData(MediaTypeNames.Application.Xml, "")]
[InlineData(MediaTypeNames.Text.Plain, "")] [InlineData(MediaTypeNames.Text.Plain, "")]
[InlineData(null, null)] [InlineData(null, null)]
public void KafkaBinaryMessageTombstoneTest(string contentType, object? expectedDecodedResult) public void KafkaBinaryMessageTombstoneTest(string? contentType, object? expectedDecodedResult)
{ {
var jsonEventFormatter = new JsonEventFormatter(); var jsonEventFormatter = new JsonEventFormatter();
var cloudEvent = new CloudEvent(Partitioning.AllAttributes) var cloudEvent = new CloudEvent(Partitioning.AllAttributes)
@ -253,4 +253,4 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
} }
} }
} }
} }

View File

@ -706,7 +706,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("text/plain")] [InlineData("text/plain")]
[InlineData("application/binary")] [InlineData("application/binary")]
public void DecodeStructuredModeMessage_NoData(string contentType) public void DecodeStructuredModeMessage_NoData(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -740,7 +740,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("text/plain")] [InlineData("text/plain")]
[InlineData("application/binary")] [InlineData("application/binary")]
public void DecodeStructuredModeMessage_Base64(string contentType) public void DecodeStructuredModeMessage_Base64(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -768,7 +768,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
[InlineData(null)] [InlineData(null)]
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("application/json; charset=utf-8")] [InlineData("application/json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType) public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -787,7 +787,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("application/xyz+json")] [InlineData("application/xyz+json")]
[InlineData("application/xyz+json; charset=utf-8")] [InlineData("application/xyz+json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType) public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -1215,4 +1215,4 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
return formatter.DecodeBatchModeMessage(bytes, s_jsonCloudEventContentType, null); return formatter.DecodeBatchModeMessage(bytes, s_jsonCloudEventContentType, null);
} }
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright 2022 Cloud Native Foundation. // Copyright 2022 Cloud Native Foundation.
// Licensed under the Apache 2.0 license. // Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
@ -201,7 +201,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
[InlineData("utf-8")] [InlineData("utf-8")]
[InlineData("iso-8859-1")] [InlineData("iso-8859-1")]
[InlineData(null)] [InlineData(null)]
public void EncodeBinaryModeData_String_TextContentType(string charset) public void EncodeBinaryModeData_String_TextContentType(string? charset)
{ {
string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations
var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset); var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
@ -552,7 +552,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
[InlineData("utf-8")] [InlineData("utf-8")]
[InlineData("iso-8859-1")] [InlineData("iso-8859-1")]
[InlineData(null)] [InlineData(null)]
public void DecodeBinaryModeEventData_Text(string charset) public void DecodeBinaryModeEventData_Text(string? charset)
{ {
string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations
var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset); var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
@ -566,7 +566,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
[Theory] [Theory]
[InlineData("application/json")] [InlineData("application/json")]
[InlineData(null)] [InlineData(null)]
public void DecodeBinaryModeData_NonTextContentType(string contentType) public void DecodeBinaryModeData_NonTextContentType(string? contentType)
{ {
var bytes = Encoding.UTF8.GetBytes("{}"); var bytes = Encoding.UTF8.GetBytes("{}");
var data = DecodeBinaryModeEventData(bytes, contentType); var data = DecodeBinaryModeEventData(bytes, contentType);
@ -670,7 +670,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
// Utility methods // Utility methods
private static object? DecodeBinaryModeEventData(byte[] bytes, string contentType) private static object? DecodeBinaryModeEventData(byte[] bytes, string? contentType)
{ {
var cloudEvent = new CloudEvent().PopulateRequiredAttributes(); var cloudEvent = new CloudEvent().PopulateRequiredAttributes();
cloudEvent.DataContentType = contentType; cloudEvent.DataContentType = contentType;

View File

@ -726,7 +726,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("text/plain")] [InlineData("text/plain")]
[InlineData("application/binary")] [InlineData("application/binary")]
public void DecodeStructuredModeMessage_NoData(string contentType) public void DecodeStructuredModeMessage_NoData(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -760,7 +760,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("text/plain")] [InlineData("text/plain")]
[InlineData("application/binary")] [InlineData("application/binary")]
public void DecodeStructuredModeMessage_Base64(string contentType) public void DecodeStructuredModeMessage_Base64(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -788,7 +788,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
[InlineData(null)] [InlineData(null)]
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("application/json; charset=utf-8")] [InlineData("application/json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType) public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -807,7 +807,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
[InlineData("application/json")] [InlineData("application/json")]
[InlineData("application/xyz+json")] [InlineData("application/xyz+json")]
[InlineData("application/xyz+json; charset=utf-8")] [InlineData("application/xyz+json; charset=utf-8")]
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType) public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string? contentType)
{ {
var obj = CreateMinimalValidJObject(); var obj = CreateMinimalValidJObject();
if (contentType is object) if (contentType is object)
@ -1227,4 +1227,4 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
writer.WriteStringValue(value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); writer.WriteStringValue(value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
} }
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright 2021 Cloud Native Foundation. // Copyright 2021 Cloud Native Foundation.
// Licensed under the Apache 2.0 license. // Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
@ -153,7 +153,7 @@ namespace CloudNative.CloudEvents.UnitTests
} }
if (expected is null || actual is null) if (expected is null || actual is null)
{ {
Assert.True(false, "Expected both values to be null, or neither to be null"); Assert.Fail("Expected both values to be null, or neither to be null");
} }
AssertTimestampsEqual(expected!.Value, actual!.Value); AssertTimestampsEqual(expected!.Value, actual!.Value);
} }