Skip to content

Commit

Permalink
Create JsonTests.cs
Browse files Browse the repository at this point in the history
Test cases around supporting HTTP response that are specifically a primitive value instead of a json object.
  • Loading branch information
GravityWolfNotAmused committed Sep 13, 2022
1 parent a3a364f commit 5c33720
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions DiscordPlayerCountBot.Tests/JsonTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using DiscordPlayerCountBot.Json;

namespace DiscordPlayerCountBot.Tests;

[Collection("Json Serialization Test Suite")]
public class JsonTests
{
[Fact(DisplayName = "Test Primitives Float", Timeout = 30)]
public void SerializePrimitivesFloat()
{
var testFloat = JsonHelper.DeserializeObject<float>("2.23");

Assert.True(testFloat == (float)2.23, $"{testFloat}");
Assert.True(testFloat.GetType() == typeof(float));
}

[Fact(DisplayName = "Test Primitives Double", Timeout = 30)]
public void SerializePrimitivesDouble()
{
var testDouble = JsonHelper.DeserializeObject<double>("200.00");

Assert.True(testDouble == 200.00);
Assert.True(testDouble.GetType() == typeof(double));

}

[Fact(DisplayName = "Test Primitives Char", Timeout = 30)]
public void SerializePrimitivesChar()
{
var testChar = JsonHelper.DeserializeObject<char>("3");

Assert.True(testChar == '3');
Assert.True(testChar.GetType() == typeof(char));
}

[Fact(DisplayName = "Test Primitives Bool", Timeout = 30)]
public void SerializePrimitivesBool()
{
var testBooleanTrue = JsonHelper.DeserializeObject<bool>("true");

Assert.True(testBooleanTrue);
Assert.True(testBooleanTrue.GetType() == typeof(bool));

var testBooleanFalse = JsonHelper.DeserializeObject<bool>("false");

Assert.True(!testBooleanFalse);
Assert.True(testBooleanFalse.GetType() == typeof(bool));
}

[Fact(DisplayName = "Test Primitives Int", Timeout = 30)]
public void SerializePrimitivesInt()
{
var testInt = JsonHelper.DeserializeObject<int>("100");

Assert.True(testInt == 100);
Assert.True(testInt.GetType() == typeof(int));
}

[Fact(DisplayName = "Test Strings", Timeout = 30)]
public void SerializeStrings()
{
var testString = JsonHelper.DeserializeObject<string>("test") ?? "";

Assert.True(!string.IsNullOrEmpty(testString), "Should not be null or empty.");
Assert.True(!string.IsNullOrWhiteSpace(testString), "Should not be null or whitespace.");
Assert.Equal("test", testString, true, true, true);
Assert.True(testString.GetType() == typeof(string));
}
}

0 comments on commit 5c33720

Please sign in to comment.