-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement character controller Setup controllers Remove Slim Switch to System.Text.Json
- Loading branch information
1 parent
95b0f3f
commit 30e1dab
Showing
32 changed files
with
447 additions
and
213 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
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
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
38 changes: 38 additions & 0 deletions
38
GuildWarsPartySearch.Tests/Services/CharName/CharNameValidatorTests.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,38 @@ | ||
using FluentAssertions; | ||
using GuildWarsPartySearch.Server.Services.CharName; | ||
|
||
namespace GuildWarsPartySearch.Tests.Services.CharName; | ||
|
||
[TestClass] | ||
public sealed class CharNameValidatorTests | ||
{ | ||
private readonly CharNameValidator charNameValidator; | ||
|
||
public CharNameValidatorTests() | ||
{ | ||
this.charNameValidator = new CharNameValidator(); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("-eq", false)] //Invalid chars | ||
[DataRow(";_;_;", false)] //Invalid chars | ||
[DataRow("D@ddy UwU", false)] //Invalid chars | ||
[DataRow("Kormir Fr3@kin Sucks", false)] // Invalid chars | ||
[DataRow("Myself", false)] // Only one word | ||
[DataRow("Fentanyl Ascetic", true)] //Correct | ||
[DataRow("Kormir", false)] // Only one word | ||
[DataRow("Kormir Sucks", true)] // Correct | ||
[DataRow("Bob'); DROP TABLE", false)] // Invalid chars | ||
[DataRow("Why are we still here, just to suffer", false)] // Too long + Invalid chars | ||
[DataRow("Why are we still here just to suffer", false)] // Too long | ||
[DataRow(null, false)] // Null | ||
[DataRow("", false)] // Empty | ||
[DataRow(" ", false)] // Whitespace | ||
[DataRow(" ", false)] // Whitespace | ||
[DataRow("Me", false)] // Too short | ||
public void ValidateNames_ShouldReturnExpected(string name, bool expected) | ||
{ | ||
var result = this.charNameValidator.Validate(name); | ||
result.Should().Be(expected); | ||
} | ||
} |
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,6 @@ | ||
namespace GuildWarsPartySearch.Server.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Constructor)] | ||
public class DoNotInjectAttribute : Attribute | ||
{ | ||
} |
15 changes: 8 additions & 7 deletions
15
GuildWarsPartySearch/Converters/Base64ToCertificateConverter.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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
using Newtonsoft.Json; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWarsPartySearch.Server.Converters; | ||
|
||
public sealed class Base64ToCertificateConverter : JsonConverter<X509Certificate2> | ||
{ | ||
public override X509Certificate2? ReadJson(JsonReader reader, Type objectType, X509Certificate2? existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
public override X509Certificate2? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.Value is not string base64) | ||
if (reader.GetString() is not string base64) | ||
{ | ||
throw new InvalidOperationException($"Cannot deserialize {nameof(X509Certificate2)} from {reader.Value}"); | ||
throw new InvalidOperationException($"Cannot deserialize {nameof(X509Certificate2)} from {reader.GetString()}"); | ||
} | ||
|
||
var bytes = Convert.FromBase64String(base64); | ||
return new X509Certificate2(bytes); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, X509Certificate2? value, JsonSerializer serializer) | ||
public override void Write(Utf8JsonWriter writer, X509Certificate2 value, JsonSerializerOptions options) | ||
{ | ||
var base64 = Convert.ToBase64String(value!.GetRawCertData()); | ||
writer.WriteValue(base64); | ||
writer.WriteStringValue(base64); | ||
} | ||
} |
Oops, something went wrong.