Skip to content

Commit

Permalink
Upgraded to net8
Browse files Browse the repository at this point in the history
  • Loading branch information
nfMalde committed Oct 11, 2024
1 parent fce4780 commit de91cfb
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 89 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET 6
uses: actions/setup-dotnet@v1
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: "Build and Test"
run: |
dotnet build
Expand Down Expand Up @@ -86,10 +86,10 @@ jobs:
needs: [test, version, prepublish]
runs-on: windows-latest
steps:
- name: Setup .NET 6
uses: actions/setup-dotnet@v1
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Checkout Sources
uses: actions/checkout@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET 6
- name: Setup .NET 8
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: "Build and Test"
run: |
dotnet build
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Change Log
## 2.1.0
Upgraded to latest Restsharp and .net 8.
## 2.0.0
Fixes:
* Fixed a bug where certain null values at GameModel result in breaking the code.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For API-Docs look here: https://api.thegamesdb.net/#/
This Library uses the following lib(s) fro archive its functionality:
* [RestSharp](https://github.com/restsharp/RestSharp)
* [NewtonSoft.Json/JSON.NET](https://github.com/JamesNK/Newtonsoft.Json)
* [Shouldly](https://github.com/shouldly)

## Requirements
* .NET 6 or higher
Expand Down
2 changes: 1 addition & 1 deletion nugetdocs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For API-Docs look here: https://api.thegamesdb.net/#/
This Library uses the following lib(s) fro archive its functionality:
* [RestSharp](https://github.com/restsharp/RestSharp)
* [NewtonSoft.Json/JSON.NET](https://github.com/JamesNK/Newtonsoft.Json)

* [Shouldly](https://github.com/shouldly)
## Requirements
* .NET 6 or higher
* Older Versions for NET5 and below are still available - however **starting with v2.0.0** these versions are no longer supported and marked as depricated. Please update your package to latest version when possible.
Expand Down
2 changes: 1 addition & 1 deletion src/Data/ApiClasses/Base/BaseApiClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected async Task<T> CallGet<T>(string endpoint = null, object payload = null
RestRequest r = new RestRequest(endpoint, Method.Get);

// Support for long requests
r.Timeout = 3600;
r.Timeout = TimeSpan.FromSeconds(3600);


if (version != null)
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Entities/GameImageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GameImageModel
/// The type.
/// </value>
[JsonProperty("type")]
public GameImageType Type { get; set; }
public GameImageType? Type { get; set; }
/// <summary>
/// Gets or sets the side (i.e. front or back) for boxart images.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Models/Entities/UpdateModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UpdateModel
/// The edit identifier.
/// </value>
[JsonProperty("edit_id")]
public int EditID { get; set; }
public int? EditID { get; set; }

/// <summary>
/// Gets or sets the game identifier.
Expand All @@ -30,7 +30,7 @@ public class UpdateModel
/// The game identifier.
/// </value>
[JsonProperty("game_id")]
public int GameID { get; set; }
public int? GameID { get; set; }

/// <summary>
/// Gets or sets the timestamp.
Expand All @@ -39,7 +39,7 @@ public class UpdateModel
/// The timestamp.
/// </value>
[JsonProperty("timestamp")]
public DateTime Timestamp { get; set; }
public DateTime? Timestamp { get; set; }

/// <summary>
/// Gets or sets the type.
Expand All @@ -48,7 +48,7 @@ public class UpdateModel
/// The type.
/// </value>
[JsonProperty("type")]
public string Type { get; set; }
public string? Type { get; set; }

Check warning on line 51 in src/Models/Entities/UpdateModel.cs

View workflow job for this annotation

GitHub Actions / test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Gets or sets the value if value is string.
Expand All @@ -67,7 +67,7 @@ public class UpdateModel
/// The value.
/// </value>
[JsonIgnore]
public string Value { get { return this.Values?.Value; } }
public string? Value { get { return this.Values?.Value; } }

Check warning on line 70 in src/Models/Entities/UpdateModel.cs

View workflow job for this annotation

GitHub Actions / test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

}
}
12 changes: 6 additions & 6 deletions src/TheGamesDBApiWrapper.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>2021 Malte Peters</Copyright>
<Description>Wrapper Class in Fluent Style for TheGamesDBAPI</Description>
Expand All @@ -27,12 +27,12 @@ Starting with this release older versions of th is package are no longer support
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="110.2.0" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />
<None Include="..\nugetdocs\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

Expand Down
105 changes: 47 additions & 58 deletions tests/TheGamesDBApiWrapperTests/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using RestSharp;
using RestSharp.Serializers.NewtonsoftJson;
using RichardSzalay.MockHttp;
using Shouldly;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -41,7 +42,7 @@ private string loadJson(string filename)
throw new Exception($"Json Mock {filename}.mock.json not found. Path: {p}");
}

private RestClient mockRestClient<TResponse>(string jsonfile) where TResponse:class
private RestClient mockRestClient<TResponse>(string jsonfile) where TResponse : class
{
string content = this.loadJson(jsonfile);
var mockHttp = new MockHttpMessageHandler();
Expand All @@ -53,11 +54,8 @@ private RestClient mockRestClient<TResponse>(string jsonfile) where TResponse:cl
{
ConfigureMessageHandler = _ => mockHttp,
BaseUrl = new Uri("https://localhost/testapi/"),


},
configureSerialization: s => s.UseNewtonsoftJson(this.getJsonSettings()));

}

private IServiceProvider ServiceProvider;
Expand All @@ -72,10 +70,8 @@ private JsonSerializerSettings getJsonSettings()
return settings;
}


private void mockServices<TResponse>(string jsonfile) where TResponse:class
private void mockServices<TResponse>(string jsonfile) where TResponse : class
{

Mock<ITheGamesDBApiWrapperRestClientFactory> mock = new Mock<ITheGamesDBApiWrapperRestClientFactory>();
mock.Setup(x => x.Create(It.IsAny<string>())).Returns(() => this.mockRestClient<TResponse>(jsonfile));

Expand All @@ -99,10 +95,10 @@ public async Task DeveloperResponseShouldBeParsed()
ITheGamesDBAPI api = this.ServiceProvider.GetService<ITheGamesDBAPI>();

Check warning on line 95 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Converting null literal or possible null value to non-nullable type.
var response = await api.Developers.All();

Check warning on line 96 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Developers);
Assert.NotNull(response.Data.Developers.First().Value.Name);
response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.Developers.ShouldNotBeNull();
response.Data.Developers.First().Value.Name.ShouldNotBeNull();
}

[TestCaseSource(nameof(GameByIdMocks))]
Expand All @@ -111,35 +107,34 @@ public async Task GameByIdResponseShouldBeParsed(string mockfile)
this.mockServices<GamesByGameIDResponse>(mockfile);

ITheGamesDBAPI api = this.ServiceProvider.GetService<ITheGamesDBAPI>();

Check warning on line 109 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Converting null literal or possible null value to non-nullable type.
var response = await api.Games.ByGameID(new int[] { 1,2,3,4,5});
var response = await api.Games.ByGameID(new int[] { 1, 2, 3, 4, 5 });

Check warning on line 110 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Games);
Assert.NotNull(response.Data.Games.First().GameTitle);
response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.Games.ShouldNotBeNull();
response.Data.Games.First().GameTitle.ShouldNotBeNull();
}

