Created
December 12, 2016 10:32
-
-
Save Protonz/e405feb699a8ff70cd201ea4c5b7cd23 to your computer and use it in GitHub Desktop.
Testing out the ReactiveCommand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UniRxUnitTests { | |
[Test] | |
public void ReactiveCommandTest_2() { | |
// Arrange | |
ReactiveProperty<long> CurrentHp = new ReactiveProperty<long>(100); | |
// Only allow when the player is dead | |
// ReactiveCommand Resurrect = CurrentHp.Select(hp=> return hp <= 0).ToReactiveCommand(); | |
int canExecuteCalled = 0; | |
ReactiveCommand Resurrect = CurrentHp.Select(hp=> { canExecuteCalled++; return hp <= 0; }).ToReactiveCommand(); | |
Resurrect.Subscribe(_ => CurrentHp.Value = 100); // 1 | |
// Act | |
CurrentHp.Value -= 10; // 2 | |
CurrentHp.Value -= 10; // 3 | |
CurrentHp.Value -= 10; // 4 | |
// Assert | |
Assert.AreEqual(70, CurrentHp.Value); | |
Assert.AreEqual(4, canExecuteCalled, "canExecuteCalled"); | |
// Act | |
Resurrect.Execute(); | |
// Assert | |
Assert.AreEqual(70, CurrentHp.Value); | |
Assert.AreEqual(4, canExecuteCalled, "canExecuteCalled"); | |
// Act | |
CurrentHp.Value = 0; // 5 | |
Resurrect.Execute(); // 6 | |
// Assert | |
Assert.AreEqual(100, CurrentHp.Value); | |
Assert.AreEqual(6, canExecuteCalled, "canExecuteCalled"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment