Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Fix tests after ConnectAsync() waits for connection established.
Browse files Browse the repository at this point in the history
  • Loading branch information
vegardlarsen committed Jan 18, 2014
1 parent e33d014 commit a242071
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Pusher.Tests.WindowsStore/PusherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Newtonsoft.Json;
using Pusher.Events;
using Pusher.Exceptions;

namespace Pusher.Tests.WindowsStore
{
Expand All @@ -28,11 +27,12 @@ public async Task Open()
{
OnOpen(this, new EventArgs());
}
SendData(JsonConvert.SerializeObject(new IncomingEvent
Task.Delay(1).ContinueWith(task =>
SendData(JsonConvert.SerializeObject(new IncomingEvent
{
EventName = Pusher.EventConnectionEstablished,
Data = "{\"socket_id\":\"a\"}"
}));
})));
}

public async Task SendMessage(string data)
Expand Down Expand Up @@ -128,21 +128,18 @@ public async Task TestRaiseAllEventsOnPusherAsync()
var factory = new FakeConnectionFactory();
var pusher = new Pusher(factory, "abcd1234", new Options { RaiseAllEventsOnPusher = false });

var eventsOnPusher = 0;

pusher.EventEmitted += (sender, evt) => eventsOnPusher++;
await pusher.ConnectAsync();

Assert.AreEqual(1, eventsOnPusher);

var eventsOnPusher = 0;
pusher.EventEmitted += (sender, evt) => eventsOnPusher++;
var eventsOnChannel = 0;
var channel = await pusher.SubscribeToChannelAsync("foo");
channel.EventEmitted += (sender, evt) => eventsOnChannel++;

// the subscribe successful event is raised on channel, but it is raised before we can hook up the event
Assert.AreEqual(0, eventsOnChannel);
// RaiseAllEventsOnPusher prevents the subscribe successful event from being raised on pusher
Assert.AreEqual(1, eventsOnPusher);
// RaiseAllEventsOnPusher = false prevents the subscribe successful event from being raised on pusher
Assert.AreEqual(0, eventsOnPusher);
}

[TestMethod]
Expand Down

0 comments on commit a242071

Please sign in to comment.