public static object[] GameByIdMocks = {
new object[] { "game-by-id" },
new object[] { "game-by-id-2" }
};
new object[] { "game-by-id" },
new object[] { "game-by-id-2" }
};

[Test]
public async Task GameImagesResponseShouldBeParsed()
{
this.mockServices<GamesImagesResponse>("game-images");

ITheGamesDBAPI api = this.ServiceProvider.GetService<ITheGamesDBAPI>();

Check warning on line 128 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Converting null literal or possible null value to non-nullable type.
var response = await api.Games.Images(new int[] { 1});

Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.BaseUrl);
Assert.NotNull(response.Pages);
Assert.NotNull(response.Data.Images);
Assert.NotNull(response.Data.Images.First().Value.First().Type);
Assert.AreEqual(response.Data.Images.First().Value.First().Type, GameImageType.Fanart);

var response = await api.Games.Images(new int[] { 1 });

Check warning on line 129 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.BaseUrl.ShouldNotBeNull();
response.Pages.ShouldNotBeNull();
response.Data.Images.ShouldNotBeNull();
response.Data.Images.First().Value.First().Type.ShouldNotBeNull();
response.Data.Images.First().Value.First().Type.ShouldBe(GameImageType.Fanart);
}

[Test]
Expand All @@ -151,16 +146,14 @@ public async Task GameUpdateResponseShouldBeParsed()

