MessagingTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Networking.Tests MessagingTests

Namespace: DeltaEngine.Networking.Tests
Assembly: DeltaEngine.Networking.Tests (in DeltaEngine.Networking.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class MessagingTests : TestWithMocksOrVisually

The MessagingTests type exposes the following members.

Constructors

  NameDescription
Public methodMessagingTests
Initializes a new instance of the MessagingTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodClientReportsParticipantsNotCalculated
Public methodDisconnectedClientNoLongerReceivesMessagesFromServer
Public methodDisconnectedServerNoLongerReceivesMessagesFromClients
Public methodDisposeConnectionsSockets
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodMessagesAreOnlyReceivedOnce
Public methodNoMessagesInitially
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSendMessagesClientToServer
Public methodSendMessagesServerToClient
Public methodServerReportsOneParticipant
Public methodSetUp
Public methodUniqueIDsAssigned
Public methodWhenTwoServersExistMessagesAreSentToTheCorrectOne
Public methodWithTwoClientsWhenOneClientMessagesTheServerItIsEchoedToTheOtherClient
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void UniqueIDsAssigned()
{
    Assert.AreEqual(0, serverSession.UniqueID);
    Assert.AreEqual(1, clientSession.UniqueID);
}
[Test, CloseAfterFirstFrame]
public void ServerReportsOneParticipant()
{
    Assert.AreEqual(1, serverSession.NumberOfParticipants);
}
[Test, CloseAfterFirstFrame, Timeout(5000)]
public void ClientReportsParticipantsNotCalculated()
{
    Assert.AreEqual(ClientMessagingSession.NumberOfParticipantsNotCalculated,
        clientSession.NumberOfParticipants);
}
[Test, CloseAfterFirstFrame]
public void NoMessagesInitially()
{
    List<MessagingSession.Message> messages = serverSession.GetMessages();
    Assert.AreEqual(0, messages.Count);
    Assert.AreEqual(0, clientSession.GetMessages().Count);
}
[Test, CloseAfterFirstFrame]
public void SendMessagesServerToClient()
{
    serverSession.SendMessage("hello");
    serverSession.SendMessage(9);
    Pause();
    List<MessagingSession.Message> messages = clientSession.GetMessages();
    Assert.AreEqual(2, messages.Count);
    VerifyMessageContents(messages[0], 0, "hello");
    VerifyMessageContents(messages[1], 0, 9);
}
[Test, CloseAfterFirstFrame]
public void MessagesAreOnlyReceivedOnce()
{
    serverSession.SendMessage("hello");
    clientSession.SendMessage("hello");
    Pause();
    Assert.AreEqual(1, serverSession.GetMessages().Count);
    Assert.AreEqual(0, serverSession.GetMessages().Count);
    Assert.AreEqual(1, clientSession.GetMessages().Count);
    Assert.AreEqual(0, clientSession.GetMessages().Count);
}
[Test, CloseAfterFirstFrame]
public void SendMessagesClientToServer()
{
    clientSession.SendMessage("hi");
    clientSession.SendMessage(1.2f);
    Pause();
    List<MessagingSession.Message> messages = serverSession.GetMessages();
    Assert.AreEqual(2, messages.Count);
    VerifyMessageContents(messages[0], 1, "hi");
    VerifyMessageContents(messages[1], 1, 1.2f);
}
[Test, CloseAfterFirstFrame]
public void WithTwoClientsWhenOneClientMessagesTheServerItIsEchoedToTheOtherClient()
{
    if (!StackTraceExtensions.IsStartedFromNCrunch())
        return; //ncrunch: no coverage 
    var clientSession2 = Messaging.JoinSession(Address, Port);
    clientSession2.SendMessage("welcome");
    List<MessagingSession.Message> messages = clientSession.GetMessages();
    Assert.AreEqual(1, serverSession.GetMessages().Count);
    Assert.AreEqual(1, messages.Count);
    VerifyMessageContents(messages[0], 2, "welcome");
    Assert.AreEqual(2, serverSession.NumberOfParticipants);
}
[Test, CloseAfterFirstFrame]
public void DisconnectedClientNoLongerReceivesMessagesFromServer()
{
    clientSession.Disconnect();
    Pause();
    serverSession.SendMessage("hello?");
    Pause();
    Assert.AreEqual(0, clientSession.GetMessages().Count);
}
[Test, CloseAfterFirstFrame]
public void DisconnectedServerNoLongerReceivesMessagesFromClients()
{
    serverSession.Disconnect();
    Pause();
    clientSession.SendMessage("are you there?");
    Pause();
    Assert.AreEqual(0, serverSession.GetMessages().Count);
}
[Test, CloseAfterFirstFrame]
public void WhenTwoServersExistMessagesAreSentToTheCorrectOne()
{
    if (!StackTraceExtensions.IsStartedFromNCrunch())
        return; //ncrunch: no coverage
    MessagingSession serverSession2 = Messaging.StartSession(Port + 1);
    MessagingSession clientSession2 = Messaging.JoinSession(Address, Port + 1);
    clientSession.SendMessage("first");
    clientSession2.SendMessage("second");
    Assert.AreEqual("first", serverSession.GetMessages()[0].Data);
    Assert.AreEqual("second", serverSession2.GetMessages()[0].Data);
}
See Also