diff --git a/test/CloudNative.CloudEvents.UnitTests/CloudEventsSpecVersionTest.cs b/test/CloudNative.CloudEvents.UnitTests/CloudEventsSpecVersionTest.cs index 4d8252b..4701f06 100644 --- a/test/CloudNative.CloudEvents.UnitTests/CloudEventsSpecVersionTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/CloudEventsSpecVersionTest.cs @@ -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] diff --git a/test/CloudNative.CloudEvents.UnitTests/Core/MimeUtilitiesTest.cs b/test/CloudNative.CloudEvents.UnitTests/Core/MimeUtilitiesTest.cs index 8e053ff..e7c18bd 100644 --- a/test/CloudNative.CloudEvents.UnitTests/Core/MimeUtilitiesTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/Core/MimeUtilitiesTest.cs @@ -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)); } } diff --git a/test/CloudNative.CloudEvents.UnitTests/Http/HttpClientExtensionsTest.cs b/test/CloudNative.CloudEvents.UnitTests/Http/HttpClientExtensionsTest.cs index d711a80..de77f8d 100644 --- a/test/CloudNative.CloudEvents.UnitTests/Http/HttpClientExtensionsTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/Http/HttpClientExtensionsTest.cs @@ -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()); } } diff --git a/test/CloudNative.CloudEvents.UnitTests/Kafka/KafkaTest.cs b/test/CloudNative.CloudEvents.UnitTests/Kafka/KafkaTest.cs index 7d1b258..b8bcc0c 100644 --- a/test/CloudNative.CloudEvents.UnitTests/Kafka/KafkaTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/Kafka/KafkaTest.cs @@ -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 } } } -} \ No newline at end of file +} diff --git a/test/CloudNative.CloudEvents.UnitTests/NewtonsoftJson/JsonEventFormatterTest.cs b/test/CloudNative.CloudEvents.UnitTests/NewtonsoftJson/JsonEventFormatterTest.cs index f0abb62..4ae806a 100644 --- a/test/CloudNative.CloudEvents.UnitTests/NewtonsoftJson/JsonEventFormatterTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/NewtonsoftJson/JsonEventFormatterTest.cs @@ -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); } } -} \ No newline at end of file +} diff --git a/test/CloudNative.CloudEvents.UnitTests/Protobuf/ProtobufEventFormatterTest.cs b/test/CloudNative.CloudEvents.UnitTests/Protobuf/ProtobufEventFormatterTest.cs index 087c2da..9868d2a 100644 --- a/test/CloudNative.CloudEvents.UnitTests/Protobuf/ProtobufEventFormatterTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/Protobuf/ProtobufEventFormatterTest.cs @@ -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; diff --git a/test/CloudNative.CloudEvents.UnitTests/SystemTextJson/JsonEventFormatterTest.cs b/test/CloudNative.CloudEvents.UnitTests/SystemTextJson/JsonEventFormatterTest.cs index af1ef0c..888639f 100644 --- a/test/CloudNative.CloudEvents.UnitTests/SystemTextJson/JsonEventFormatterTest.cs +++ b/test/CloudNative.CloudEvents.UnitTests/SystemTextJson/JsonEventFormatterTest.cs @@ -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)); } } -} \ No newline at end of file +} diff --git a/test/CloudNative.CloudEvents.UnitTests/TestHelpers.cs b/test/CloudNative.CloudEvents.UnitTests/TestHelpers.cs index da1d230..f21bfee 100644 --- a/test/CloudNative.CloudEvents.UnitTests/TestHelpers.cs +++ b/test/CloudNative.CloudEvents.UnitTests/TestHelpers.cs @@ -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); }