first commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using NitroxClient.Communication.Abstract;
|
||||
using NSubstitute;
|
||||
|
||||
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
|
||||
{
|
||||
[TestClass]
|
||||
public class SessionJoinedStateTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void NegotiateShouldThrowInvalidOperationException()
|
||||
{
|
||||
// Arrange
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
SessionJoined connectionState = new SessionJoined();
|
||||
|
||||
// Act
|
||||
Action action = () => connectionState.NegotiateReservationAsync(connectionContext);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void JoinSessionShouldThrowInvalidOperationExcepion()
|
||||
{
|
||||
// Arrange
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
SessionJoined connectionState = new SessionJoined();
|
||||
|
||||
// Act
|
||||
Action action = () => connectionState.JoinSession(connectionContext);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldStopTheClient()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionJoined connectionState = new SessionJoined();
|
||||
|
||||
// Act
|
||||
connectionState.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
serverClient.Received().Stop();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldResetTheConnectionContext()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionJoined connectionState = new SessionJoined();
|
||||
|
||||
// Act
|
||||
connectionState.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().ClearSessionState();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldTransitionToDisconnectedState()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionJoined connection = new SessionJoined();
|
||||
|
||||
// Act
|
||||
connection.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().UpdateConnectionState(Arg.Any<Disconnected>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using NitroxClient.Communication.Abstract;
|
||||
using NSubstitute;
|
||||
|
||||
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
|
||||
{
|
||||
[TestClass]
|
||||
public class SessionReservationRejectedStateTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void NegotiateShouldThrowInvalidOperationException()
|
||||
{
|
||||
// Arrange
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
SessionReservationRejected connectionState = new SessionReservationRejected();
|
||||
|
||||
// Act
|
||||
Action action = () => connectionState.NegotiateReservationAsync(connectionContext);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void JoinSessionShouldThrowInvalidOperationExcepion()
|
||||
{
|
||||
// Arrange
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
SessionReservationRejected connectionState = new SessionReservationRejected();
|
||||
|
||||
// Act
|
||||
Action action = () => connectionState.JoinSession(connectionContext);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldStopTheClient()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReservationRejected connectionState = new SessionReservationRejected();
|
||||
|
||||
// Act
|
||||
connectionState.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
serverClient.Received().Stop();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldResetTheConnectionContext()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReservationRejected connectionState = new SessionReservationRejected();
|
||||
|
||||
// Act
|
||||
connectionState.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().ClearSessionState();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldTransitionToDisconnectedState()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReservationRejected connection = new SessionReservationRejected();
|
||||
|
||||
// Act
|
||||
connection.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().UpdateConnectionState(Arg.Any<Disconnected>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Nitrox.Test.Client.Communication.MultiplayerSession;
|
||||
using NitroxClient.Communication.Abstract;
|
||||
using NitroxModel.Packets;
|
||||
using NSubstitute;
|
||||
|
||||
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
|
||||
{
|
||||
[TestClass]
|
||||
public class SessionReservedStateTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void NegotiateShouldThrowInvalidOperationException()
|
||||
{
|
||||
// Arrange
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
SessionReserved connectionState = new SessionReserved();
|
||||
|
||||
// Act
|
||||
Action action = () => connectionState.NegotiateReservationAsync(connectionContext);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void JoinSessionShouldSendPlayerJoiningMultiplayerSessionPacket()
|
||||
{
|
||||
// Arrange
|
||||
MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation(
|
||||
TestConstants.TEST_CORRELATION_ID,
|
||||
TestConstants.TEST_PLAYER_ID,
|
||||
TestConstants.TEST_RESERVATION_KEY);
|
||||
|
||||
IClient client = Substitute.For<IClient>();
|
||||
client.IsConnected.Returns(true);
|
||||
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Reservation.Returns(successfulReservation);
|
||||
connectionContext.Client.Returns(client);
|
||||
|
||||
SessionReserved connectionState = new SessionReserved();
|
||||
|
||||
// Act
|
||||
connectionState.JoinSession(connectionContext);
|
||||
|
||||
// Assert
|
||||
client.Received().Send(Arg.Any<PlayerJoiningMultiplayerSession>());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void JoinSessionShouldTransitionToSessionJoinedState()
|
||||
{
|
||||
// Arrange
|
||||
MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation(
|
||||
TestConstants.TEST_CORRELATION_ID,
|
||||
TestConstants.TEST_PLAYER_ID,
|
||||
TestConstants.TEST_RESERVATION_KEY);
|
||||
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
serverClient.IsConnected.Returns(true);
|
||||
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Reservation.Returns(successfulReservation);
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReserved connection = new SessionReserved();
|
||||
|
||||
// Act
|
||||
connection.JoinSession(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().UpdateConnectionState(Arg.Any<SessionJoined>());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldStopTheClient()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReserved connectionState = new SessionReserved();
|
||||
|
||||
// Act
|
||||
connectionState.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
serverClient.Received().Stop();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldResetTheConnectionContext()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReserved connectionState = new SessionReserved();
|
||||
|
||||
// Act
|
||||
connectionState.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().ClearSessionState();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisconnectShouldTransitionToDisconnectedState()
|
||||
{
|
||||
// Arrange
|
||||
IClient serverClient = Substitute.For<IClient>();
|
||||
IMultiplayerSessionConnectionContext connectionContext = Substitute.For<IMultiplayerSessionConnectionContext>();
|
||||
connectionContext.Client.Returns(serverClient);
|
||||
|
||||
SessionReserved connection = new SessionReserved();
|
||||
|
||||
// Act
|
||||
connection.Disconnect(connectionContext);
|
||||
|
||||
// Assert
|
||||
connectionContext.Received().UpdateConnectionState(Arg.Any<Disconnected>());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user