title: Prism TDD Unsubscribe()
body: <p>I'm using TDD and want to write a unit test for the Unsubscribe() method available in with PubSubEvent. Because there is no interface as you inherit from the parent class, which has no interface, so I don't know how to test it.</p>
  
  <p>My service and the method, I would like to test:</p>
  
  <pre><code>public class FrameService: IFrameService
  {
       private readonly IEventAggregator _eventAggregator;
  
       public void UnsubscribeEvents()
       {
           _eventAgregator.GetEvent&lt;FrameAddedEvent&gt;()
                          .Unsubscribe(FrameAddedEventHandler); // How to unit test this?
        }
   }
  </code></pre>
  
  <p>The FrameAddedEvent class, that inherit from the PubSubEvent from Prism library:</p>
  
  <pre><code>public class FrameAddedEvent: PubSubEvent&lt;Frame&gt;
  {
  }
  </code></pre>
  
  <p>Declaration in Prism's library:</p>
  
  <pre><code>public class PubSubEvent&lt;TPayload&gt; : EventBase
  {  
      public SubscriptionToken Subscribe(Action&lt;TPayload&gt; action);
  }
  </code></pre>
  
  <p>My test (using MSTest and Moq) for the first part of the code line.
  I need now another UnitTest with the assert on the Unsubscribe()</p>
  
  <pre><code>[TestClass]
  public class FrameServiceTest
  {
      private Mock&lt;IEventAgregator&gt; _eventAgregator;
  
      [TestMethod]
      public void When_SubscribeEvents_Then_Get_FrameAddedEvent_From_EventAggregator()
      {
          var frameAddedEvent = new FrameAddedEvent();
  
          _eventAgregator.Setup(x=&gt;x.GetEvent&lt;FrameAddedEvent&gt;())
                                     .Returns(frameAddedEvent);
  
          _frameService.SubscribeEvents();
  
          _serviceLayerEventAgregator.Verify(x =&gt; x.GetEvent&lt;FrameAddedEvent&gt;(), Times.Once);
      }
  }
  </code></pre>
  
  <p><strong>ANSWER:</strong>
  See comment below for the explanation, I'm just adding the code for people who might have the same problem as me.</p>
  
  <p>The fake class:</p>
  
  <pre><code>public class FakeFrameAddedEvent : FrameAddedEvent
  {
      public bool Unsubscribed { get; private set; }
  
      public FakeFrameAddedEvent()
      {
          Unsubscribed = false;
      }
  
      public override void Unsubscribe(Action&lt;Frame&gt; subscriber)
      {
          Unsubscribed = true;
      }
  }
  </code></pre>
  
  <p>And the new UnitTest:</p>
  
  <pre><code>    [TestMethod]
      public void When_UnsubscribeEvents_Then_Unsubscribe_Is_Call()
      {
          var frameAddedEvent = new FakeFrameAddedEvent();
  
          _serviceLayerEventAgregator.Setup(x =&gt; x.GetEvent&lt;FrameAddedEvent&gt;())
                                     .Returns(frameAddedEvent);
  
          _frameService.UnsubscribeEvents();
  
          Check.That(frameAddedEvent.Unsubscribed).IsTrue();
      }
  </code></pre>