-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathReplayBookmarkDatabaseTests.cs
More file actions
100 lines (84 loc) · 3.19 KB
/
Copy pathReplayBookmarkDatabaseTests.cs
File metadata and controls
100 lines (84 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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 System;
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Scoring;
namespace osu.Game.Tests.Database
{
[TestFixture]
public class ReplayBookmarkDatabaseTests : RealmTest
{
[Test]
public void TestBookmarksPersist()
{
RunTestWithRealmAsync(async (realm, _) =>
{
Guid id = Guid.NewGuid();
await realm.WriteAsync(r =>
{
var ruleset = CreateRuleset();
r.Add(ruleset);
r.Add(new ScoreInfo(ruleset: ruleset, beatmap: new BeatmapInfo(ruleset: ruleset)) { ID = id });
});
await realm.WriteAsync(r =>
{
var si = r.Find<ScoreInfo>(id)!;
si.ReplayBookmarks.Add(1000);
si.ReplayBookmarks.Add(5000);
si.ReplayBookmarks.Add(12000);
});
realm.Run(r => r.Refresh());
int[] bookmarks = realm.Run(r => r.Find<ScoreInfo>(id)!.ReplayBookmarks.ToArray());
Assert.That(bookmarks, Is.EqualTo(new[] { 1000, 5000, 12000 }));
});
}
[Test]
public void TestBookmarksClearedAndReplaced()
{
RunTestWithRealmAsync(async (realm, _) =>
{
Guid id = Guid.NewGuid();
await realm.WriteAsync(r =>
{
var ruleset = CreateRuleset();
r.Add(ruleset);
r.Add(new ScoreInfo(ruleset: ruleset, beatmap: new BeatmapInfo(ruleset: ruleset)) { ID = id });
});
await realm.WriteAsync(r =>
{
var si = r.Find<ScoreInfo>(id)!;
si.ReplayBookmarks.Add(1000);
si.ReplayBookmarks.Add(2000);
});
await realm.WriteAsync(r =>
{
var si = r.Find<ScoreInfo>(id)!;
si.ReplayBookmarks.Clear();
si.ReplayBookmarks.Add(9000);
});
realm.Run(r => r.Refresh());
int[] bookmarks = realm.Run(r => r.Find<ScoreInfo>(id)!.ReplayBookmarks.ToArray());
Assert.That(bookmarks, Is.EqualTo(new[] { 9000 }));
});
}
[Test]
public void TestNoBookmarksReturnsEmpty()
{
RunTestWithRealmAsync(async (realm, _) =>
{
Guid id = Guid.NewGuid();
await realm.WriteAsync(r =>
{
var ruleset = CreateRuleset();
r.Add(ruleset);
r.Add(new ScoreInfo(ruleset: ruleset, beatmap: new BeatmapInfo(ruleset: ruleset)) { ID = id });
});
realm.Run(r => r.Refresh());
int[] bookmarks = realm.Run(r => r.Find<ScoreInfo>(id)!.ReplayBookmarks.ToArray());
Assert.That(bookmarks, Is.Empty);
});
}
}
}