Update unit test parameter nullability
Signed-off-by: Jon Skeet <jonskeet@google.com>
This commit is contained in:
parent
4463f8e1ea
commit
95aeded775
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
[InlineData(null)]
|
||||
[InlineData("bogus")]
|
||||
[InlineData("1")]
|
||||
public void FromVersionId_Unknown(string versionId) =>
|
||||
public void FromVersionId_Unknown(string? versionId) =>
|
||||
Assert.Null(CloudEventsSpecVersion.FromVersionId(versionId));
|
||||
|
||||
[Theory]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace CloudNative.CloudEvents.Core.UnitTests
|
|||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("text/plain")]
|
||||
public void CreateContentTypeOrNull_WithContentType(string text)
|
||||
public void CreateContentTypeOrNull_WithContentType(string? text)
|
||||
{
|
||||
ContentType? ct = MimeUtilities.CreateContentTypeOrNull(text);
|
||||
Assert.Equal(text, ct?.ToString());
|
||||
|
@ -88,7 +88,7 @@ namespace CloudNative.CloudEvents.Core.UnitTests
|
|||
[InlineData("application/cloudeventstrailing", true)]
|
||||
[InlineData("application/cloudevents-batch", 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));
|
||||
|
||||
[Theory]
|
||||
|
@ -101,7 +101,7 @@ namespace CloudNative.CloudEvents.Core.UnitTests
|
|||
// It's not entirely clear that this *should* be true...
|
||||
[InlineData("application/cloudevents-batchtrailing", 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// 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);
|
||||
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));
|
||||
if (result.StatusCode != HttpStatusCode.NoContent)
|
||||
{
|
||||
throw new InvalidOperationException(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());
|
||||
throw new InvalidOperationException(await result.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Cloud Native Foundation.
|
||||
// Copyright (c) Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// 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.Text.Plain, "")]
|
||||
[InlineData(null, null)]
|
||||
public void KafkaBinaryMessageTombstoneTest(string contentType, object? expectedDecodedResult)
|
||||
public void KafkaBinaryMessageTombstoneTest(string? contentType, object? expectedDecodedResult)
|
||||
{
|
||||
var jsonEventFormatter = new JsonEventFormatter();
|
||||
var cloudEvent = new CloudEvent(Partitioning.AllAttributes)
|
||||
|
@ -253,4 +253,4 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -706,7 +706,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
[InlineData("application/json")]
|
||||
[InlineData("text/plain")]
|
||||
[InlineData("application/binary")]
|
||||
public void DecodeStructuredModeMessage_NoData(string contentType)
|
||||
public void DecodeStructuredModeMessage_NoData(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -740,7 +740,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
[InlineData("application/json")]
|
||||
[InlineData("text/plain")]
|
||||
[InlineData("application/binary")]
|
||||
public void DecodeStructuredModeMessage_Base64(string contentType)
|
||||
public void DecodeStructuredModeMessage_Base64(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -768,7 +768,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
[InlineData(null)]
|
||||
[InlineData("application/json")]
|
||||
[InlineData("application/json; charset=utf-8")]
|
||||
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
|
||||
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -787,7 +787,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
[InlineData("application/json")]
|
||||
[InlineData("application/xyz+json")]
|
||||
[InlineData("application/xyz+json; charset=utf-8")]
|
||||
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
|
||||
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -1215,4 +1215,4 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
return formatter.DecodeBatchModeMessage(bytes, s_jsonCloudEventContentType, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2022 Cloud Native Foundation.
|
||||
// Copyright 2022 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
|
@ -201,7 +201,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
|
|||
[InlineData("utf-8")]
|
||||
[InlineData("iso-8859-1")]
|
||||
[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
|
||||
var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
|
||||
|
@ -552,7 +552,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
|
|||
[InlineData("utf-8")]
|
||||
[InlineData("iso-8859-1")]
|
||||
[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
|
||||
var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset);
|
||||
|
@ -566,7 +566,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
|
|||
[Theory]
|
||||
[InlineData("application/json")]
|
||||
[InlineData(null)]
|
||||
public void DecodeBinaryModeData_NonTextContentType(string contentType)
|
||||
public void DecodeBinaryModeData_NonTextContentType(string? contentType)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes("{}");
|
||||
var data = DecodeBinaryModeEventData(bytes, contentType);
|
||||
|
@ -670,7 +670,7 @@ namespace CloudNative.CloudEvents.Protobuf.UnitTests
|
|||
|
||||
// Utility methods
|
||||
|
||||
private static object? DecodeBinaryModeEventData(byte[] bytes, string contentType)
|
||||
private static object? DecodeBinaryModeEventData(byte[] bytes, string? contentType)
|
||||
{
|
||||
var cloudEvent = new CloudEvent().PopulateRequiredAttributes();
|
||||
cloudEvent.DataContentType = contentType;
|
||||
|
|
|
@ -726,7 +726,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
[InlineData("application/json")]
|
||||
[InlineData("text/plain")]
|
||||
[InlineData("application/binary")]
|
||||
public void DecodeStructuredModeMessage_NoData(string contentType)
|
||||
public void DecodeStructuredModeMessage_NoData(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -760,7 +760,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
[InlineData("application/json")]
|
||||
[InlineData("text/plain")]
|
||||
[InlineData("application/binary")]
|
||||
public void DecodeStructuredModeMessage_Base64(string contentType)
|
||||
public void DecodeStructuredModeMessage_Base64(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -788,7 +788,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
[InlineData(null)]
|
||||
[InlineData("application/json")]
|
||||
[InlineData("application/json; charset=utf-8")]
|
||||
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string contentType)
|
||||
public void DecodeStructuredModeMessage_JsonContentType_JsonStringToken(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -807,7 +807,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
[InlineData("application/json")]
|
||||
[InlineData("application/xyz+json")]
|
||||
[InlineData("application/xyz+json; charset=utf-8")]
|
||||
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string contentType)
|
||||
public void DecodeStructuredModeMessage_JsonContentType_NonStringValue(string? contentType)
|
||||
{
|
||||
var obj = CreateMinimalValidJObject();
|
||||
if (contentType is object)
|
||||
|
@ -1227,4 +1227,4 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
writer.WriteStringValue(value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue