Skip to content

Commit

Permalink
Test connect and send
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Dec 24, 2019
1 parent e7abf4e commit d83efbb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Assets/Mirror/Tests/MultiplexTest.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using UnityEngine;
Expand Down Expand Up @@ -30,6 +31,7 @@ public void SetupMultipex()
transport.Awake();
}

#region Client tests
// A Test behaves as an ordinary method
[Test]
public void TestAvailable()
Expand Down Expand Up @@ -148,5 +150,38 @@ public void TestClient2Connected()
callback.Received().Invoke();
}

#endregion

#region Server tests

[Test]
public void TestServerConnected()
{
byte[] data = { 1, 2, 3 };
ArraySegment<byte> segment = new ArraySegment<byte>(data);


// on connect, send a message back
void SendMessage(int connectionId)
{
List<int> connectionIds = new List<int>(new[] { connectionId });
transport.ServerSend(connectionIds, 5, segment);
}

transport.OnServerConnected.AddListener(SendMessage);

transport1.OnServerConnected.Invoke(1);

List<int> expectedIds = new List<int>(new[] { 1 });

transport1.Received().ServerSend(
Arg.Is<List<int>>(x => x.SequenceEqual(expectedIds)),
5,
segment);
}


#endregion

}
}

0 comments on commit d83efbb

Please sign in to comment.