title: Unit testing ReactiveUI view models and commands
body: <p>I have a working view implemented using ReactiveUI and now I'm trying to write some unit tests for my view model, but my view model doesn't seem to work when used from the test. </p>
  
  <p>Specifically, executing commands does not seem to trigger the subscribers. In this test below, I am invoking the AddPlayer command but the subscribed handler does not run:</p>
  
  <pre><code>public class NewGameViewModelTests
  {
      private NewGameViewModel viewmodel;
  
      public NewGameViewModelTests()
      {
          viewmodel = new NewGameViewModel();            
      }
  
      [Fact]
      public void CanAddUpToSevenPlayers()
      {
          foreach(var i in Enumerable.Range(1, 7))
          {
              viewmodel.NewPlayerName = "Player" + i;
              viewmodel.AddPlayer.Execute(null);
              Assert.Equal(i, viewmodel.Players.Count);
          }
      }
  }
  </code></pre>
  
  <p>Here's the view model I'm testing:</p>
  
  <pre><code>public class NewGameViewModel : ReactiveObject
  {
      public ReactiveList&lt;string&gt; Players { get; private set; }
      public ReactiveCommand&lt;Object&gt; AddPlayer { get; private set; }
      public ReactiveCommand&lt;Object&gt; RemovePlayer { get; private set; }
      public ReactiveCommand&lt;Object&gt; StartGame { get; private set; }
      public ReactiveCommand&lt;Object&gt; RandomizeOrder { get; private set; }
  
  
      string newPlayerName;
      public string NewPlayerName {
          get { return newPlayerName; }
          set { this.RaiseAndSetIfChanged(ref newPlayerName, value); }
      }
  
      public NewGameViewModel()
      {
          Players = new ReactiveList&lt;string&gt; ();
  
          var canStart = this.Players.CountChanged.Select(count =&gt; count &gt;= 3);
          StartGame = canStart.ToCommand();
          RandomizeOrder = canStart.ToCommand();
  
          RemovePlayer = ReactiveCommand.Create();
          AddPlayer = this.WhenAnyValue(x =&gt; x.Players.Count, x =&gt; x.NewPlayerName,
              (count, newPlayerName) =&gt; count &lt; 7 &amp;&amp; !string.IsNullOrWhiteSpace(newPlayerName) &amp;&amp; !this.Players.Contains(newPlayerName))
              .ToCommand();
  
          RandomizeOrder.Subscribe(_ =&gt;
          {
              using (Players.SuppressChangeNotifications())
              {
                  var r = new Random();
                  var newOrder = Players.OrderBy(x =&gt; r.NextDouble()).ToList();
                  Players.Clear();
                  Players.AddRange(newOrder);
              }
          });
  
          RemovePlayer.Subscribe(player =&gt;
          {
              this.Players.Remove((string)player);
          });
  
          AddPlayer.Subscribe(_ =&gt;
          {
              Players.Add(NewPlayerName.Trim());
              NewPlayerName = string.Empty;
          });
      }
  }
  </code></pre>