コード例 #1
0
        public void ErrorForTargetRpcWhenNotGivenConnectionToClient()
        {
            TargetRpcBehaviour hostBehaviour = CreateHostObject <TargetRpcBehaviour>(false);

            const int someInt = 20;

            hostBehaviour.onSendInt += incomingInt =>
            {
                Assert.Fail("Event should not be invoked with error");
            };
            LogAssert.Expect(LogType.Error, $"TargetRPC {nameof(TargetRpcBehaviour.SendIntWithTarget)} requires a NetworkConnectionToClient but was given {typeof(FakeConnection).Name}");
            hostBehaviour.SendIntWithTarget(new FakeConnection(), someInt);
        }
コード例 #2
0
        public void ErrorForTargetRpcWithNullArgment()
        {
            TargetRpcBehaviour hostBehaviour = CreateHostObject <TargetRpcBehaviour>(false);

            const int someInt = 20;

            hostBehaviour.onSendInt += incomingInt =>
            {
                Assert.Fail("Event should not be invoked with error");
            };
            LogAssert.Expect(LogType.Error, $"TargetRPC {nameof(TargetRpcBehaviour.SendIntWithTarget)} was given a null connection, make sure the object has an owner or you pass in the target connection");
            hostBehaviour.SendIntWithTarget(null, someInt);
        }
コード例 #3
0
        public void ErrorForTargetRpcWhenServerNotActive()
        {
            TargetRpcBehaviour hostBehaviour = CreateHostObject <TargetRpcBehaviour>(true);

            const int someInt = 20;

            hostBehaviour.onSendInt += incomingInt =>
            {
                Assert.Fail("Event should not be invoked with error");
            };
            NetworkServer.active = false;
            LogAssert.Expect(LogType.Error, $"TargetRPC {nameof(TargetRpcBehaviour.SendInt)} called when server not active");
            hostBehaviour.SendInt(someInt);
        }
コード例 #4
0
        public void RpcIsCalled()
        {
            TargetRpcBehaviour hostBehaviour = CreateHostObject <TargetRpcBehaviour>(true);

            const int someInt = 20;

            int callCount = 0;

            hostBehaviour.onSendInt += incomingInt =>
            {
                callCount++;
                Assert.That(incomingInt, Is.EqualTo(someInt));
            };
            hostBehaviour.SendInt(someInt);
            ProcessMessages();
            Assert.That(callCount, Is.EqualTo(1));
        }
コード例 #5
0
        public void TargetRpcIsCalledOnTarget()
        {
            TargetRpcBehaviour hostBehaviour = CreateHostObject <TargetRpcBehaviour>(false);

            const int someInt = 20;

            int callCount = 0;

            hostBehaviour.onSendInt += incomingInt =>
            {
                callCount++;
                Assert.That(incomingInt, Is.EqualTo(someInt));
            };
            hostBehaviour.SendIntWithTarget(NetworkServer.localConnection, someInt);
            ProcessMessages();
            Assert.That(callCount, Is.EqualTo(1));
        }
コード例 #6
0
        public void ErrorForTargetRpcWhenObjetNotSpawned()
        {
            GameObject gameObject = new GameObject();

            spawned.Add(gameObject);
            gameObject.AddComponent <NetworkIdentity>();
            TargetRpcBehaviour hostBehaviour = gameObject.AddComponent <TargetRpcBehaviour>();

            const int someInt = 20;

            hostBehaviour.onSendInt += incomingInt =>
            {
                Assert.Fail("Event should not be invoked with error");
            };
            LogAssert.Expect(LogType.Warning, $"TargetRpc {nameof(TargetRpcBehaviour.SendInt)} called on {hostBehaviour.name} but that object has not been spawned or has been unspawned");
            hostBehaviour.SendInt(someInt);
        }