Add SubstateOf
MODIFY
WalletWasabi.Tests/UnitTests/StateMachineTests.cs
WalletWasabi.Tests/UnitTests/StateMachineTests.cs
using FluentAssertions;
-using WalletWasabi.Fluent.State;
+using Stateless;
using Xunit;
using Xunit.Abstractions;
@@ -81,6 +81,32 @@ public class StateMachineTests
entered.Should().BeTrue();
}
+ [Fact]
+ public void Substate()
+ {
+ var hasDisconnected = false;
+
+ StateMachine<PhoneState, PhoneTrigger> sut = new(PhoneState.Disconnected);
+ sut.Configure(PhoneState.Disconnected)
+ .Permit(PhoneTrigger.Connect, PhoneState.Connected);
+ sut.Configure(PhoneState.OnHold)
+ .SubstateOf(PhoneState.Connected)
+ .OnExit(() => hasDisconnected = true);
+ sut.Configure(PhoneState.Connected)
+ .Permit(PhoneTrigger.PutOnHold, PhoneState.OnHold);
+
+ sut.Fire(PhoneTrigger.Connect);
+ sut.Fire(PhoneTrigger.PutOnHold);
+
+ hasDisconnected.Should().BeFalse();
+ }
+
+ public enum PhoneState
+ {
+ Disconnected,
+ OnHold,
+ Connected
+ }
public enum Trigger
{
@@ -93,4 +119,10 @@ public class StateMachineTests
Locked,
Unlocked
}
+
+ public enum PhoneTrigger
+ {
+ Connect,
+ PutOnHold
+ }
}
\ No newline at end of file

Add SubstateOf