Exemple #1
0
        public async Task TestEventContractAsync()
        {
            var factory = new FakeConnectionFactory();
            var pusher  = new Pusher(factory, "abcd1234", new Options()
            {
                Authenticator = new FakeAuthenticator()
            });

            pusher.AddContract(EventContract.Create <FakeEvent>("fooHappened"));
            await pusher.ConnectAsync();

            var sentEvent = new IncomingEvent <FakeEvent>
            {
                Channel    = "foo",
                DataObject = new FakeEvent {
                    Id = 1, Text = "foo"
                },
                EventName = "fooHappened"
            };
            var channel = await pusher.SubscribeToChannelAsync("foo");

            var eventsReceived = 0;

            channel.GetEventSubscription <FakeEvent>().EventEmitted += (sender, receivedEvent) =>
            {
                Assert.AreEqual(sentEvent.DataObject.Id, receivedEvent.DataObject.Id);
                Assert.AreEqual(sentEvent.DataObject.Text, receivedEvent.DataObject.Text);
                Assert.AreEqual(sentEvent.EventName, receivedEvent.EventName);
                Assert.AreEqual(sentEvent.Channel, receivedEvent.Channel);
                eventsReceived++;
            };

            channel.EventEmitted += (sender, receivedEvent) =>
            {
                Assert.AreEqual(sentEvent.EventName, receivedEvent.EventName);
                Assert.AreEqual(sentEvent.Channel, receivedEvent.Channel);
                eventsReceived++;

                Assert.AreEqual(typeof(IncomingEvent <FakeEvent>), receivedEvent.GetType());
            };

            factory.LastCreated.SendData(JsonConvert.SerializeObject(sentEvent));
            Assert.AreEqual(2, eventsReceived);
        }
		public async Task TestEventContractAsync()
		{
			var factory = new FakeConnectionFactory();
			var pusher = new Pusher(factory, "abcd1234", new Options() { Authenticator = new FakeAuthenticator() });
			pusher.AddContract(EventContract.Create<FakeEvent>("fooHappened"));
			await pusher.ConnectAsync();

			var sentEvent = new IncomingEvent<FakeEvent>
				{
					Channel = "foo",
					DataObject = new FakeEvent {Id = 1, Text = "foo"},
					EventName = "fooHappened"
				};
			var channel = await pusher.SubscribeToChannelAsync("foo");
			var eventsReceived = 0;
			channel.GetEventSubscription<FakeEvent>().EventEmitted += (sender, receivedEvent) =>
				{
					Assert.AreEqual(sentEvent.DataObject.Id, receivedEvent.DataObject.Id);
					Assert.AreEqual(sentEvent.DataObject.Text, receivedEvent.DataObject.Text);
					Assert.AreEqual(sentEvent.EventName, receivedEvent.EventName);
					Assert.AreEqual(sentEvent.Channel, receivedEvent.Channel);
					eventsReceived++;
				};

			channel.EventEmitted += (sender, receivedEvent) =>
				{
					Assert.AreEqual(sentEvent.EventName, receivedEvent.EventName);
					Assert.AreEqual(sentEvent.Channel, receivedEvent.Channel);
					eventsReceived++;

					Assert.AreEqual(typeof(IncomingEvent<FakeEvent>), receivedEvent.GetType());
				};

			factory.LastCreated.SendData(JsonConvert.SerializeObject(sentEvent));
			Assert.AreEqual(2, eventsReceived);
		}