-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
453 additions
and
143 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Text.Json; | ||
using GuildWars2.Hero.Accounts; | ||
|
||
namespace GuildWars2.Tests.Features; | ||
|
||
public class EnumJsonSerializer | ||
{ | ||
[Fact] | ||
public void Has_json_conversion() | ||
{ | ||
var product = ProductName.GuildWars2; | ||
var json = JsonSerializer.Serialize(product); | ||
var actual = JsonSerializer.Deserialize<ProductName>(json); | ||
Assert.Equal(product, actual); | ||
} | ||
|
||
[Fact] | ||
public void Throws_for_undefined_values() | ||
{ | ||
Assert.Throws<ArgumentOutOfRangeException>( | ||
() => | ||
{ | ||
var product = (ProductName)69; | ||
_ = JsonSerializer.Serialize(product); | ||
} | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Text.Json.Serialization; | ||
using GuildWars2.Tests.TestInfrastructure; | ||
|
||
namespace GuildWars2.Tests.PatternsAndPractices; | ||
|
||
public class JsonConverterTest(AssemblyFixture fixture) : IClassFixture<AssemblyFixture> | ||
{ | ||
[Fact] | ||
public void AllEnumsShouldHaveJsonConverterAttribute() | ||
{ | ||
// Get all enum types in the assembly | ||
var enumTypes = fixture.Assembly.GetTypes() | ||
.Where(t => t is { IsEnum: true, IsPublic: true, Namespace: not null } && t.Namespace.StartsWith("GuildWars2")); | ||
|
||
Assert.All(enumTypes, | ||
enumType => | ||
{ | ||
var hasJsonConverterAttribute = | ||
enumType.GetCustomAttributes(typeof(JsonConverterAttribute), false).Any(); | ||
Assert.True( | ||
hasJsonConverterAttribute, | ||
$"Enum {enumType.Name} does not have a JsonConverterAttribute." | ||
); | ||
}); | ||
} | ||
} |
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.