コード例 #1
0
        public void JoinSessionShouldThrowInvalidOperationException()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();
            AwaitingSessionReservation           connectionState   = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            Action action = () => connectionState.JoinSession(connectionContext);

            // Assert
            action.Should().Throw <InvalidOperationException>();
        }
コード例 #2
0
        public void NegotiateShouldThrowInvalidOperationExceptionWhenTheReservationIsNull()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Reservation.Returns((MultiplayerSessionReservation)null);

            AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            Action action = () => connectionState.NegotiateReservation(connectionContext);

            // Assert
            action.Should().Throw <InvalidOperationException>();
        }
コード例 #3
0
        public void DisconnectShouldTransitionToDisconnectedState()
        {
            // Arrange
            IClient serverClient = Substitute.For <IClient>();
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Client.Returns(serverClient);

            AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            connectionState.Disconnect(connectionContext);

            // Assert
            connectionContext.Received().UpdateConnectionState(Arg.Any <Disconnected>());
        }
コード例 #4
0
        public void NegotiateShouldTransitionToSessionReservationRejectedAfterReceivingRejectedReservation()
        {
            // Arrange
            MultiplayerSessionReservation rejectedReservation = new MultiplayerSessionReservation(TestConstants.TEST_CORRELATION_ID, TestConstants.TEST_REJECTION_STATE);

            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Reservation.Returns(rejectedReservation);

            AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            connectionState.NegotiateReservation(connectionContext);

            // Assert
            connectionContext.Received().UpdateConnectionState(Arg.Any <SessionReservationRejected>());
        }
コード例 #5
0
        public void NegotiateShouldThrowUncorrelatedPacketExceptionWhenTheReservationHasTheWrongCorrelationId()
        {
            // Arrange
            MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation(
                "wrong",
                TestConstants.TEST_PLAYER_ID,
                TestConstants.TEST_RESERVATION_KEY);

            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Reservation.Returns(successfulReservation);

            AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            Action action = () => connectionState.NegotiateReservation(connectionContext);

            // Assert
            action.Should().Throw <UncorrelatedPacketException>();
        }