2022-03-08 08:58:52 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Game.IO.Serialization;
|
2022-07-25 10:43:19 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2023-12-08 08:27:12 +00:00
|
|
|
|
using osu.Game.Scoring;
|
2022-03-08 08:58:52 +00:00
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Online
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Basic testing to ensure our attribute-based naming is correctly working.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TestFixture]
|
2022-07-25 10:43:19 +00:00
|
|
|
|
public class TestSoloScoreInfoJsonSerialization
|
2022-03-08 08:58:52 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestScoreSerialisationViaExtensionMethod()
|
|
|
|
|
{
|
2022-07-25 10:43:19 +00:00
|
|
|
|
var score = SoloScoreInfo.ForSubmission(TestResources.CreateTestScoreInfo());
|
2022-03-08 08:58:52 +00:00
|
|
|
|
|
|
|
|
|
string serialised = score.Serialize();
|
|
|
|
|
|
|
|
|
|
Assert.That(serialised, Contains.Substring("large_tick_hit"));
|
|
|
|
|
Assert.That(serialised, Contains.Substring("\"rank\": \"S\""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestScoreSerialisationWithoutSettings()
|
|
|
|
|
{
|
2022-07-25 10:43:19 +00:00
|
|
|
|
var score = SoloScoreInfo.ForSubmission(TestResources.CreateTestScoreInfo());
|
2022-03-08 08:58:52 +00:00
|
|
|
|
|
|
|
|
|
string serialised = JsonConvert.SerializeObject(score);
|
|
|
|
|
|
|
|
|
|
Assert.That(serialised, Contains.Substring("large_tick_hit"));
|
|
|
|
|
Assert.That(serialised, Contains.Substring("\"rank\":\"S\""));
|
|
|
|
|
}
|
2023-12-08 08:27:12 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures that the proxy implementations of <see cref="IScoreInfo"/> by <see cref="SoloScoreInfo"/>
|
|
|
|
|
/// do not get serialised to JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestScoreSerialisationSkipsInterfaceMembers()
|
|
|
|
|
{
|
|
|
|
|
var score = SoloScoreInfo.ForSubmission(TestResources.CreateTestScoreInfo());
|
|
|
|
|
|
|
|
|
|
string[] variants =
|
|
|
|
|
{
|
|
|
|
|
JsonConvert.SerializeObject(score),
|
|
|
|
|
score.Serialize()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (string serialised in variants)
|
|
|
|
|
{
|
|
|
|
|
Assert.That(serialised, Does.Not.Contain("\"online_id\":"));
|
|
|
|
|
Assert.That(serialised, Does.Not.Contain("\"user\":"));
|
|
|
|
|
Assert.That(serialised, Does.Not.Contain("\"date\":"));
|
|
|
|
|
Assert.That(serialised, Does.Not.Contain("\"legacy_online_id\":"));
|
|
|
|
|
Assert.That(serialised, Does.Not.Contain("\"beatmap\":"));
|
|
|
|
|
Assert.That(serialised, Does.Not.Contain("\"ruleset\":"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-08 08:58:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|