Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Activout.RestClient\Activout.RestClient.csproj" />
<ProjectReference Include="..\Activout.RestClient.Newtonsoft.Json\Activout.RestClient.Newtonsoft.Json.csproj" />
</ItemGroup>

</Project>

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using RichardSzalay.MockHttp;
using Xunit;

namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
[ErrorResponse(typeof(MyApiErrorResponse))]
[DomainException(typeof(SomeDomainErrorObjectException))]
Expand Down Expand Up @@ -43,6 +43,7 @@ public DefaultDomainExceptionErrorObjectTests()

_defaultMapperApiClient = Services.CreateRestClientFactory()
.CreateBuilder()
.WithNewtonsoftJson()
.With(_mockHttp.ToHttpClient())
.BaseUri(new Uri(BaseUri))
.Build<ISomeApiErrorObjectClient>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using RichardSzalay.MockHttp;
using Xunit;

namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
internal class MyDomainErrorEnumException : Exception
{
Expand Down Expand Up @@ -47,6 +47,7 @@ public DomainExceptionErrorEnumTests()
_myApiClient = Services.CreateRestClientFactory()
.CreateBuilder()
.With(_mockHttp.ToHttpClient())
.WithNewtonsoftJson()
.BaseUri(new Uri(BaseUri))
.Build<IMyApiClient>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using RichardSzalay.MockHttp;
using Xunit;

namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
internal class MyDomainErrorObject
{
Expand Down Expand Up @@ -78,6 +78,7 @@ public DomainExceptionErrorObjectTests()

_myApiClient = Services.CreateRestClientFactory()
.CreateBuilder()
.WithNewtonsoftJson()
.With(_mockHttp.ToHttpClient())
.BaseUri(new Uri(BaseUri))
.With(new MyDomainExceptionMapperFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
public enum MyApiError
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
public class MyApiErrorResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Activout.RestClient.DomainExceptions;

namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
internal class MyDomainErrorAttribute : DomainErrorAttribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
public enum MyDomainErrorEnum
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Net;
using Activout.RestClient.DomainExceptions;

namespace Activout.RestClient.Test.DomainExceptionTests
namespace Activout.RestClient.Newtonsoft.Json.Test.DomainExceptions
{
internal class MyDomainHttpErrorAttribute : DomainExceptions.DomainHttpErrorAttribute
internal class MyDomainHttpErrorAttribute : DomainHttpErrorAttribute
{
public MyDomainHttpErrorAttribute(HttpStatusCode httpStatusCode, MyDomainErrorEnum domainErrorValue) : base(
httpStatusCode, domainErrorValue)
Expand Down
20 changes: 20 additions & 0 deletions Activout.RestClient.Newtonsoft.Json.Test/LoggerFactoryHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Activout.RestClient.Newtonsoft.Json.Test
{
public static class LoggerFactoryHelpers
{
public static ILoggerFactory CreateLoggerFactory(ITestOutputHelper outputHelper)
{
return LoggerFactory.Create(builder =>
{
builder
.AddFilter("Microsoft", LogLevel.Warning)
.AddFilter("System", LogLevel.Warning)
.AddFilter("Activout.RestClient", LogLevel.Debug)
.AddXUnit(outputHelper);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace Activout.RestClient.Test.MovieReviews
namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews
{
public class ErrorResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace Activout.RestClient.Test.MovieReviews
namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews
{
[Path("movies")]
[ErrorResponse(typeof(ErrorResponse))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;

namespace Activout.RestClient.Test.MovieReviews
namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews
{
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
public class Movie
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Activout.RestClient.Test.MovieReviews
namespace Activout.RestClient.Newtonsoft.Json.Test.MovieReviews
{
public class Review
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
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;
using RichardSzalay.MockHttp;
using Xunit;

namespace Activout.RestClient.Test
namespace Activout.RestClient.Newtonsoft.Json.Test
{
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
public class Data
Expand All @@ -22,9 +23,9 @@ public interface IClient
Data GetData();
}

public class JsonDeserializerTest
public class NewtonsoftJsonDeserializerTest
{
public JsonDeserializerTest()
public NewtonsoftJsonDeserializerTest()
{
_restClientFactory = Services.CreateRestClientFactory();
_mockHttp = new MockHttpMessageHandler();
Expand Down Expand Up @@ -76,7 +77,7 @@ public void TestCamelCaseWithDeserializer()
MockCamelCaseResponse();

var client = CreateRestClientBuilder()
.With(new JsonDeserializer(new JsonSerializerSettings
.With(new NewtonsoftJsonDeserializer(new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}))
Expand All @@ -97,7 +98,7 @@ public void TestCamelCaseWithSerializationManager()
MockCamelCaseResponse();

var deserializers = SerializationManager.DefaultDeserializers.ToList();
deserializers.Add(new JsonDeserializer(new JsonSerializerSettings
deserializers.Add(new NewtonsoftJsonDeserializer(new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}));
Expand All @@ -118,8 +119,9 @@ public void TestCamelCaseWithSerializationManager()
private IRestClientBuilder CreateRestClientBuilder()
{
return _restClientFactory.CreateBuilder()
.WithNewtonsoftJson()
.With(_mockHttp.ToHttpClient())
.BaseUri(new Uri(BaseUri));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
using System.Threading;
using System.Threading.Tasks;
using Activout.RestClient.Helpers.Implementation;
using Activout.RestClient.Test.MovieReviews;
using Activout.RestClient.Newtonsoft.Json.Test.MovieReviews;
using Microsoft.Extensions.Logging;
using Moq;
using Newtonsoft.Json;
using RichardSzalay.MockHttp;
using Xunit;
using Xunit.Abstractions;

namespace Activout.RestClient.Test
namespace Activout.RestClient.Newtonsoft.Json.Test
{
public class RestClientTests
{
Expand All @@ -37,6 +37,7 @@ public RestClientTests(ITestOutputHelper outputHelper)
private IRestClientBuilder CreateRestClientBuilder()
{
return _restClientFactory.CreateBuilder()
.WithNewtonsoftJson()
.Accept("application/json")
.ContentType("application/json")
.With(_loggerFactory.CreateLogger<RestClientTests>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Activout.RestClient.Serialization.Implementation;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RichardSzalay.MockHttp;
using Xunit;

namespace Activout.RestClient.Test
namespace Activout.RestClient.Newtonsoft.Json.Test
{
public class SerializationOrderTest
{
Expand Down Expand Up @@ -64,7 +63,7 @@ public interface ISerializationOrderClient
private ISerializationOrderClient CreateClient(int orderOfJsonDeserializer)
{
return CreateRestClientBuilder()
.With(new JsonDeserializer(new JsonSerializerSettings()
.With(new NewtonsoftJsonDeserializer(new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver()
{
Expand All @@ -78,6 +77,7 @@ private ISerializationOrderClient CreateClient(int orderOfJsonDeserializer)
private IRestClientBuilder CreateRestClientBuilder()
{
return _restClientFactory.CreateBuilder()
.WithNewtonsoftJson()
.With(_mockHttp.ToHttpClient())
.BaseUri(new Uri(BaseUri));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using RichardSzalay.MockHttp;
using Xunit;

namespace Activout.RestClient.Test
namespace Activout.RestClient.Newtonsoft.Json.Test
{
public class MySimpleValueObject
{
Expand Down Expand Up @@ -128,6 +128,7 @@ private IValueObjectClient CreateClient()
{
return _restClientFactory.CreateBuilder()
.With(_mockHttp.ToHttpClient())
.WithNewtonsoftJson()
.BaseUri(new Uri(BaseUri))
.Build<IValueObjectClient>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider centralizing dependency version management if applicable, to ensure consistency across the project.

Copilot uses AI. Check for mistakes.
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Activout.RestClient\Activout.RestClient.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath=""/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Activout.RestClient.Serialization.Implementation
namespace Activout.RestClient.Newtonsoft.Json
{
public static class JsonHelper
{
Expand All @@ -14,4 +14,4 @@ static JsonHelper()

public static IReadOnlyCollection<MediaType> SupportedMediaTypes { get; }
}
}
}
21 changes: 21 additions & 0 deletions Activout.RestClient.Newtonsoft.Json/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 David Eriksson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading