Inheritance Hierarchy
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
The MessagingTests type exposes the following members.
Constructors
Name | Description | |
---|---|---|
MessagingTests | Initializes a new instance of the MessagingTests class |
Methods
Properties
Name | Description | |
---|---|---|
IsMockResolver | (Inherited from TestWithMocksOrVisually.) |
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