private static Score encodeThenDecode(int beatmapVersion, Score score, TestBeatmap beatmap) { var encodeStream = new MemoryStream(); var encoder = new LegacyScoreEncoder(score, beatmap); encoder.Encode(encodeStream); var decodeStream = new MemoryStream(encodeStream.GetBuffer()); var decoder = new TestLegacyScoreDecoder(beatmapVersion); var decodedAfterEncode = decoder.Parse(decodeStream); return(decodedAfterEncode); }
public void TestCultureInvariance() { var ruleset = new OsuRuleset().RulesetInfo; var scoreInfo = new TestScoreInfo(ruleset); var beatmap = new TestBeatmap(ruleset); var score = new Score { ScoreInfo = scoreInfo, Replay = new Replay { Frames = new List <ReplayFrame> { new OsuReplayFrame(2000, OsuPlayfield.BASE_SIZE / 2, OsuAction.LeftButton) } } }; // the "se" culture is used here, as it encodes the negative number sign as U+2212 MINUS SIGN, // rather than the classic ASCII U+002D HYPHEN-MINUS. CultureInfo.CurrentCulture = new CultureInfo("se"); var encodeStream = new MemoryStream(); var encoder = new LegacyScoreEncoder(score, beatmap); encoder.Encode(encodeStream); var decodeStream = new MemoryStream(encodeStream.GetBuffer()); var decoder = new TestLegacyScoreDecoder(); var decodedAfterEncode = decoder.Parse(decodeStream); Assert.Multiple(() => { Assert.That(decodedAfterEncode, Is.Not.Null); Assert.That(decodedAfterEncode.ScoreInfo.User.Username, Is.EqualTo(scoreInfo.User.Username)); Assert.That(decodedAfterEncode.ScoreInfo.BeatmapInfoID, Is.EqualTo(scoreInfo.BeatmapInfoID)); Assert.That(decodedAfterEncode.ScoreInfo.Ruleset, Is.EqualTo(scoreInfo.Ruleset)); Assert.That(decodedAfterEncode.ScoreInfo.TotalScore, Is.EqualTo(scoreInfo.TotalScore)); Assert.That(decodedAfterEncode.ScoreInfo.MaxCombo, Is.EqualTo(scoreInfo.MaxCombo)); Assert.That(decodedAfterEncode.ScoreInfo.Date, Is.EqualTo(scoreInfo.Date)); Assert.That(decodedAfterEncode.Replay.Frames.Count, Is.EqualTo(1)); }); }