Add test coverage of ruleset being marked unavailable if methods are throwing

This commit is contained in:
Dean Herbert 2022-08-29 14:28:55 +09:00
parent 5ff4e6a4fe
commit 892f43da43
1 changed files with 30 additions and 5 deletions

View File

@ -60,15 +60,40 @@ public void TestRetrievedRulesetsAreDetached()
});
}
[Test]
public void TestRulesetThrowingOnMethods()
{
RunTestWithRealm((realm, storage) =>
{
LoadTestRuleset.Version = Ruleset.CURRENT_RULESET_API_VERSION;
LoadTestRuleset.HasImplementations = false;
var ruleset = new LoadTestRuleset();
string rulesetShortName = ruleset.RulesetInfo.ShortName;
realm.Write(r => r.Add(new RulesetInfo(rulesetShortName, ruleset.RulesetInfo.Name, ruleset.RulesetInfo.InstantiationInfo, ruleset.RulesetInfo.OnlineID)
{
Available = true,
}));
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.True);
// Availability is updated on construction of a RealmRulesetStore
var _ = new RealmRulesetStore(realm, storage);
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.False);
});
}
[Test]
public void TestOutdatedRulesetNotAvailable()
{
RunTestWithRealm((realm, storage) =>
{
OutdatedRuleset.Version = "2021.101.0";
OutdatedRuleset.HasImplementations = true;
LoadTestRuleset.Version = "2021.101.0";
LoadTestRuleset.HasImplementations = true;
var ruleset = new OutdatedRuleset();
var ruleset = new LoadTestRuleset();
string rulesetShortName = ruleset.RulesetInfo.ShortName;
realm.Write(r => r.Add(new RulesetInfo(rulesetShortName, ruleset.RulesetInfo.Name, ruleset.RulesetInfo.InstantiationInfo, ruleset.RulesetInfo.OnlineID)
@ -84,14 +109,14 @@ public void TestOutdatedRulesetNotAvailable()
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.False);
// Simulate the ruleset getting updated
OutdatedRuleset.Version = Ruleset.CURRENT_RULESET_API_VERSION;
LoadTestRuleset.Version = Ruleset.CURRENT_RULESET_API_VERSION;
var __ = new RealmRulesetStore(realm, storage);
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.True);
});
}
private class OutdatedRuleset : Ruleset
private class LoadTestRuleset : Ruleset
{
public override string RulesetAPIVersionSupported => Version;