public void Communication_MustNotStopSessionWithoutActiveSession()
        {
            var args = new SessionStopEventArgs {
                SessionId = Guid.NewGuid()
            };

            bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);
            sessionContext.IsRunning = false;

            sut.TryStart();
            serviceHost.Raise(h => h.SessionStopRequested += null, args);

            sessionSequence.Verify(s => s.TryRevert(), Times.Never);
        }
        public void Communication_MustStopActiveSessionUponRequest()
        {
            var args = new SessionStopEventArgs {
                SessionId = Guid.NewGuid()
            };

            bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);
            sessionContext.Configuration = new ServiceConfiguration {
                SessionId = args.SessionId
            };
            sessionContext.IsRunning = true;

            sut.TryStart();
            serviceHost.Raise(h => h.SessionStopRequested += null, args);

            sessionSequence.Verify(s => s.TryRevert(), Times.Once);
        }
 private void ServiceHost_SessionStopRequested(SessionStopEventArgs args)
 {
     if (SessionIsRunning)
     {
         if (Session.SessionId == args.SessionId)
         {
             StopSession();
         }
         else
         {
             logger.Warn("Received session stop request with wrong session ID!");
         }
     }
     else
     {
         logger.Warn("Received session stop request, even though no session is currently running!");
     }
 }