mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Refine RealmContext
implementation API
This commit is contained in:
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
storage = new NativeStorage(directory.FullName);
|
||||
|
||||
realmContextFactory = new RealmContextFactory(storage);
|
||||
realmContextFactory = new RealmContextFactory(storage, "test");
|
||||
keyBindingStore = new RealmKeyBindingStore(realmContextFactory);
|
||||
}
|
||||
|
||||
@ -53,9 +53,9 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
private int queryCount(GlobalAction? match = null)
|
||||
{
|
||||
using (var usage = realmContextFactory.GetForRead())
|
||||
using (var realm = realmContextFactory.CreateContext())
|
||||
{
|
||||
var results = usage.Realm.All<RealmKeyBinding>();
|
||||
var results = realm.All<RealmKeyBinding>();
|
||||
if (match.HasValue)
|
||||
results = results.Where(k => k.ActionInt == (int)match.Value);
|
||||
return results.Count();
|
||||
@ -69,26 +69,24 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
keyBindingStore.Register(testContainer, Enumerable.Empty<RulesetInfo>());
|
||||
|
||||
using (var primaryUsage = realmContextFactory.GetForRead())
|
||||
using (var primaryRealm = realmContextFactory.CreateContext())
|
||||
{
|
||||
var backBinding = primaryUsage.Realm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||
var backBinding = primaryRealm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||
|
||||
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.Escape }));
|
||||
|
||||
var tsr = ThreadSafeReference.Create(backBinding);
|
||||
|
||||
using (var usage = realmContextFactory.GetForWrite())
|
||||
using (var threadedContext = realmContextFactory.CreateContext())
|
||||
{
|
||||
var binding = usage.Realm.ResolveReference(tsr);
|
||||
binding.KeyCombination = new KeyCombination(InputKey.BackSpace);
|
||||
|
||||
usage.Commit();
|
||||
var binding = threadedContext.ResolveReference(tsr);
|
||||
threadedContext.Write(() => binding.KeyCombination = new KeyCombination(InputKey.BackSpace));
|
||||
}
|
||||
|
||||
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
||||
|
||||
// check still correct after re-query.
|
||||
backBinding = primaryUsage.Realm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||
backBinding = primaryRealm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user