public async Task KillAllTest(int killer) { WampPlayground playground = SetupHost(); List <IWampChannel> channels = new List <IWampChannel>(); for (int i = 0; i < 30; i++) { IWampChannel channel = playground.CreateNewChannel("realm1"); channels.Add(channel); } Dictionary <int, (string reason, string message)> disconnectionDetails = await OpenChannels(channels).ConfigureAwait(false); Assert.That(disconnectionDetails.Count, Is.EqualTo(0)); IWampSessionManagementServiceProxy proxy = channels[killer].RealmProxy.Services .GetCalleeProxy <IWampSessionManagementServiceProxy>(); const string expectedReason = "wamp.myreason"; const string expectedMessage = "Bye bye bye"; await proxy.KillAllAsync(expectedReason, expectedMessage).ConfigureAwait(false); AssertClosedChannels(Enumerable.Range(0, 30).Except(new[] { killer }), disconnectionDetails, expectedMessage, expectedReason); }
public async Task KillByAuthIdTest(int killingChannel, int killedChannel, IEnumerable <int> expectedDeadChannels) { WampAuthenticationPlayground playground = SetupAuthenticationHost(); List <IWampChannel> channels = new List <IWampChannel>(); for (int i = 0; i < 30; i++) { IWampChannel channel = playground.CreateNewChannel("realm1", new WampCraClientAuthenticator("user" + i % 15, "secret")); channels.Add(channel); } Dictionary <int, (string reason, string message)> disconnectionDetails = await OpenChannels(channels); Assert.That(disconnectionDetails.Count, Is.EqualTo(0)); IWampSessionManagementServiceProxy proxy = channels[killingChannel].RealmProxy.Services.GetCalleeProxy <IWampSessionManagementServiceProxy>(); const string expectedReason = "wamp.myreason"; const string expectedMessage = "Bye bye bye"; await proxy.KillByAuthIdAsync("user" + killedChannel, expectedReason, expectedMessage).ConfigureAwait(false); AssertClosedChannels(expectedDeadChannels, disconnectionDetails, expectedMessage, expectedReason); }
public async Task KillBySessionIdTest(int killer, int killed, bool expectException = false) { WampPlayground playground = SetupHost(); List <IWampChannel> channels = new List <IWampChannel>(); IDictionary <int, long> channelToSessionId = new Dictionary <int, long>(); for (int i = 0; i < 30; i++) { IWampChannel channel = playground.CreateNewChannel("realm1"); int copyOfKey = i; channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) => { channelToSessionId[copyOfKey] = args.SessionId; }; channels.Add(channel); } Dictionary <int, (string reason, string message)> disconnectionDetails = await OpenChannels(channels).ConfigureAwait(false); Assert.That(disconnectionDetails.Count, Is.EqualTo(0)); IWampSessionManagementServiceProxy proxy = channels[killer].RealmProxy.Services .GetCalleeProxy <IWampSessionManagementServiceProxy>(); const string expectedReason = "wamp.myreason"; const string expectedMessage = "Bye bye bye"; WampException exception = null; try { await proxy.KillBySessionIdAsync(channelToSessionId[killed], expectedReason, expectedMessage).ConfigureAwait(false); } catch (WampException ex) { exception = ex; } if (expectException) { Assert.That(exception, Is.Not.Null); Assert.That(exception.ErrorUri, Is.EqualTo("wamp.error.no_such_session")); } AssertClosedChannels(new [] { killed }.Except(new[] { killer }), disconnectionDetails, expectedMessage, expectedReason); }