From 793097ad260e1c6830b9d3dab0d6a0fc3bdec16a Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 22:03:40 +0200 Subject: [PATCH 1/7] Enable nullable in project but disable in files --- Activout.RestClient/AcceptAttribute.cs | 1 + Activout.RestClient/Activout.RestClient.csproj | 1 + Activout.RestClient/ContentTypeAttribute.cs | 1 + .../DomainExceptions/AbstractDomainExceptionMapper.cs | 1 + .../DomainExceptions/DefaultDomainExceptionMapper.cs | 1 + .../DomainExceptions/DefaultDomainExceptionMapperFactory.cs | 1 + Activout.RestClient/DomainExceptions/DomainErrorAttribute.cs | 1 + .../DomainExceptions/DomainExceptionAttribute.cs | 1 + .../DomainExceptions/DomainHttpErrorAttribute.cs | 3 ++- Activout.RestClient/DomainExceptions/IDomainExceptionMapper.cs | 1 + .../DomainExceptions/IDomainExceptionMapperFactory.cs | 1 + Activout.RestClient/ErrorResponseAttribute.cs | 3 ++- Activout.RestClient/FormKeyAttribute.cs | 1 + Activout.RestClient/FormParamAttribute.cs | 3 ++- Activout.RestClient/HeaderAttribute.cs | 1 + Activout.RestClient/HeaderParamAttribute.cs | 3 ++- Activout.RestClient/Helpers/IDuckTyping.cs | 3 ++- Activout.RestClient/Helpers/ITaskConverter.cs | 3 ++- Activout.RestClient/Helpers/ITaskConverterFactory.cs | 3 ++- Activout.RestClient/Helpers/Implementation/DuckTyping.cs | 3 ++- Activout.RestClient/Helpers/Implementation/TaskConverter.cs | 3 ++- Activout.RestClient/Helpers/Implementation/TaskConverter2.cs | 1 + .../Helpers/Implementation/TaskConverter2Factory.cs | 3 ++- Activout.RestClient/Helpers/Implementation/TaskConverter3.cs | 1 + .../Helpers/Implementation/TaskConverter3Factory.cs | 3 ++- .../Helpers/Implementation/TaskConverterFactory.cs | 3 ++- Activout.RestClient/HttpMethodAttribute.cs | 1 + Activout.RestClient/IRequestLogger.cs | 1 + Activout.RestClient/IRestClientBuilder.cs | 3 ++- Activout.RestClient/IRestClientFactory.cs | 3 ++- Activout.RestClient/Implementation/HeaderListExtensions.cs | 1 + Activout.RestClient/Implementation/RequestHandler.cs | 3 ++- Activout.RestClient/Implementation/RestClient.cs | 3 ++- Activout.RestClient/Implementation/RestClientBuilder.cs | 3 ++- Activout.RestClient/Implementation/RestClientContext.cs | 3 ++- Activout.RestClient/Implementation/RestClientFactory.cs | 3 ++- Activout.RestClient/Implementation/StringExtensions.cs | 1 + Activout.RestClient/MediaType.cs | 1 + Activout.RestClient/NamedParamAttribute.cs | 1 + Activout.RestClient/ParamConverter/IParamConverter.cs | 3 ++- Activout.RestClient/ParamConverter/IParamConverterManager.cs | 3 ++- .../Implementation/DateTimeEpochParamConverter.cs | 3 ++- .../Implementation/DateTimeIso8601ParamConverter.cs | 3 ++- .../ParamConverter/Implementation/ParamConverterManager.cs | 3 ++- .../ParamConverter/Implementation/ToStringParamConverter.cs | 3 ++- Activout.RestClient/Part.cs | 1 + Activout.RestClient/PartParamAttribute.cs | 1 + Activout.RestClient/PathAttribute.cs | 1 + Activout.RestClient/PathParamAttribute.cs | 3 ++- Activout.RestClient/QueryParamAttribute.cs | 3 ++- Activout.RestClient/RestClientBuilderExtensions.cs | 1 + Activout.RestClient/RestClientException.cs | 3 ++- Activout.RestClient/RouteAttribute.cs | 1 + Activout.RestClient/RouteParamAttribute.cs | 3 ++- Activout.RestClient/Serialization/IDeserializer.cs | 3 ++- Activout.RestClient/Serialization/ISerializationManager.cs | 3 ++- Activout.RestClient/Serialization/ISerializer.cs | 3 ++- .../Serialization/Implementation/ByteArrayDeserializer.cs | 3 ++- .../Serialization/Implementation/ByteArraySerializer.cs | 3 ++- .../Serialization/Implementation/FormUrlEncodedSerializer.cs | 1 + .../Serialization/Implementation/SerializationManager.cs | 3 ++- .../Serialization/Implementation/StringDeserializer.cs | 3 ++- .../Serialization/Implementation/StringSerializer.cs | 3 ++- Activout.RestClient/Services.cs | 3 ++- Activout.RestClient/TemplateAttribute.cs | 1 + 65 files changed, 103 insertions(+), 38 deletions(-) diff --git a/Activout.RestClient/AcceptAttribute.cs b/Activout.RestClient/AcceptAttribute.cs index 3dc79fe..39a1a85 100644 --- a/Activout.RestClient/AcceptAttribute.cs +++ b/Activout.RestClient/AcceptAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable namespace Activout.RestClient { public class AcceptAttribute : HeaderAttribute diff --git a/Activout.RestClient/Activout.RestClient.csproj b/Activout.RestClient/Activout.RestClient.csproj index 68c7bdf..9d9bffe 100644 --- a/Activout.RestClient/Activout.RestClient.csproj +++ b/Activout.RestClient/Activout.RestClient.csproj @@ -2,6 +2,7 @@ net8.0 default + enable true CS0618;CS0619 README.md diff --git a/Activout.RestClient/ContentTypeAttribute.cs b/Activout.RestClient/ContentTypeAttribute.cs index 19c6977..b124d6c 100644 --- a/Activout.RestClient/ContentTypeAttribute.cs +++ b/Activout.RestClient/ContentTypeAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/DomainExceptions/AbstractDomainExceptionMapper.cs b/Activout.RestClient/DomainExceptions/AbstractDomainExceptionMapper.cs index 0524cd3..8bc7482 100644 --- a/Activout.RestClient/DomainExceptions/AbstractDomainExceptionMapper.cs +++ b/Activout.RestClient/DomainExceptions/AbstractDomainExceptionMapper.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Net.Http; using System.Threading.Tasks; diff --git a/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapper.cs b/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapper.cs index eaf8b1f..03370a5 100644 --- a/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapper.cs +++ b/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapper.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapperFactory.cs b/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapperFactory.cs index f3407bf..1ee547d 100644 --- a/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapperFactory.cs +++ b/Activout.RestClient/DomainExceptions/DefaultDomainExceptionMapperFactory.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/Activout.RestClient/DomainExceptions/DomainErrorAttribute.cs b/Activout.RestClient/DomainExceptions/DomainErrorAttribute.cs index 000a535..bbba45d 100644 --- a/Activout.RestClient/DomainExceptions/DomainErrorAttribute.cs +++ b/Activout.RestClient/DomainExceptions/DomainErrorAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient.DomainExceptions diff --git a/Activout.RestClient/DomainExceptions/DomainExceptionAttribute.cs b/Activout.RestClient/DomainExceptions/DomainExceptionAttribute.cs index b08aecf..d129b07 100644 --- a/Activout.RestClient/DomainExceptions/DomainExceptionAttribute.cs +++ b/Activout.RestClient/DomainExceptions/DomainExceptionAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient.DomainExceptions diff --git a/Activout.RestClient/DomainExceptions/DomainHttpErrorAttribute.cs b/Activout.RestClient/DomainExceptions/DomainHttpErrorAttribute.cs index 81b548f..09c9db8 100644 --- a/Activout.RestClient/DomainExceptions/DomainHttpErrorAttribute.cs +++ b/Activout.RestClient/DomainExceptions/DomainHttpErrorAttribute.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Net; namespace Activout.RestClient.DomainExceptions diff --git a/Activout.RestClient/DomainExceptions/IDomainExceptionMapper.cs b/Activout.RestClient/DomainExceptions/IDomainExceptionMapper.cs index 4fd0e11..1062cb8 100644 --- a/Activout.RestClient/DomainExceptions/IDomainExceptionMapper.cs +++ b/Activout.RestClient/DomainExceptions/IDomainExceptionMapper.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Net.Http; using System.Threading.Tasks; diff --git a/Activout.RestClient/DomainExceptions/IDomainExceptionMapperFactory.cs b/Activout.RestClient/DomainExceptions/IDomainExceptionMapperFactory.cs index ac71c08..8d71d5e 100644 --- a/Activout.RestClient/DomainExceptions/IDomainExceptionMapperFactory.cs +++ b/Activout.RestClient/DomainExceptions/IDomainExceptionMapperFactory.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Reflection; diff --git a/Activout.RestClient/ErrorResponseAttribute.cs b/Activout.RestClient/ErrorResponseAttribute.cs index 023bad2..8e81236 100644 --- a/Activout.RestClient/ErrorResponseAttribute.cs +++ b/Activout.RestClient/ErrorResponseAttribute.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient { diff --git a/Activout.RestClient/FormKeyAttribute.cs b/Activout.RestClient/FormKeyAttribute.cs index c40d91e..0728d29 100644 --- a/Activout.RestClient/FormKeyAttribute.cs +++ b/Activout.RestClient/FormKeyAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/FormParamAttribute.cs b/Activout.RestClient/FormParamAttribute.cs index dc73dbd..a57c9fe 100644 --- a/Activout.RestClient/FormParamAttribute.cs +++ b/Activout.RestClient/FormParamAttribute.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient { diff --git a/Activout.RestClient/HeaderAttribute.cs b/Activout.RestClient/HeaderAttribute.cs index e917929..a716b4f 100644 --- a/Activout.RestClient/HeaderAttribute.cs +++ b/Activout.RestClient/HeaderAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/HeaderParamAttribute.cs b/Activout.RestClient/HeaderParamAttribute.cs index 3bd9cba..42b5767 100644 --- a/Activout.RestClient/HeaderParamAttribute.cs +++ b/Activout.RestClient/HeaderParamAttribute.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient { diff --git a/Activout.RestClient/Helpers/IDuckTyping.cs b/Activout.RestClient/Helpers/IDuckTyping.cs index 77a22ad..452e478 100644 --- a/Activout.RestClient/Helpers/IDuckTyping.cs +++ b/Activout.RestClient/Helpers/IDuckTyping.cs @@ -1,4 +1,5 @@ -namespace Activout.RestClient.Helpers +#nullable disable +namespace Activout.RestClient.Helpers { public interface IDuckTyping { diff --git a/Activout.RestClient/Helpers/ITaskConverter.cs b/Activout.RestClient/Helpers/ITaskConverter.cs index 02d4c9f..ca82c6a 100644 --- a/Activout.RestClient/Helpers/ITaskConverter.cs +++ b/Activout.RestClient/Helpers/ITaskConverter.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +#nullable disable +using System.Threading.Tasks; namespace Activout.RestClient.Helpers { diff --git a/Activout.RestClient/Helpers/ITaskConverterFactory.cs b/Activout.RestClient/Helpers/ITaskConverterFactory.cs index 7176f4f..aca664e 100644 --- a/Activout.RestClient/Helpers/ITaskConverterFactory.cs +++ b/Activout.RestClient/Helpers/ITaskConverterFactory.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient.Helpers { diff --git a/Activout.RestClient/Helpers/Implementation/DuckTyping.cs b/Activout.RestClient/Helpers/Implementation/DuckTyping.cs index be6f770..393123f 100644 --- a/Activout.RestClient/Helpers/Implementation/DuckTyping.cs +++ b/Activout.RestClient/Helpers/Implementation/DuckTyping.cs @@ -1,4 +1,5 @@ -using ImpromptuInterface; +#nullable disable +using ImpromptuInterface; namespace Activout.RestClient.Helpers.Implementation { diff --git a/Activout.RestClient/Helpers/Implementation/TaskConverter.cs b/Activout.RestClient/Helpers/Implementation/TaskConverter.cs index 3eaa393..f4b6029 100644 --- a/Activout.RestClient/Helpers/Implementation/TaskConverter.cs +++ b/Activout.RestClient/Helpers/Implementation/TaskConverter.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; diff --git a/Activout.RestClient/Helpers/Implementation/TaskConverter2.cs b/Activout.RestClient/Helpers/Implementation/TaskConverter2.cs index b942fbd..db92200 100644 --- a/Activout.RestClient/Helpers/Implementation/TaskConverter2.cs +++ b/Activout.RestClient/Helpers/Implementation/TaskConverter2.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Reflection; using System.Threading.Tasks; diff --git a/Activout.RestClient/Helpers/Implementation/TaskConverter2Factory.cs b/Activout.RestClient/Helpers/Implementation/TaskConverter2Factory.cs index 0d33f98..9bcb13c 100644 --- a/Activout.RestClient/Helpers/Implementation/TaskConverter2Factory.cs +++ b/Activout.RestClient/Helpers/Implementation/TaskConverter2Factory.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient.Helpers.Implementation { diff --git a/Activout.RestClient/Helpers/Implementation/TaskConverter3.cs b/Activout.RestClient/Helpers/Implementation/TaskConverter3.cs index ec26350..6eb5357 100644 --- a/Activout.RestClient/Helpers/Implementation/TaskConverter3.cs +++ b/Activout.RestClient/Helpers/Implementation/TaskConverter3.cs @@ -1,3 +1,4 @@ +#nullable disable using System.Diagnostics; using System.Threading.Tasks; diff --git a/Activout.RestClient/Helpers/Implementation/TaskConverter3Factory.cs b/Activout.RestClient/Helpers/Implementation/TaskConverter3Factory.cs index a0af67b..b5ba196 100644 --- a/Activout.RestClient/Helpers/Implementation/TaskConverter3Factory.cs +++ b/Activout.RestClient/Helpers/Implementation/TaskConverter3Factory.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient.Helpers.Implementation; diff --git a/Activout.RestClient/Helpers/Implementation/TaskConverterFactory.cs b/Activout.RestClient/Helpers/Implementation/TaskConverterFactory.cs index 0f8c958..e3e4a8b 100644 --- a/Activout.RestClient/Helpers/Implementation/TaskConverterFactory.cs +++ b/Activout.RestClient/Helpers/Implementation/TaskConverterFactory.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient.Helpers.Implementation { diff --git a/Activout.RestClient/HttpMethodAttribute.cs b/Activout.RestClient/HttpMethodAttribute.cs index a37db00..3965809 100644 --- a/Activout.RestClient/HttpMethodAttribute.cs +++ b/Activout.RestClient/HttpMethodAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Net.Http; diff --git a/Activout.RestClient/IRequestLogger.cs b/Activout.RestClient/IRequestLogger.cs index c3a4ea9..7f6508a 100644 --- a/Activout.RestClient/IRequestLogger.cs +++ b/Activout.RestClient/IRequestLogger.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Net.Http; diff --git a/Activout.RestClient/IRestClientBuilder.cs b/Activout.RestClient/IRestClientBuilder.cs index c179575..1c727e2 100644 --- a/Activout.RestClient/IRestClientBuilder.cs +++ b/Activout.RestClient/IRestClientBuilder.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Net.Http; using Activout.RestClient.DomainExceptions; using Activout.RestClient.Helpers; diff --git a/Activout.RestClient/IRestClientFactory.cs b/Activout.RestClient/IRestClientFactory.cs index 3861722..98a0efd 100644 --- a/Activout.RestClient/IRestClientFactory.cs +++ b/Activout.RestClient/IRestClientFactory.cs @@ -1,4 +1,5 @@ -namespace Activout.RestClient +#nullable disable +namespace Activout.RestClient { public interface IRestClientFactory { diff --git a/Activout.RestClient/Implementation/HeaderListExtensions.cs b/Activout.RestClient/Implementation/HeaderListExtensions.cs index f5f51a2..c0b38cd 100644 --- a/Activout.RestClient/Implementation/HeaderListExtensions.cs +++ b/Activout.RestClient/Implementation/HeaderListExtensions.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Collections.Generic; diff --git a/Activout.RestClient/Implementation/RequestHandler.cs b/Activout.RestClient/Implementation/RequestHandler.cs index 1ac1248..db8a646 100644 --- a/Activout.RestClient/Implementation/RequestHandler.cs +++ b/Activout.RestClient/Implementation/RequestHandler.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/Activout.RestClient/Implementation/RestClient.cs b/Activout.RestClient/Implementation/RestClient.cs index c9313f7..07310a5 100644 --- a/Activout.RestClient/Implementation/RestClient.cs +++ b/Activout.RestClient/Implementation/RestClient.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Dynamic; diff --git a/Activout.RestClient/Implementation/RestClientBuilder.cs b/Activout.RestClient/Implementation/RestClientBuilder.cs index c4cbb89..be2763d 100644 --- a/Activout.RestClient/Implementation/RestClientBuilder.cs +++ b/Activout.RestClient/Implementation/RestClientBuilder.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; diff --git a/Activout.RestClient/Implementation/RestClientContext.cs b/Activout.RestClient/Implementation/RestClientContext.cs index 0a41bb5..17f0406 100644 --- a/Activout.RestClient/Implementation/RestClientContext.cs +++ b/Activout.RestClient/Implementation/RestClientContext.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; diff --git a/Activout.RestClient/Implementation/RestClientFactory.cs b/Activout.RestClient/Implementation/RestClientFactory.cs index 7fe8b95..b73456a 100644 --- a/Activout.RestClient/Implementation/RestClientFactory.cs +++ b/Activout.RestClient/Implementation/RestClientFactory.cs @@ -1,4 +1,5 @@ -using Activout.RestClient.Helpers; +#nullable disable +using Activout.RestClient.Helpers; using Activout.RestClient.ParamConverter; namespace Activout.RestClient.Implementation diff --git a/Activout.RestClient/Implementation/StringExtensions.cs b/Activout.RestClient/Implementation/StringExtensions.cs index 9e76ef8..0b7ce40 100644 --- a/Activout.RestClient/Implementation/StringExtensions.cs +++ b/Activout.RestClient/Implementation/StringExtensions.cs @@ -1,3 +1,4 @@ +#nullable disable namespace Activout.RestClient.Implementation { public static class StringExtensions diff --git a/Activout.RestClient/MediaType.cs b/Activout.RestClient/MediaType.cs index 43b1cbb..1937a69 100644 --- a/Activout.RestClient/MediaType.cs +++ b/Activout.RestClient/MediaType.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Net.Http.Headers; diff --git a/Activout.RestClient/NamedParamAttribute.cs b/Activout.RestClient/NamedParamAttribute.cs index fb878b3..2b7c218 100644 --- a/Activout.RestClient/NamedParamAttribute.cs +++ b/Activout.RestClient/NamedParamAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/ParamConverter/IParamConverter.cs b/Activout.RestClient/ParamConverter/IParamConverter.cs index 8c2095c..2a4ab11 100644 --- a/Activout.RestClient/ParamConverter/IParamConverter.cs +++ b/Activout.RestClient/ParamConverter/IParamConverter.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Reflection; namespace Activout.RestClient.ParamConverter diff --git a/Activout.RestClient/ParamConverter/IParamConverterManager.cs b/Activout.RestClient/ParamConverter/IParamConverterManager.cs index 963f23c..5ccd934 100644 --- a/Activout.RestClient/ParamConverter/IParamConverterManager.cs +++ b/Activout.RestClient/ParamConverter/IParamConverterManager.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Reflection; namespace Activout.RestClient.ParamConverter diff --git a/Activout.RestClient/ParamConverter/Implementation/DateTimeEpochParamConverter.cs b/Activout.RestClient/ParamConverter/Implementation/DateTimeEpochParamConverter.cs index 29a1879..e6ee928 100644 --- a/Activout.RestClient/ParamConverter/Implementation/DateTimeEpochParamConverter.cs +++ b/Activout.RestClient/ParamConverter/Implementation/DateTimeEpochParamConverter.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Reflection; namespace Activout.RestClient.ParamConverter.Implementation diff --git a/Activout.RestClient/ParamConverter/Implementation/DateTimeIso8601ParamConverter.cs b/Activout.RestClient/ParamConverter/Implementation/DateTimeIso8601ParamConverter.cs index b786b30..891ec58 100644 --- a/Activout.RestClient/ParamConverter/Implementation/DateTimeIso8601ParamConverter.cs +++ b/Activout.RestClient/ParamConverter/Implementation/DateTimeIso8601ParamConverter.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Reflection; namespace Activout.RestClient.ParamConverter.Implementation diff --git a/Activout.RestClient/ParamConverter/Implementation/ParamConverterManager.cs b/Activout.RestClient/ParamConverter/Implementation/ParamConverterManager.cs index b24d72e..dc09128 100644 --- a/Activout.RestClient/ParamConverter/Implementation/ParamConverterManager.cs +++ b/Activout.RestClient/ParamConverter/Implementation/ParamConverterManager.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Globalization; using System.Reflection; diff --git a/Activout.RestClient/ParamConverter/Implementation/ToStringParamConverter.cs b/Activout.RestClient/ParamConverter/Implementation/ToStringParamConverter.cs index 9bd05c4..f71858c 100644 --- a/Activout.RestClient/ParamConverter/Implementation/ToStringParamConverter.cs +++ b/Activout.RestClient/ParamConverter/Implementation/ToStringParamConverter.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Reflection; namespace Activout.RestClient.ParamConverter.Implementation diff --git a/Activout.RestClient/Part.cs b/Activout.RestClient/Part.cs index d3428d8..8a8db93 100644 --- a/Activout.RestClient/Part.cs +++ b/Activout.RestClient/Part.cs @@ -1,3 +1,4 @@ +#nullable disable namespace Activout.RestClient { public class Part diff --git a/Activout.RestClient/PartParamAttribute.cs b/Activout.RestClient/PartParamAttribute.cs index 0486494..12b096e 100644 --- a/Activout.RestClient/PartParamAttribute.cs +++ b/Activout.RestClient/PartParamAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/PathAttribute.cs b/Activout.RestClient/PathAttribute.cs index 54a4aed..8a45433 100644 --- a/Activout.RestClient/PathAttribute.cs +++ b/Activout.RestClient/PathAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/PathParamAttribute.cs b/Activout.RestClient/PathParamAttribute.cs index 531bf09..b0783f7 100644 --- a/Activout.RestClient/PathParamAttribute.cs +++ b/Activout.RestClient/PathParamAttribute.cs @@ -1,4 +1,5 @@ -namespace Activout.RestClient +#nullable disable +namespace Activout.RestClient { public class PathParamAttribute : NamedParamAttribute { diff --git a/Activout.RestClient/QueryParamAttribute.cs b/Activout.RestClient/QueryParamAttribute.cs index 0349489..8e8d5ee 100644 --- a/Activout.RestClient/QueryParamAttribute.cs +++ b/Activout.RestClient/QueryParamAttribute.cs @@ -1,4 +1,5 @@ -namespace Activout.RestClient +#nullable disable +namespace Activout.RestClient { public class QueryParamAttribute : NamedParamAttribute { diff --git a/Activout.RestClient/RestClientBuilderExtensions.cs b/Activout.RestClient/RestClientBuilderExtensions.cs index c4b19b6..e75730a 100644 --- a/Activout.RestClient/RestClientBuilderExtensions.cs +++ b/Activout.RestClient/RestClientBuilderExtensions.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Net.Http.Headers; diff --git a/Activout.RestClient/RestClientException.cs b/Activout.RestClient/RestClientException.cs index 98bc25d..66084aa 100644 --- a/Activout.RestClient/RestClientException.cs +++ b/Activout.RestClient/RestClientException.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Net; namespace Activout.RestClient diff --git a/Activout.RestClient/RouteAttribute.cs b/Activout.RestClient/RouteAttribute.cs index 122f12f..288429b 100644 --- a/Activout.RestClient/RouteAttribute.cs +++ b/Activout.RestClient/RouteAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient diff --git a/Activout.RestClient/RouteParamAttribute.cs b/Activout.RestClient/RouteParamAttribute.cs index 157c802..8bd428c 100644 --- a/Activout.RestClient/RouteParamAttribute.cs +++ b/Activout.RestClient/RouteParamAttribute.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; namespace Activout.RestClient { diff --git a/Activout.RestClient/Serialization/IDeserializer.cs b/Activout.RestClient/Serialization/IDeserializer.cs index ac9d9da..8659c58 100644 --- a/Activout.RestClient/Serialization/IDeserializer.cs +++ b/Activout.RestClient/Serialization/IDeserializer.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Net.Http; using System.Threading.Tasks; diff --git a/Activout.RestClient/Serialization/ISerializationManager.cs b/Activout.RestClient/Serialization/ISerializationManager.cs index 6460e97..274b514 100644 --- a/Activout.RestClient/Serialization/ISerializationManager.cs +++ b/Activout.RestClient/Serialization/ISerializationManager.cs @@ -1,4 +1,5 @@ -namespace Activout.RestClient.Serialization +#nullable disable +namespace Activout.RestClient.Serialization { public interface ISerializationManager { diff --git a/Activout.RestClient/Serialization/ISerializer.cs b/Activout.RestClient/Serialization/ISerializer.cs index 956d2df..e64e0e1 100644 --- a/Activout.RestClient/Serialization/ISerializer.cs +++ b/Activout.RestClient/Serialization/ISerializer.cs @@ -1,4 +1,5 @@ -using System.Net.Http; +#nullable disable +using System.Net.Http; using System.Text; namespace Activout.RestClient.Serialization diff --git a/Activout.RestClient/Serialization/Implementation/ByteArrayDeserializer.cs b/Activout.RestClient/Serialization/Implementation/ByteArrayDeserializer.cs index cf935b5..0a2e693 100644 --- a/Activout.RestClient/Serialization/Implementation/ByteArrayDeserializer.cs +++ b/Activout.RestClient/Serialization/Implementation/ByteArrayDeserializer.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; diff --git a/Activout.RestClient/Serialization/Implementation/ByteArraySerializer.cs b/Activout.RestClient/Serialization/Implementation/ByteArraySerializer.cs index 24a5dc5..b44a423 100644 --- a/Activout.RestClient/Serialization/Implementation/ByteArraySerializer.cs +++ b/Activout.RestClient/Serialization/Implementation/ByteArraySerializer.cs @@ -1,4 +1,5 @@ -using System.Net.Http; +#nullable disable +using System.Net.Http; using System.Net.Http.Headers; using System.Text; diff --git a/Activout.RestClient/Serialization/Implementation/FormUrlEncodedSerializer.cs b/Activout.RestClient/Serialization/Implementation/FormUrlEncodedSerializer.cs index ce2c3d9..3186d28 100644 --- a/Activout.RestClient/Serialization/Implementation/FormUrlEncodedSerializer.cs +++ b/Activout.RestClient/Serialization/Implementation/FormUrlEncodedSerializer.cs @@ -1,3 +1,4 @@ +#nullable disable using System.Collections.Generic; using System.Linq; using System.Net.Http; diff --git a/Activout.RestClient/Serialization/Implementation/SerializationManager.cs b/Activout.RestClient/Serialization/Implementation/SerializationManager.cs index 47708b8..555ae27 100644 --- a/Activout.RestClient/Serialization/Implementation/SerializationManager.cs +++ b/Activout.RestClient/Serialization/Implementation/SerializationManager.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; diff --git a/Activout.RestClient/Serialization/Implementation/StringDeserializer.cs b/Activout.RestClient/Serialization/Implementation/StringDeserializer.cs index 2ee5e27..912824a 100644 --- a/Activout.RestClient/Serialization/Implementation/StringDeserializer.cs +++ b/Activout.RestClient/Serialization/Implementation/StringDeserializer.cs @@ -1,4 +1,5 @@ -using System; +#nullable disable +using System; using System.Net.Http; using System.Threading.Tasks; diff --git a/Activout.RestClient/Serialization/Implementation/StringSerializer.cs b/Activout.RestClient/Serialization/Implementation/StringSerializer.cs index 1ecdd95..e9da748 100644 --- a/Activout.RestClient/Serialization/Implementation/StringSerializer.cs +++ b/Activout.RestClient/Serialization/Implementation/StringSerializer.cs @@ -1,4 +1,5 @@ -using System.Net.Http; +#nullable disable +using System.Net.Http; using System.Text; namespace Activout.RestClient.Serialization.Implementation diff --git a/Activout.RestClient/Services.cs b/Activout.RestClient/Services.cs index 06cd9e1..85a881b 100644 --- a/Activout.RestClient/Services.cs +++ b/Activout.RestClient/Services.cs @@ -1,4 +1,5 @@ -using Activout.RestClient.Helpers; +#nullable disable +using Activout.RestClient.Helpers; using Activout.RestClient.Helpers.Implementation; using Activout.RestClient.Implementation; using Activout.RestClient.ParamConverter; diff --git a/Activout.RestClient/TemplateAttribute.cs b/Activout.RestClient/TemplateAttribute.cs index c04922f..df093a6 100644 --- a/Activout.RestClient/TemplateAttribute.cs +++ b/Activout.RestClient/TemplateAttribute.cs @@ -1,3 +1,4 @@ +#nullable disable using System; namespace Activout.RestClient From d678135a4dad782f568980da59ff41e1481720e0 Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 21:13:12 +0200 Subject: [PATCH 2/7] Enable Nullable --- .../DefaultDomainExceptionErrorObjectTests.cs | 4 +- .../DomainExceptionErrorEnumTests.cs | 2 +- .../DomainExceptionErrorObjectTests.cs | 8 ++-- .../MovieReviews/ErrorResponse.cs | 6 +-- .../MovieReviews/Movie.cs | 2 +- .../MovieReviews/Review.cs | 8 ++-- .../NewtonsoftJsonDeserializerTest.cs | 5 +-- .../RestClientTests.cs | 38 ++++--------------- .../SerializationOrderTest.cs | 4 +- .../SimpleValueObjectTest.cs | 10 ++--- 10 files changed, 31 insertions(+), 56 deletions(-) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs index a3b291b..4ffaf53 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs @@ -24,7 +24,7 @@ internal class SomeDomainErrorObjectException : Exception { public MyDomainErrorEnum Error { get; } - public SomeDomainErrorObjectException(MyDomainErrorEnum error, Exception innerException = null) : base( + public SomeDomainErrorObjectException(MyDomainErrorEnum error, Exception? innerException = null) : base( error.ToString(), innerException) { Error = error; @@ -42,7 +42,7 @@ public DefaultDomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _defaultMapperApiClient = Services.CreateRestClientFactory() + _defaultMapperApiClient = new RestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs index c100f76..e154086 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs @@ -45,7 +45,7 @@ public DomainExceptionErrorEnumTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = Services.CreateRestClientFactory() + _myApiClient = new RestClientFactory() .CreateBuilder() .With(_mockHttp.ToHttpClient()) .WithNewtonsoftJson() diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs index c30e0fb..26cd2af 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs @@ -26,7 +26,7 @@ internal class MyDomainErrorObjectException : Exception { public MyDomainErrorObject Error { get; } - public MyDomainErrorObjectException(MyDomainErrorObject error, Exception innerException = null) : base( + public MyDomainErrorObjectException(MyDomainErrorObject error, Exception? innerException = null) : base( error.ToString(), innerException) { Error = error; @@ -42,8 +42,8 @@ public interface IMyApiErrorObjectClient internal class MyDomainExceptionObjectMapper : AbstractDomainExceptionMapper { - protected override Exception CreateException(HttpResponseMessage httpResponseMessage, object data, - Exception innerException) + protected override Exception CreateException(HttpResponseMessage httpResponseMessage, object? data, + Exception? innerException) { var domainError = data is MyApiErrorResponse errorResponse && errorResponse.Code == MyApiError.Bar ? new MyDomainErrorObject(MyDomainErrorEnum.DomainBar) @@ -77,7 +77,7 @@ public DomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = Services.CreateRestClientFactory() + _myApiClient = new RestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs index 2f0ca9c..f8713d9 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs @@ -5,12 +5,12 @@ namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews { public class ErrorResponse { - public List Errors { get; set; } + public List Errors { get; init; } = []; public class Error { - public string Message { get; set; } - public int Code { get; set; } + public string? Message { get; init; } + public int Code { get; init; } } } } \ No newline at end of file diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs index 9f3a5f6..43f71fd 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs @@ -6,6 +6,6 @@ namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class Movie { - public string Title { get; set; } + public string? Title { get; init; } } } \ No newline at end of file diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs index f965172..625827a 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs @@ -9,9 +9,9 @@ public Review(int stars, string text) Text = text; } - public string MovieId { get; set; } - public string ReviewId { get; set; } - public int Stars { get; set; } - public string Text { get; set; } + public string? MovieId { get; init; } + public string? ReviewId { get; init; } + public int Stars { get; init; } + public string Text { get; init; } } } \ No newline at end of file diff --git a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs index ce9fc8b..26bebc0 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Net.Http; using System.Text; -using Activout.RestClient.Newtonsoft.Json; using Activout.RestClient.Serialization.Implementation; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -16,7 +15,7 @@ namespace Activout.RestClient.Newtonsoft.Json.Test [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class Data { - public string Value { get; set; } + public string? Value { get; init; } } public interface IClient @@ -28,7 +27,7 @@ public class NewtonsoftJsonDeserializerTest { public NewtonsoftJsonDeserializerTest() { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs index e76fd3a..ab6cb08 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs @@ -4,7 +4,6 @@ using System.Net; using System.Net.Http; using System.Text; -using System.Threading; using System.Threading.Tasks; using Activout.RestClient.Helpers.Implementation; using Activout.RestClient.Newtonsoft.Json.Test.MovieReviews; @@ -20,7 +19,7 @@ public class RestClientTests { public RestClientTests(ITestOutputHelper outputHelper) { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper); } @@ -50,32 +49,6 @@ private IMovieReviewService CreateMovieReviewService() .Build(); } - [Fact] - public async Task TestErrorAsyncWithOldTaskConverter() - { - // arrange - ExpectGetAllReviewsAndReturnError(); - - var reviewSvc = CreateRestClientBuilder() - .With(new TaskConverterFactory()) - .Build(); - - // act - var aggregateException = - await Assert.ThrowsAsync(() => reviewSvc.GetAllReviews(MovieId)); - - // assert - _mockHttp.VerifyNoOutstandingExpectation(); - - Assert.IsType(aggregateException.InnerException); - var exception = (RestClientException)aggregateException.InnerException; - - Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); - var error = exception.GetErrorResponse(); - Assert.Equal(34, error.Errors[0].Code); - Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message); - } - [Fact] public async Task TestErrorAsync() { @@ -93,6 +66,7 @@ public async Task TestErrorAsync() Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); var error = exception.GetErrorResponse(); + Assert.NotNull(error); Assert.Equal(34, error.Errors[0].Code); Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message); } @@ -101,7 +75,7 @@ private void ExpectGetAllReviewsAndReturnError(string movieId = MovieId) { _mockHttp .Expect(HttpMethod.Get, $"{BaseUri}/movies/{movieId}/reviews") - .Respond(HttpStatusCode.NotFound, request => new StringContent(JsonConvert.SerializeObject(new + .Respond(HttpStatusCode.NotFound, _ => new StringContent(JsonConvert.SerializeObject(new { Errors = new object[] { @@ -137,6 +111,7 @@ public void TestErrorSync() var exception = (RestClientException)aggregateException.GetBaseException(); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); + Assert.NotNull(exception.ErrorResponse); dynamic dynamicError = exception.ErrorResponse; string message = dynamicError.Errors[0].Message; int code = dynamicError.Errors[0].Code; @@ -144,6 +119,7 @@ public void TestErrorSync() Assert.Equal("Sorry, that page does not exist", message); var error = exception.GetErrorResponse(); + Assert.NotNull(error); Assert.Equal(34, error.Errors[0].Code); Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message); } @@ -222,7 +198,7 @@ public void TestPutSync() var reviewId = "*REVIEW_ID*"; _mockHttp .When(HttpMethod.Put, $"{BaseUri}/movies/{movieId}/reviews/{reviewId}") - .Respond(request => request.Content); + .Respond(request => request.Content!); var reviewSvc = CreateMovieReviewService(); @@ -251,7 +227,7 @@ public void TestPatchSync() var reviewId = "*REVIEW_ID*"; _mockHttp .When(HttpMethod.Patch, $"{BaseUri}/movies/{movieId}/reviews/{reviewId}") - .Respond(request => request.Content); + .Respond(request => request.Content!); var reviewSvc = CreateMovieReviewService(); diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs index c5fae53..561d3d6 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs @@ -21,7 +21,7 @@ public class SerializationOrderTest public SerializationOrderTest() { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } @@ -53,7 +53,7 @@ public async Task TestSerializationOrder(int order, string expectedValue) public class SerializationOrderModel { - public string MyValue { get; set; } + public string? MyValue { get; init; } } public interface ISerializationOrderClient diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs index 82d06bf..20df228 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs @@ -22,9 +22,9 @@ public MySimpleValueObject(string value) public class Stuff { - public MySimpleValueObject FooBar { get; set; } + public MySimpleValueObject? FooBar { get; init; } - public int? NullableInteger { get; set; } + public int? NullableInteger { get; init; } } public interface IValueObjectClient @@ -39,7 +39,7 @@ public class SimpleValueObjectTest { public SimpleValueObjectTest() { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } @@ -97,7 +97,7 @@ public void TestSimpleValueObjectDeserialization() // Assert _mockHttp.VerifyNoOutstandingExpectation(); - Assert.Equal("foobar", result.FooBar.Value); + Assert.Equal("foobar", result.FooBar?.Value); } [Fact] @@ -108,7 +108,7 @@ public void TestSimpleValueObjectDeserializationWithNulls() .Expect(BaseUri) .Respond(new StringContent(JsonConvert.SerializeObject(new { - FooBar = (string)null, + FooBar = (string?)null, NullableInteger = (int?)null }), Encoding.UTF8, From 6ad9f538325010fdea05e6f081312e1d5b6ead69 Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 21:40:15 +0200 Subject: [PATCH 3/7] Make tests pass --- .../SimpleValueObjectTest.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs index 20df228..c9aa2c0 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs @@ -37,16 +37,10 @@ public interface IValueObjectClient public class SimpleValueObjectTest { - public SimpleValueObjectTest() - { - _restClientFactory = new RestClientFactory(); - _mockHttp = new MockHttpMessageHandler(); - } - private const string BaseUri = "https://example.com/api/"; - private readonly IRestClientFactory _restClientFactory; - private readonly MockHttpMessageHandler _mockHttp; + private readonly IRestClientFactory _restClientFactory = new RestClientFactory(); + private readonly MockHttpMessageHandler _mockHttp = new(); [Fact] public async Task TestSimpleValueObjectSerialization() From 38c94853af28ed9faef4ffa606b87ab450030aca Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 22:15:55 +0200 Subject: [PATCH 4/7] Handle nullable --- .../DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs | 3 +-- .../DomainExceptions/DomainExceptionErrorEnumTests.cs | 3 +-- .../DomainExceptions/DomainExceptionErrorObjectTests.cs | 3 +-- .../DomainExceptions/MyApiError.cs | 1 - .../DomainExceptions/MyApiErrorResponse.cs | 1 - .../DomainExceptions/MyDomainErrorAttribute.cs | 1 - .../DomainExceptions/MyDomainErrorEnum.cs | 1 - .../DomainExceptions/MyDomainHttpErrorAttribute.cs | 1 - .../LoggerFactoryHelpers.cs | 1 - .../MovieReviews/ErrorResponse.cs | 1 - .../MovieReviews/IMovieReviewService.cs | 1 - Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs | 1 - .../MovieReviews/Review.cs | 1 - .../NewtonsoftJsonDeserializerTest.cs | 3 +-- Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs | 3 +-- .../SerializationOrderTest.cs | 3 +-- .../SimpleValueObjectTest.cs | 3 +-- 17 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs index 4ffaf53..d7c7a2f 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -42,7 +41,7 @@ public DefaultDomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _defaultMapperApiClient = new RestClientFactory() + _defaultMapperApiClient = Services.CreateRestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs index e154086..aa86902 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -45,7 +44,7 @@ public DomainExceptionErrorEnumTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = new RestClientFactory() + _myApiClient = Services.CreateRestClientFactory() .CreateBuilder() .With(_mockHttp.ToHttpClient()) .WithNewtonsoftJson() diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs index 26cd2af..fc77f6b 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -77,7 +76,7 @@ public DomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = new RestClientFactory() + _myApiClient = Services.CreateRestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs index c1cfb10..1bd2570 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions { public enum MyApiError diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs index 64a770f..b010980 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions { public class MyApiErrorResponse diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs index 614dd04..573d320 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs @@ -1,4 +1,3 @@ -#nullable disable using Activout.RestClient.DomainExceptions; namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs index dc7a21b..03090fe 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions { public enum MyDomainErrorEnum diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs index f3372e1..d488765 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Net; using Activout.RestClient.DomainExceptions; diff --git a/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs b/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs index c569c5f..ad5f135 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs @@ -1,4 +1,3 @@ -#nullable disable using Microsoft.Extensions.Logging; using Xunit.Abstractions; diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs index f8713d9..f346321 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Collections.Generic; namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs index 6f918fc..d9af2d2 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Collections.Generic; using System.Threading; diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs index 43f71fd..51a13ff 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Diagnostics.CodeAnalysis; namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs index 625827a..ca8b931 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews { public class Review diff --git a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs index 26bebc0..f468a2d 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -27,7 +26,7 @@ public class NewtonsoftJsonDeserializerTest { public NewtonsoftJsonDeserializerTest() { - _restClientFactory = new RestClientFactory(); + _restClientFactory = Services.CreateRestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs index ab6cb08..28a7dcf 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Linq; using System.Net; @@ -19,7 +18,7 @@ public class RestClientTests { public RestClientTests(ITestOutputHelper outputHelper) { - _restClientFactory = new RestClientFactory(); + _restClientFactory = Services.CreateRestClientFactory(); _mockHttp = new MockHttpMessageHandler(); _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs index 561d3d6..d999618 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net.Http; using System.Text; @@ -21,7 +20,7 @@ public class SerializationOrderTest public SerializationOrderTest() { - _restClientFactory = new RestClientFactory(); + _restClientFactory = Services.CreateRestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs index c9aa2c0..afe266a 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -39,7 +38,7 @@ public class SimpleValueObjectTest { private const string BaseUri = "https://example.com/api/"; - private readonly IRestClientFactory _restClientFactory = new RestClientFactory(); + private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory(); private readonly MockHttpMessageHandler _mockHttp = new(); [Fact] From a2288c26bf28e010283f4539891694034dd2d3b5 Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 21:13:12 +0200 Subject: [PATCH 5/7] Enable Nullable --- .../DefaultDomainExceptionErrorObjectTests.cs | 4 +- .../DomainExceptionErrorEnumTests.cs | 2 +- .../DomainExceptionErrorObjectTests.cs | 8 ++-- .../MovieReviews/ErrorResponse.cs | 6 +-- .../MovieReviews/Movie.cs | 2 +- .../MovieReviews/Review.cs | 8 ++-- .../NewtonsoftJsonDeserializerTest.cs | 5 +-- .../RestClientTests.cs | 38 ++++--------------- .../SerializationOrderTest.cs | 4 +- .../SimpleValueObjectTest.cs | 10 ++--- 10 files changed, 31 insertions(+), 56 deletions(-) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs index a3b291b..4ffaf53 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs @@ -24,7 +24,7 @@ internal class SomeDomainErrorObjectException : Exception { public MyDomainErrorEnum Error { get; } - public SomeDomainErrorObjectException(MyDomainErrorEnum error, Exception innerException = null) : base( + public SomeDomainErrorObjectException(MyDomainErrorEnum error, Exception? innerException = null) : base( error.ToString(), innerException) { Error = error; @@ -42,7 +42,7 @@ public DefaultDomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _defaultMapperApiClient = Services.CreateRestClientFactory() + _defaultMapperApiClient = new RestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs index c100f76..e154086 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs @@ -45,7 +45,7 @@ public DomainExceptionErrorEnumTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = Services.CreateRestClientFactory() + _myApiClient = new RestClientFactory() .CreateBuilder() .With(_mockHttp.ToHttpClient()) .WithNewtonsoftJson() diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs index c30e0fb..26cd2af 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs @@ -26,7 +26,7 @@ internal class MyDomainErrorObjectException : Exception { public MyDomainErrorObject Error { get; } - public MyDomainErrorObjectException(MyDomainErrorObject error, Exception innerException = null) : base( + public MyDomainErrorObjectException(MyDomainErrorObject error, Exception? innerException = null) : base( error.ToString(), innerException) { Error = error; @@ -42,8 +42,8 @@ public interface IMyApiErrorObjectClient internal class MyDomainExceptionObjectMapper : AbstractDomainExceptionMapper { - protected override Exception CreateException(HttpResponseMessage httpResponseMessage, object data, - Exception innerException) + protected override Exception CreateException(HttpResponseMessage httpResponseMessage, object? data, + Exception? innerException) { var domainError = data is MyApiErrorResponse errorResponse && errorResponse.Code == MyApiError.Bar ? new MyDomainErrorObject(MyDomainErrorEnum.DomainBar) @@ -77,7 +77,7 @@ public DomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = Services.CreateRestClientFactory() + _myApiClient = new RestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs index 2f0ca9c..f8713d9 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs @@ -5,12 +5,12 @@ namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews { public class ErrorResponse { - public List Errors { get; set; } + public List Errors { get; init; } = []; public class Error { - public string Message { get; set; } - public int Code { get; set; } + public string? Message { get; init; } + public int Code { get; init; } } } } \ No newline at end of file diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs index 9f3a5f6..43f71fd 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs @@ -6,6 +6,6 @@ namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class Movie { - public string Title { get; set; } + public string? Title { get; init; } } } \ No newline at end of file diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs index f965172..625827a 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs @@ -9,9 +9,9 @@ public Review(int stars, string text) Text = text; } - public string MovieId { get; set; } - public string ReviewId { get; set; } - public int Stars { get; set; } - public string Text { get; set; } + public string? MovieId { get; init; } + public string? ReviewId { get; init; } + public int Stars { get; init; } + public string Text { get; init; } } } \ No newline at end of file diff --git a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs index ce9fc8b..26bebc0 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Net.Http; using System.Text; -using Activout.RestClient.Newtonsoft.Json; using Activout.RestClient.Serialization.Implementation; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -16,7 +15,7 @@ namespace Activout.RestClient.Newtonsoft.Json.Test [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class Data { - public string Value { get; set; } + public string? Value { get; init; } } public interface IClient @@ -28,7 +27,7 @@ public class NewtonsoftJsonDeserializerTest { public NewtonsoftJsonDeserializerTest() { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs index e76fd3a..ab6cb08 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs @@ -4,7 +4,6 @@ using System.Net; using System.Net.Http; using System.Text; -using System.Threading; using System.Threading.Tasks; using Activout.RestClient.Helpers.Implementation; using Activout.RestClient.Newtonsoft.Json.Test.MovieReviews; @@ -20,7 +19,7 @@ public class RestClientTests { public RestClientTests(ITestOutputHelper outputHelper) { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper); } @@ -50,32 +49,6 @@ private IMovieReviewService CreateMovieReviewService() .Build(); } - [Fact] - public async Task TestErrorAsyncWithOldTaskConverter() - { - // arrange - ExpectGetAllReviewsAndReturnError(); - - var reviewSvc = CreateRestClientBuilder() - .With(new TaskConverterFactory()) - .Build(); - - // act - var aggregateException = - await Assert.ThrowsAsync(() => reviewSvc.GetAllReviews(MovieId)); - - // assert - _mockHttp.VerifyNoOutstandingExpectation(); - - Assert.IsType(aggregateException.InnerException); - var exception = (RestClientException)aggregateException.InnerException; - - Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); - var error = exception.GetErrorResponse(); - Assert.Equal(34, error.Errors[0].Code); - Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message); - } - [Fact] public async Task TestErrorAsync() { @@ -93,6 +66,7 @@ public async Task TestErrorAsync() Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); var error = exception.GetErrorResponse(); + Assert.NotNull(error); Assert.Equal(34, error.Errors[0].Code); Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message); } @@ -101,7 +75,7 @@ private void ExpectGetAllReviewsAndReturnError(string movieId = MovieId) { _mockHttp .Expect(HttpMethod.Get, $"{BaseUri}/movies/{movieId}/reviews") - .Respond(HttpStatusCode.NotFound, request => new StringContent(JsonConvert.SerializeObject(new + .Respond(HttpStatusCode.NotFound, _ => new StringContent(JsonConvert.SerializeObject(new { Errors = new object[] { @@ -137,6 +111,7 @@ public void TestErrorSync() var exception = (RestClientException)aggregateException.GetBaseException(); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); + Assert.NotNull(exception.ErrorResponse); dynamic dynamicError = exception.ErrorResponse; string message = dynamicError.Errors[0].Message; int code = dynamicError.Errors[0].Code; @@ -144,6 +119,7 @@ public void TestErrorSync() Assert.Equal("Sorry, that page does not exist", message); var error = exception.GetErrorResponse(); + Assert.NotNull(error); Assert.Equal(34, error.Errors[0].Code); Assert.Equal("Sorry, that page does not exist", error.Errors[0].Message); } @@ -222,7 +198,7 @@ public void TestPutSync() var reviewId = "*REVIEW_ID*"; _mockHttp .When(HttpMethod.Put, $"{BaseUri}/movies/{movieId}/reviews/{reviewId}") - .Respond(request => request.Content); + .Respond(request => request.Content!); var reviewSvc = CreateMovieReviewService(); @@ -251,7 +227,7 @@ public void TestPatchSync() var reviewId = "*REVIEW_ID*"; _mockHttp .When(HttpMethod.Patch, $"{BaseUri}/movies/{movieId}/reviews/{reviewId}") - .Respond(request => request.Content); + .Respond(request => request.Content!); var reviewSvc = CreateMovieReviewService(); diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs index c5fae53..561d3d6 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs @@ -21,7 +21,7 @@ public class SerializationOrderTest public SerializationOrderTest() { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } @@ -53,7 +53,7 @@ public async Task TestSerializationOrder(int order, string expectedValue) public class SerializationOrderModel { - public string MyValue { get; set; } + public string? MyValue { get; init; } } public interface ISerializationOrderClient diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs index 82d06bf..20df228 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs @@ -22,9 +22,9 @@ public MySimpleValueObject(string value) public class Stuff { - public MySimpleValueObject FooBar { get; set; } + public MySimpleValueObject? FooBar { get; init; } - public int? NullableInteger { get; set; } + public int? NullableInteger { get; init; } } public interface IValueObjectClient @@ -39,7 +39,7 @@ public class SimpleValueObjectTest { public SimpleValueObjectTest() { - _restClientFactory = Services.CreateRestClientFactory(); + _restClientFactory = new RestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } @@ -97,7 +97,7 @@ public void TestSimpleValueObjectDeserialization() // Assert _mockHttp.VerifyNoOutstandingExpectation(); - Assert.Equal("foobar", result.FooBar.Value); + Assert.Equal("foobar", result.FooBar?.Value); } [Fact] @@ -108,7 +108,7 @@ public void TestSimpleValueObjectDeserializationWithNulls() .Expect(BaseUri) .Respond(new StringContent(JsonConvert.SerializeObject(new { - FooBar = (string)null, + FooBar = (string?)null, NullableInteger = (int?)null }), Encoding.UTF8, From 82682ab45fbb6ef77ee2e5ff5f1f1d016d1e8f8b Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 21:40:15 +0200 Subject: [PATCH 6/7] Make tests pass --- .../SimpleValueObjectTest.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs index 20df228..c9aa2c0 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs @@ -37,16 +37,10 @@ public interface IValueObjectClient public class SimpleValueObjectTest { - public SimpleValueObjectTest() - { - _restClientFactory = new RestClientFactory(); - _mockHttp = new MockHttpMessageHandler(); - } - private const string BaseUri = "https://example.com/api/"; - private readonly IRestClientFactory _restClientFactory; - private readonly MockHttpMessageHandler _mockHttp; + private readonly IRestClientFactory _restClientFactory = new RestClientFactory(); + private readonly MockHttpMessageHandler _mockHttp = new(); [Fact] public async Task TestSimpleValueObjectSerialization() From 7df948bea7ab56a4af834a0580dc9fbff6b63e15 Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Fri, 24 Oct 2025 22:15:55 +0200 Subject: [PATCH 7/7] Handle nullable --- .../DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs | 3 +-- .../DomainExceptions/DomainExceptionErrorEnumTests.cs | 3 +-- .../DomainExceptions/DomainExceptionErrorObjectTests.cs | 3 +-- .../DomainExceptions/MyApiError.cs | 1 - .../DomainExceptions/MyApiErrorResponse.cs | 1 - .../DomainExceptions/MyDomainErrorAttribute.cs | 1 - .../DomainExceptions/MyDomainErrorEnum.cs | 1 - .../DomainExceptions/MyDomainHttpErrorAttribute.cs | 1 - .../LoggerFactoryHelpers.cs | 1 - .../MovieReviews/ErrorResponse.cs | 1 - .../MovieReviews/IMovieReviewService.cs | 1 - Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs | 1 - .../MovieReviews/Review.cs | 1 - .../NewtonsoftJsonDeserializerTest.cs | 3 +-- Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs | 3 +-- .../SerializationOrderTest.cs | 3 +-- .../SimpleValueObjectTest.cs | 3 +-- 17 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs index 4ffaf53..d7c7a2f 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DefaultDomainExceptionErrorObjectTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -42,7 +41,7 @@ public DefaultDomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _defaultMapperApiClient = new RestClientFactory() + _defaultMapperApiClient = Services.CreateRestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs index e154086..aa86902 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorEnumTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -45,7 +44,7 @@ public DomainExceptionErrorEnumTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = new RestClientFactory() + _myApiClient = Services.CreateRestClientFactory() .CreateBuilder() .With(_mockHttp.ToHttpClient()) .WithNewtonsoftJson() diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs index 26cd2af..fc77f6b 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/DomainExceptionErrorObjectTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -77,7 +76,7 @@ public DomainExceptionErrorObjectTests() { _mockHttp = new MockHttpMessageHandler(); - _myApiClient = new RestClientFactory() + _myApiClient = Services.CreateRestClientFactory() .CreateBuilder() .WithNewtonsoftJson() .With(_mockHttp.ToHttpClient()) diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs index c1cfb10..1bd2570 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiError.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions { public enum MyApiError diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs index 64a770f..b010980 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyApiErrorResponse.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions { public class MyApiErrorResponse diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs index 614dd04..573d320 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorAttribute.cs @@ -1,4 +1,3 @@ -#nullable disable using Activout.RestClient.DomainExceptions; namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs index dc7a21b..03090fe 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainErrorEnum.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions { public enum MyDomainErrorEnum diff --git a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs index f3372e1..d488765 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/DomainExceptions/MyDomainHttpErrorAttribute.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Net; using Activout.RestClient.DomainExceptions; diff --git a/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs b/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs index c569c5f..ad5f135 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs @@ -1,4 +1,3 @@ -#nullable disable using Microsoft.Extensions.Logging; using Xunit.Abstractions; diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs index f8713d9..f346321 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/ErrorResponse.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Collections.Generic; namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs index 6f918fc..d9af2d2 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/IMovieReviewService.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Collections.Generic; using System.Threading; diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs index 43f71fd..51a13ff 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Movie.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Diagnostics.CodeAnalysis; namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews diff --git a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs index 625827a..ca8b931 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/MovieReviews/Review.cs @@ -1,4 +1,3 @@ -#nullable disable namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews { public class Review diff --git a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs index 26bebc0..f468a2d 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/NewtonsoftJsonDeserializerTest.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -27,7 +26,7 @@ public class NewtonsoftJsonDeserializerTest { public NewtonsoftJsonDeserializerTest() { - _restClientFactory = new RestClientFactory(); + _restClientFactory = Services.CreateRestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs index ab6cb08..28a7dcf 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/RestClientTests.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Linq; using System.Net; @@ -19,7 +18,7 @@ public class RestClientTests { public RestClientTests(ITestOutputHelper outputHelper) { - _restClientFactory = new RestClientFactory(); + _restClientFactory = Services.CreateRestClientFactory(); _mockHttp = new MockHttpMessageHandler(); _loggerFactory = LoggerFactoryHelpers.CreateLoggerFactory(outputHelper); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs index 561d3d6..d999618 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SerializationOrderTest.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net.Http; using System.Text; @@ -21,7 +20,7 @@ public class SerializationOrderTest public SerializationOrderTest() { - _restClientFactory = new RestClientFactory(); + _restClientFactory = Services.CreateRestClientFactory(); _mockHttp = new MockHttpMessageHandler(); } diff --git a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs index c9aa2c0..afe266a 100644 --- a/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs +++ b/Activout.RestClient.Newtonsoft.Json.Test/SimpleValueObjectTest.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Net; using System.Net.Http; @@ -39,7 +38,7 @@ public class SimpleValueObjectTest { private const string BaseUri = "https://example.com/api/"; - private readonly IRestClientFactory _restClientFactory = new RestClientFactory(); + private readonly IRestClientFactory _restClientFactory = Services.CreateRestClientFactory(); private readonly MockHttpMessageHandler _mockHttp = new(); [Fact]