Пример #1
0
        private static EventData EndReceiveEvent(Client client, EventCode eventCode)
        {
            EventData data;

            Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTimeMultiOp, out data), "Event not received");
            Assert.AreEqual(eventCode, (EventCode)data.Code);
            return(data);
        }
Пример #2
0
        private static void ExitWorld(Client client)
        {
            EventData data;

            Operations.ExitWorld(client);
            client.BeginReceiveEvent(EventCode.WorldExited, d => true, 0);
            Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
            Assert.AreEqual(data.Code, (byte)EventCode.WorldExited);
        }
Пример #3
0
        public void SubscribeUnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                var myItemId = "MyItem";

                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f), new Vector(1f, 1f), new Vector(2f, 2f), null);

                SpawnItem(client);

                // subscribing...
                Operations.SubscribeItem(client, myItemId, null);
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] == myItemId, 0);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

                // check if subscription works
                Operations.Move(client, myItemId, new Vector(3f, 3.3f));

                Func <EventData, bool> checkAction =
                    d => (string)d[(byte)ParameterCode.ItemId] == myItemId;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemMoved);
                Assert.IsTrue(checkAction(data), "check action failed");

                // unsubscribing...
                Operations.UnsubscribeItem(client, myItemId);
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d[(byte)ParameterCode.ItemId] == myItemId, 0);
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if unsubscription works
                Operations.Move(client, null, new Vector(1f, 2f));

                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received");
            }
        }
Пример #4
0
        public void RaiseGenericEvent()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                ////Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.WorldRegion);
                Func <EventData, bool> checkAction =
                    d =>
                    (string)d[(byte)ParameterCode.ItemId] == client.Username && (byte)d[(byte)ParameterCode.ItemType] == (byte)ItemType.Avatar &&
                    (byte)d[(byte)ParameterCode.CustomEventCode] == byte.MaxValue;

                ////client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                EventData data;

                ////Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar world region");
                ////Assert.AreEqual((byte)data.Code, (byte)EventCode.ItemGeneric);
                ////Assert.IsTrue(checkAction(data), "check action failed");
                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemOwner);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar owner");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemGeneric);
                Assert.IsTrue(checkAction(data), "check action failed");

                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received - avator should not be subscribed");

                // subscribe avatar
                Operations.SubscribeItem(client, client.Username, (byte)ItemType.Avatar, null);
                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar subscriber");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemGeneric);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Пример #5
0
        public void SetProperties()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f), new Vector(1f, 1f), new Vector(2f, 2f), null);

                Operations.SetProperties(client, null, new Hashtable {
                    { "Key", "Value" }
                }, null);

                client.BeginReceiveResponse(0);
                EventData data;
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Response received");
            }
        }
Пример #6
0
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f), new Vector(1f, 1f), new Vector(2f, 2f), null);
                SpawnItem(client);
                Operations.DestroyItem(client, "MyItem");

                Func <EventData, bool> checkAction =
                    d => (string)d.Parameters[(byte)ParameterCode.ItemId] == "MyItem";
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction, 10);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemDestroyed);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Пример #7
0
 /// <summary>
 ///   The exit world.
 /// </summary>
 /// <param name = "client">
 ///   The client.
 /// </param>
 private static void ExitWorld(Client client)
 {
     EventData data;
     Operations.ExitWorld(client);
     client.BeginReceiveEvent(EventCode.WorldExited, d => true, 0);
     Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
     Assert.AreEqual(data.Code, (byte)EventCode.WorldExited);
 }
Пример #8
0
        public void UnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                Operations.SubscribeItem(client, client.Username, (byte)ItemType.Avatar, null);
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] == client.Username, 0);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

                Operations.UnsubscribeItem(client, client.Username, (byte)ItemType.Avatar);
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d[(byte)ParameterCode.ItemId] == client.Username, 0);
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if subscription worked
                Operations.Move(client, null, null, new[] { 1f, 2f });

                Func<EventData, bool> checkAction = d => true;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received");
            }
        }
Пример #9
0
        public void SetProperties()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                Operations.SetProperties(client, null, null, new Hashtable { { "Key", "Value" } }, null);

                client.BeginReceiveResponse(0);
                EventData data;
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Response received");
            }
        }
Пример #10
0
        public void RaiseGenericEvent()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                ////Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.WorldRegion);
                Func<EventData, bool> checkAction =
                    d =>
                    (string)d[(byte)ParameterCode.ItemId] == client.Username && (byte)d[(byte)ParameterCode.ItemType] == (byte)ItemType.Avatar &&
                    (byte)d[(byte)ParameterCode.CustomEventCode] == byte.MaxValue;

                ////client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                EventData data;

                ////Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar world region");
                ////Assert.AreEqual((byte)data.Code, (byte)EventCode.ItemGeneric);
                ////Assert.IsTrue(checkAction(data), "check action failed");
                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemOwner);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar owner");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemGeneric);
                Assert.IsTrue(checkAction(data), "check action failed");

                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received - avator should not be subscribed");

                // subscribe avatar
                Operations.SubscribeItem(client, client.Username, (byte)ItemType.Avatar, null);
                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar subscriber");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemGeneric);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Пример #11
0
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);
                SpawnItem(client);
                Operations.DestroyItem(client, "MyItem", byte.MaxValue);

                Func<EventData, bool> checkAction =
                    d => (string)d.Parameters[(byte)ParameterCode.ItemId] == "MyItem" && (byte)d[(byte)ParameterCode.ItemType] == byte.MaxValue;
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction, 10);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemDestroyed);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Пример #12
0
 /// <summary>
 ///   The end receive event.
 /// </summary>
 /// <param name = "client">
 ///   The client.
 /// </param>
 /// <param name = "eventCode">
 ///   The event EventCode.
 /// </param>
 /// <returns>
 ///   the received event
 /// </returns>
 private static EventData EndReceiveEvent(Client client, EventCode eventCode)
 {
     EventData data;
     Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
     Assert.AreEqual(eventCode, (EventCode)data.Code);
     return data;
 }
Пример #13
0
        public void SubscribeUnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                var myItemId = "MyItem";

                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                SpawnItem(client);

                // subscribing...
                Operations.SubscribeItem(client, myItemId, null);
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] == myItemId, 0);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

                // check if subscription works
                Operations.Move(client, myItemId, new Vector(3f, 3.3f, 0f));

                Func<EventData, bool> checkAction =
                    d => (string)d[(byte)ParameterCode.ItemId] == myItemId;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemMoved);
                Assert.IsTrue(checkAction(data), "check action failed");

                // unsubscribing...
                Operations.UnsubscribeItem(client, myItemId);
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d[(byte)ParameterCode.ItemId] == myItemId, 0);
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if unsubscription works
                Operations.Move(client, null, new Vector(1f, 2f, 0f));

                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received");
            }
        }