var response = await api.Games.Updates(0);

Check warning on line 147 in tests/TheGamesDBApiWrapperTests/ApiTests.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Updates);
Assert.NotNull(response.Data.Updates.First().EditID);
Assert.NotNull(response.Data.Updates.First().GameID);
Assert.NotNull(response.Data.Updates.First().Timestamp);
Assert.NotNull(response.Data.Updates.First().Type);
Assert.NotNull(response.Data.Updates.First().Value);


response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.Updates.ShouldNotBeNull();
response.Data.Updates.First().EditID.ShouldNotBeNull();
response.Data.Updates.First().GameID.ShouldNotBeNull();
response.Data.Updates.First().Timestamp.ShouldNotBeNull();
response.Data.Updates.First().Type.ShouldNotBeNull();
response.Data.Updates.First().Value.ShouldNotBeNull();
}

[Test]
Expand All @@ -172,11 +165,10 @@ public async Task PlatformsResponseShouldBeParsed()

var response = await api.Platform.All();

Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Platforms);
Assert.NotNull(response.Data.Platforms.First().Value.Name);

response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.Platforms.ShouldNotBeNull();
response.Data.Platforms.First().Value.Name.ShouldNotBeNull();
}

[Test]
Expand All @@ -188,11 +180,10 @@ public async Task GenresResponseShouldBeParsed()

var response = await api.Genres.All();


Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Genres);
Assert.NotNull(response.Data.Genres.First().Value.Name);
response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.Genres.ShouldNotBeNull();
response.Data.Genres.First().Value.Name.ShouldNotBeNull();
}

[Test]
Expand All @@ -204,11 +195,10 @@ public async Task PublishersResponseShouldBeParsed()

var response = await api.Publishers.All();


Assert.NotNull(response.Code);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Publishers);
Assert.NotNull(response.Data.Publishers.First().Value.Name);
response.Code.ShouldBeGreaterThan(0);
response.Data.ShouldNotBeNull();
response.Data.Publishers.ShouldNotBeNull();
response.Data.Publishers.First().Value.Name.ShouldNotBeNull();
}

[Test]
Expand All @@ -221,12 +211,11 @@ public async Task AllowanceShouldBeTracked()

IAllowanceTracker tracker = this.ServiceProvider.GetService<IAllowanceTracker>();

Assert.NotNull(tracker.Current);
Assert.AreEqual(2916, tracker.Current.Remaining);
Assert.AreSame(api.AllowanceTrack, tracker.Current);
tracker.Current.ShouldNotBeNull();
tracker.Current.Remaining.ShouldBe(2916);
api.AllowanceTrack.ShouldBeSameAs(tracker.Current);
}

#endregion

}
}
21 changes: 12 additions & 9 deletions tests/TheGamesDBApiWrapperTests/TheGamesDBApiWrapperTests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="110.2.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit de91cfb

Please sign in to comment.