92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
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>());
|
|
}
|
|
}
|
|
}
|