title: Why does this FSM only succeed at one state transition?
body: <p>I have a very simple FSM that succeeds at doing one transition, but no more than that. I don't know if there's an error in the FSM or if there's an error in the test class.</p>
  
  <p>Here is a full reproducible example with unit tests:</p>
  
  <pre><code>using Akka;
  using Akka.Actor;
  using Akka.TestKit;
  using Akka.TestKit.Xunit;
  using System.Diagnostics;
  using Xunit;
  
  class MyFsm : FSM&lt;MyFsm.State, MyFsm.Data&gt;
  {
      public MyFsm()
      {
          StartWith(State.Idle, new Data());
  
          When(State.Idle, state =&gt;
          {
              var eventWasHandled = state.FsmEvent.Match()
                  .With&lt;MessageA&gt;(message =&gt; { return; })
                  .WasHandled;
  
              if (eventWasHandled)
              {
                  Debug.WriteLine($"{State.Idle} =&gt; transitioning to {State.Busy}");
                  return GoTo(State.Busy);
              }
              else
              {
                  Debug.WriteLine($"{State.Idle} =&gt; returning null");
                  return null;
              }
          });
  
          When(State.Busy, state =&gt;
          {
              var eventWasHandled = state.FsmEvent.Match()
                  .With&lt;MessageB&gt;(message =&gt; { return; })
                  .WasHandled;
  
              if (eventWasHandled)
              {
                  Debug.WriteLine($"{State.Busy} =&gt; transitioning to {State.Done}");
                  return GoTo(State.Done);
              }
              else
              {
                  Debug.WriteLine($"{State.Busy} =&gt; returning null");
                  return null;
              }
          });
  
          Initialize();
      }
  
      public enum State { Idle, Busy, Done }
  
      public class Data { }
  }
  
  class MessageA { }
  
  class MessageB { }
  
  public class MyFsmTests : TestKit
  {
      [Fact]
      public void Its_initial_state_is_Idle()
      {
          var myFsm = new TestFSMRef&lt;MyFsm, MyFsm.State, MyFsm.Data&gt;(Sys, Props.Create&lt;MyFsm&gt;());
  
          Assert.Equal(MyFsm.State.Idle, myFsm.StateName);
      }
  
      [Fact]
      public void It_transitions_to_the_Busy_state_after_receiving_MessageA()
      {
          var myFsm = new TestFSMRef&lt;MyFsm, MyFsm.State, MyFsm.Data&gt;(Sys, Props.Create&lt;MyFsm&gt;());
          myFsm.SetState(MyFsm.State.Idle);
  
          myFsm.Tell(new MessageA());
  
          Assert.Equal(MyFsm.State.Busy, myFsm.StateName);
      }
  
      [Fact]
      public void It_transitions_to_the_Done_state_after_receiving_MessageB_using_SetState()
      {
          var myFsm = new TestFSMRef&lt;MyFsm, MyFsm.State, MyFsm.Data&gt;(Sys, Props.Create&lt;MyFsm&gt;());
          myFsm.SetState(MyFsm.State.Busy);
  
          myFsm.Tell(new MessageB());
  
          Assert.Equal(MyFsm.State.Done, myFsm.StateName);
      }
  
      [Fact]
      public void It_transitions_to_the_Done_state_after_receiving_MessageB_without_using_SetState()
      {
          var myFsm = new TestFSMRef&lt;MyFsm, MyFsm.State, MyFsm.Data&gt;(Sys, Props.Create&lt;MyFsm&gt;());
  
          myFsm.Tell(new MessageA());
          myFsm.Tell(new MessageB());
  
          Assert.Equal(MyFsm.State.Done, myFsm.StateName);
      }
  }
  </code></pre>
  
  <ul>
  <li>Its_initial_state_is_Idle
  
  <ul>
  <li>result: Test Passed</li>
  <li>output: n/a</li>
  </ul></li>
  <li>It_transitions_to_the_Busy_state_after_receiving_MessageA
  
  <ul>
  <li>result: Test Passed</li>
  <li>output: <code>Idle =&gt; transitioning to Busy</code></li>
  </ul></li>
  <li>It_transitions_to_the_Done_state_after_receiving_MessageB_using_SetState
  
  <ul>
  <li>result: Test Failed <code>Assert.Equal() Failure  Expected: Done  Actual: Busy</code></li>
  <li>output: <code>Busy =&gt; transitioning to Done</code></li>
  </ul></li>
  <li>It_transitions_to_the_Done_state_after_receiving_MessageB_without_using_SetState
  
  <ul>
  <li>result: Test Failed <code>Assert.Equal() Failure  Expected: Done  Actual: Busy</code></li>
  <li>output: <code>Idle =&gt; transitioning to Busy</code> <code>Busy =&gt; transitioning to Done</code></li>
  </ul></li>
  </ul>
  
  <p>I've gone through the docs multiple times and can't find any glaring error in the code. What am I missing?</p>