generated from JustArchiNET/ASF-PluginTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from maxisoft/options_saver
Improve ASF-FreeGames: JSON serialization, error handling, and HttpClient optimizations
- Loading branch information
Showing
11 changed files
with
676 additions
and
36 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
ASFFreeGames.Tests/Configurations/ASFFreeGamesOptionsSaverTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Text.Json; | ||
using ASFFreeGames.Configurations; | ||
using Xunit; | ||
|
||
namespace Maxisoft.ASF.Tests.Configurations; | ||
|
||
public class ASFFreeGamesOptionsSaverTests { | ||
[Fact] | ||
#pragma warning disable CA1707 | ||
public async void SaveOptions_WritesValidJson_And_ParsesCorrectly() { | ||
#pragma warning restore CA1707 | ||
|
||
// Arrange | ||
ASFFreeGamesOptions options = new() { | ||
RecheckInterval = TimeSpan.FromHours(1), | ||
RandomizeRecheckInterval = true, | ||
SkipFreeToPlay = false, | ||
SkipDLC = true, | ||
Blacklist = new HashSet<string> { | ||
"game1", | ||
"game2", | ||
"a gamewith2xquote(\")'", | ||
"game with strange char €$çêà /\\\n\r\t" | ||
}, | ||
VerboseLog = null, | ||
Proxy = "http://localhost:1080", | ||
RedditProxy = "socks5://192.168.1.1:1081" | ||
}; | ||
|
||
using MemoryStream memoryStream = new(); | ||
|
||
// Act | ||
_ = await ASFFreeGamesOptionsSaver.SaveOptions(memoryStream, options).ConfigureAwait(false); | ||
|
||
// Assert - Validate UTF-8 encoding | ||
memoryStream.Position = 0; | ||
Assert.NotEmpty(Encoding.UTF8.GetString(memoryStream.ToArray())); | ||
|
||
// Assert - Parse JSON and access properties | ||
memoryStream.Position = 0; | ||
string json = Encoding.UTF8.GetString(memoryStream.ToArray()); | ||
ASFFreeGamesOptions? deserializedOptions = JsonSerializer.Deserialize<ASFFreeGamesOptions>(json); | ||
|
||
Assert.NotNull(deserializedOptions); | ||
Assert.Equal(options.RecheckInterval, deserializedOptions.RecheckInterval); | ||
Assert.Equal(options.RandomizeRecheckInterval, deserializedOptions.RandomizeRecheckInterval); | ||
Assert.Equal(options.SkipFreeToPlay, deserializedOptions.SkipFreeToPlay); | ||
Assert.Equal(options.SkipDLC, deserializedOptions.SkipDLC); | ||
Assert.Equal(options.Blacklist, deserializedOptions.Blacklist); | ||
Assert.Equal(options.VerboseLog, deserializedOptions.VerboseLog); | ||
Assert.Equal(options.Proxy, deserializedOptions.Proxy); | ||
Assert.Equal(options.RedditProxy, deserializedOptions.RedditProxy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.