public void ModelAttemptTest() { bool condition = false, onFireCalled = false, onFailCalled = false; ModelAttempt attempt = new ModelAttempt(); attempt.RegisterCondition(() => condition); attempt.onFire += () => { onFireCalled = true; }; attempt.onFail += () => { onFailCalled = true; }; // Test fail onFailCalled = false; Assert.IsFalse(attempt.Can()); Assert.IsFalse(attempt.Try()); Assert.IsTrue(onFailCalled); // Test success onFireCalled = false; condition = true; Assert.IsTrue(attempt.Can()); Assert.IsTrue(attempt.Try()); Assert.IsTrue(onFireCalled); _ModelAttemptTTest(); _ModelAttemptT1T2Test(); }
private void _ModelAttemptT1T2Test() { int p = 123, p2 = 1337; bool condition = false, onFireCalled = false, onFailCalled = false; ModelAttempt <int, int> attempt = new ModelAttempt <int, int>(); attempt.RegisterCondition((test, test2) => { Assert.AreEqual(p, test); Assert.AreEqual(p2, test2); return(condition); }); attempt.onFire += (test, test2) => { Assert.AreEqual(p, test); Assert.AreEqual(p2, test2); onFireCalled = true; }; attempt.onFail += (test, test2) => { Assert.AreEqual(p, test); Assert.AreEqual(p2, test2); onFailCalled = true; }; // Test fail onFailCalled = false; Assert.IsFalse(attempt.Can(p, p2)); Assert.IsFalse(attempt.Try(p, p2)); Assert.IsTrue(onFailCalled); // Test success onFireCalled = false; condition = true; Assert.IsTrue(attempt.Can(p, p2)); Assert.IsTrue(attempt.Try(p, p2)); Assert.IsTrue(onFireCalled); }