From d3cd23c3d85a6a5ba0549444014a20ec952665b3 Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Tue, 24 Dec 2024 06:29:15 +0100 Subject: [PATCH] Apply new Resharper suggestion: use explicit default value --- .../IntegrationTests/CompositeKeys/Car.cs | 6 ++-- .../IdObfuscation/ObfuscatedIdentifiable.cs | 4 +-- .../SerializerIgnoreConditionTests.cs | 2 +- .../Serialization/InputConversionTests.cs | 32 +++++++++---------- .../RuntimeTypeConverterTests.cs | 24 +++++++------- test/UnitTests/Models/IdentifiableTests.cs | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/Car.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/Car.cs index d61d378db7..f77626f13e 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/Car.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/Car.cs @@ -12,13 +12,13 @@ public sealed class Car : Identifiable [NotMapped] public override string? Id { - get => RegionId == default && LicensePlate == default ? null : $"{RegionId}:{LicensePlate}"; + get => RegionId == 0 && LicensePlate == null ? null : $"{RegionId}:{LicensePlate}"; set { if (value == null) { - RegionId = default; - LicensePlate = default; + RegionId = 0; + LicensePlate = null; return; } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/IdObfuscation/ObfuscatedIdentifiable.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/IdObfuscation/ObfuscatedIdentifiable.cs index 0aa2203d8a..af6a8a1416 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/IdObfuscation/ObfuscatedIdentifiable.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/IdObfuscation/ObfuscatedIdentifiable.cs @@ -8,11 +8,11 @@ public abstract class ObfuscatedIdentifiable : Identifiable protected override string? GetStringId(int value) { - return value == default ? null : Codec.Encode(value); + return value == 0 ? null : Codec.Encode(value); } protected override int GetTypedId(string? value) { - return value == null ? default : Codec.Decode(value); + return value == null ? 0 : Codec.Decode(value); } } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SerializerIgnoreConditionTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SerializerIgnoreConditionTests.cs index a0e770e555..89db819a2c 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SerializerIgnoreConditionTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SerializerIgnoreConditionTests.cs @@ -32,7 +32,7 @@ public async Task Applies_configuration_for_ignore_condition(JsonIgnoreCondition Calendar calendar = _fakers.Calendar.GenerateOne(); calendar.TimeZone = null; - calendar.DefaultAppointmentDurationInMinutes = default; + calendar.DefaultAppointmentDurationInMinutes = 0; calendar.ShowWeekNumbers = true; calendar.MostRecentAppointment = _fakers.Appointment.GenerateOne(); calendar.MostRecentAppointment.Description = null; diff --git a/test/JsonApiDotNetCoreTests/UnitTests/Serialization/InputConversionTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/Serialization/InputConversionTests.cs index 37307b1ab5..c70ee53e8c 100644 --- a/test/JsonApiDotNetCoreTests/UnitTests/Serialization/InputConversionTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/Serialization/InputConversionTests.cs @@ -153,26 +153,26 @@ public void Converts_various_data_types_with_defaults() WriteOperation = WriteOperationKind.CreateResource }); - const bool booleanValue = default; - const bool nullableBooleanValue = default; - const char charValue = default; - const char nullableCharValue = default; - const ulong unsignedLongValue = default; - const ulong nullableUnsignedLongValue = default; - const decimal decimalValue = default; - const decimal nullableDecimalValue = default; - const float floatValue = default; - const float nullableFloatValue = default; - const string stringValue = default!; - const string? nullableStringValue = default; - Guid guidValue = default; - Guid nullableGuidValue = default; + const bool booleanValue = false; + const bool nullableBooleanValue = false; + const char charValue = '\0'; + const char nullableCharValue = '\0'; + const ulong unsignedLongValue = 0; + const ulong nullableUnsignedLongValue = 0; + const decimal decimalValue = 0; + const decimal nullableDecimalValue = 0; + const float floatValue = 0; + const float nullableFloatValue = 0; + const string stringValue = null!; + const string? nullableStringValue = null; + Guid guidValue = Guid.Empty; + Guid nullableGuidValue = Guid.Empty; DateTime dateTimeValue = default; DateTime nullableDateTimeValue = default; DateTimeOffset dateTimeOffsetValue = default; DateTimeOffset nullableDateTimeOffsetValue = default; - TimeSpan timeSpanValue = default; - TimeSpan nullableTimeSpanValue = default; + TimeSpan timeSpanValue = TimeSpan.Zero; + TimeSpan nullableTimeSpanValue = TimeSpan.Zero; const DayOfWeek enumValue = default; const DayOfWeek nullableEnumValue = default; diff --git a/test/JsonApiDotNetCoreTests/UnitTests/TypeConversion/RuntimeTypeConverterTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/TypeConversion/RuntimeTypeConverterTests.cs index 1263912faf..c7b0bf9450 100644 --- a/test/JsonApiDotNetCoreTests/UnitTests/TypeConversion/RuntimeTypeConverterTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/TypeConversion/RuntimeTypeConverterTests.cs @@ -109,29 +109,29 @@ public void Returns_same_instance_for_interface() } [Theory] - [InlineData(typeof(bool), default(bool))] + [InlineData(typeof(bool), false)] [InlineData(typeof(bool?), null)] - [InlineData(typeof(byte), default(byte))] + [InlineData(typeof(byte), 0)] [InlineData(typeof(byte?), null)] - [InlineData(typeof(sbyte), default(sbyte))] + [InlineData(typeof(sbyte), 0)] [InlineData(typeof(sbyte?), null)] - [InlineData(typeof(char), default(char))] + [InlineData(typeof(char), '\0')] [InlineData(typeof(char?), null)] - [InlineData(typeof(short), default(short))] + [InlineData(typeof(short), 0)] [InlineData(typeof(short?), null)] - [InlineData(typeof(ushort), default(ushort))] + [InlineData(typeof(ushort), 0)] [InlineData(typeof(ushort?), null)] - [InlineData(typeof(int), default(int))] + [InlineData(typeof(int), 0)] [InlineData(typeof(int?), null)] - [InlineData(typeof(uint), default(uint))] + [InlineData(typeof(uint), 0)] [InlineData(typeof(uint?), null)] - [InlineData(typeof(long), default(long))] + [InlineData(typeof(long), 0)] [InlineData(typeof(long?), null)] - [InlineData(typeof(ulong), default(ulong))] + [InlineData(typeof(ulong), 0)] [InlineData(typeof(ulong?), null)] - [InlineData(typeof(float), default(float))] + [InlineData(typeof(float), 0)] [InlineData(typeof(float?), null)] - [InlineData(typeof(double), default(double))] + [InlineData(typeof(double), 0)] [InlineData(typeof(double?), null)] [InlineData(typeof(decimal), 0)] [InlineData(typeof(decimal?), null)] diff --git a/test/UnitTests/Models/IdentifiableTests.cs b/test/UnitTests/Models/IdentifiableTests.cs index 993a3988f2..ad11081c65 100644 --- a/test/UnitTests/Models/IdentifiableTests.cs +++ b/test/UnitTests/Models/IdentifiableTests.cs @@ -33,7 +33,7 @@ public void GetStringId_Returns_Null_If_Object_Is_Default() { var resource = new IntId(); - string? stringId = resource.ExposedGetStringId(default); + string? stringId = resource.ExposedGetStringId(0); stringId.Should().BeNull(); }