Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Test execution optimisation #236

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
test:fix:grantToken
Mohit Tejani authored and Mohit Tejani committed Feb 4, 2025
commit 0c6b3afdd052e8434c9123936b85bea98e0a2f80
39 changes: 19 additions & 20 deletions src/UnitTests/PubnubApi.Tests/WhenAMessageIsPublished.cs
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@ public static async Task Init()
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(receivedGrantMessage, "WhenAMessageIsPublished Grant access failed.");
}

[TearDown]
@@ -125,7 +124,7 @@ public static void ThenNullMessageShouldReturnException()

server.RunOnHttps(true);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "";

@@ -176,7 +175,7 @@ public static void ThenUnencryptPublishGETShouldReturnSuccessCodeAndInfo()
config.AuthKey = authToken;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715278266153304\"]";

@@ -282,7 +281,7 @@ public static async Task ThenWithAsyncUnencryptPublishGETShouldReturnSuccessCode
config.AuthKey = authToken;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715278266153304\"]";

@@ -383,7 +382,7 @@ public static void ThenUnencryptFireGETShouldReturnSuccessCodeAndInfo()
config.AuthKey = authToken;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715278266153304\"]";

@@ -509,7 +508,7 @@ public static void ThenUnencryptPublishPOSTShouldReturnSuccessCodeAndInfo()
config.AuthKey = authKey;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715278266153304\"]";

@@ -610,7 +609,7 @@ public static void ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo()
config.AuthKey = authKey;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715286132003364\"]";

@@ -713,7 +712,7 @@ public static void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo()
config.AuthKey = authKey;
}
server.RunOnHttps(false);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715322883933786\"]";

@@ -815,7 +814,7 @@ public static void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfoWithSSL
config.AuthKey = authKey;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715322883933786\"]";

@@ -917,7 +916,7 @@ public static void ThenEncryptPublishShouldReturnSuccessCodeAndInfo()
config.AuthKey = authKey;
}
server.RunOnHttps(false);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14715426119520817\"]";

@@ -1030,7 +1029,7 @@ public static void ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1, \"Sent\", \"14715438956854374\"]";

@@ -1136,7 +1135,7 @@ public static void ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo
// }
// server.RunOnHttps(false);
//
// pubnub = createPubNubInstance(config);
// pubnub = createPubNubInstance(config, authToken);
//
// string expected = "[1, \"Sent\", \"14715459088445832\"]";
//
@@ -1224,7 +1223,7 @@ public static void ThenPubnubShouldFailOnWithoutSettingUuid()
SubscribeKey = PubnubCommon.SubscribeKey,
};

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
});

pubnub = null;
@@ -1239,7 +1238,7 @@ public static void ThenPublishKeyShouldNotBeEmpty()
SubscribeKey = PubnubCommon.SubscribeKey,
};

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string channel = "hello_my_channel";
string message = "Pubnub API Usage Example";
@@ -1278,7 +1277,7 @@ public static void ThenOptionalSecretKeyShouldBeProvidedInConfig()
}
server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string channel = "hello_my_channel";
string message = "Pubnub API Usage Example";
@@ -1342,7 +1341,7 @@ public static void IfSSLNotProvidedThenDefaultShouldBeTrue()
config.AuthKey = authKey;
}
server.RunOnHttps(true);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14722484585147754\"]";

@@ -1564,7 +1563,7 @@ private static bool SampleXSecretKeyWithoutAuthThenGetMessageWithSpecialCharsRet

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14722484585147754\"]";

@@ -1638,7 +1637,7 @@ public static void IfSecretKeyCipherKeyWithoutAuthThenGetMessageWithSpecialChars

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14722484585147754\"]";

@@ -1717,7 +1716,7 @@ public static void IfSecretKeyWithoutAuthThenPostMessageWithSpecialCharsReturnSu

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14722484585147754\"]";

@@ -1790,7 +1789,7 @@ public static void IfSecretKeyCipherKeyWithoutAuthThenPostMessageWithSpecialChar

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string expected = "[1,\"Sent\",\"14722484585147754\"]";

Original file line number Diff line number Diff line change
@@ -571,7 +571,7 @@ public static void DetailHistoryWithNullKeysReturnsError()
};
server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string channel = "hello_my_channel";
manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;
34 changes: 4 additions & 30 deletions src/UnitTests/PubnubApi.Tests/WhenMessageAction.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using System.Threading;
using PubnubApi;
using MockServer;
using System.Diagnostics;
using System.Threading.Tasks;

namespace PubNubMessaging.Tests
@@ -65,38 +63,14 @@ public static async Task Init()
.WithParameter("signature", "JMQKzXgfqNo-HaHuabC0gq0X6IkVMHa9AWBCg6BGN1Q=")
.WithResponse(expected)
.WithStatusCode(System.Net.HttpStatusCode.OK));

var fullAccess = new PNTokenAuthValues()
if (string.IsNullOrEmpty(PubnubCommon.GrantToken))
{
Read = true,
Write = true,
Create = true,
Get = true,
Delete = true,
Join = true,
Update = true,
Manage = true
};
var grantResult = await pubnub.GrantToken().TTL(20).AuthorizedUuid(config.UserId).Resources(
new PNTokenResources()
{
Channels = new Dictionary<string, PNTokenAuthValues>()
{
{
grantChannel, fullAccess
}
}
}).ExecuteAsync();

await Task.Delay(4000);

authToken = grantResult.Result?.Token;

await GenerateTestGrantToken(pubnub);
}
authToken = PubnubCommon.GrantToken;
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(grantResult.Result != null && grantResult.Status.Error == false,
"WhenDetailedHistoryIsRequested Grant access failed.");
}

[TearDown]
38 changes: 4 additions & 34 deletions src/UnitTests/PubnubApi.Tests/WhenMessageCountIsRequested.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using NUnit.Framework;
using System.Threading;
using PubnubApi;
using System.Collections.Generic;
using MockServer;
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace PubNubMessaging.Tests
@@ -68,41 +65,14 @@ public static async Task Init()
.WithParameter("signature", "MhmxFFbUb_HlzWqTuvJAMRjAb3fgP9dbykaiPsSZuUc=")
.WithResponse(expected)
.WithStatusCode(System.Net.HttpStatusCode.OK));

var fullAccess = new PNTokenAuthValues()
if (string.IsNullOrEmpty(PubnubCommon.GrantToken))
{
Read = true,
Write = true,
Create = true,
Get = true,
Delete = true,
Join = true,
Update = true,
Manage = true
};
var grantResult = await pubnub.GrantToken().TTL(20).AuthorizedUuid(config.UserId).Resources(
new PNTokenResources()
{
Channels = new Dictionary<string, PNTokenAuthValues>()
{
{
channelName1, fullAccess
},
{
channelName2, fullAccess
}
}
}).ExecuteAsync();

await Task.Delay(4000);

authToken = grantResult.Result?.Token;

await GenerateTestGrantToken(pubnub);
}
authToken = PubnubCommon.GrantToken;
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(grantResult.Result != null && grantResult.Status.Error == false,
"WhenMessageCountIsRequested Grant access failed.");
}

[TearDown]
44 changes: 9 additions & 35 deletions src/UnitTests/PubnubApi.Tests/WhenMessageDeletedFromChannel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using NUnit.Framework;
using NUnit.Framework;
using System.Threading;
using PubnubApi;
using System.Collections.Generic;
using MockServer;
using System.Diagnostics;
using System.Threading.Tasks;
@@ -20,7 +18,7 @@ public class WhenMessageDeletedFromChannel : TestHarness

private static int manualResetEventWaitTimeout = 310 * 1000;
private static string channel = "hello_my_channel";
private static string token;
private static string authToken;
private static string currentTestCase = "";

private static Pubnub pubnub;
@@ -77,38 +75,14 @@ public static async Task Init()
.WithParameter("signature", "JMQKzXgfqNo-HaHuabC0gq0X6IkVMHa9AWBCg6BGN1Q=")
.WithResponse(expected)
.WithStatusCode(System.Net.HttpStatusCode.OK));

var grantResult = await pubnub.GrantToken().TTL(20).AuthorizedUuid(config.UserId).Resources(
new PNTokenResources()
{
Channels = new Dictionary<string, PNTokenAuthValues>()
{
{
channel, new PNTokenAuthValues()
{
Read = true,
Write = true,
Create = true,
Get = true,
Delete = true,
Join = true,
Update = true,
Manage = true
}
}
}
}).ExecuteAsync();

await Task.Delay(3000);

token = grantResult.Result?.Token;

if (string.IsNullOrEmpty(PubnubCommon.GrantToken))
{
await GenerateTestGrantToken(pubnub);
}
authToken = PubnubCommon.GrantToken;
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;

Assert.IsTrue(grantResult.Status.Error == false && grantResult.Result != null,
"WhenUnsubscribedToAChannelGroup Grant access failed.");
}

[TearDown]
@@ -142,7 +116,7 @@ public static void ThenDeleteMessageShouldReturnSuccessMessage()
config.SecretKey = PubnubCommon.SecretKey;
}
pubnub = createPubNubInstance(config);
pubnub.SetAuthToken(token);
pubnub.SetAuthToken(authToken);

string expected = "{\"status\": 200, \"error\": false, \"error_message\": \"\"}";

@@ -201,7 +175,7 @@ public static async Task ThenWithAsyncDeleteMessageShouldReturnSuccessMessage()
config.SecretKey = PubnubCommon.SecretKey;
}
pubnub = createPubNubInstance(config);
pubnub.SetAuthToken(token);
pubnub.SetAuthToken(authToken);

string expected = "{\"status\": 200, \"error\": false, \"error_message\": \"\"}";

70 changes: 22 additions & 48 deletions src/UnitTests/PubnubApi.Tests/WhenPushIsRequested.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using NUnit.Framework;
using System.ComponentModel;
using System.Threading;
using System.Collections;
using PubnubApi;
using MockServer;
using System.Diagnostics;
using System.Threading.Tasks;

namespace PubNubMessaging.Tests
@@ -28,14 +22,15 @@ public class WhenPushIsRequested : TestHarness
private static long publishTimetoken = 0;
private static string currentTestCase = "";
private static int manualResetEventWaitTimeout = 310 * 1000;
private static string authToken;

private static Pubnub pubnub;

private static Server server;


[SetUp]
public static void Init()
public static async Task Init()
{
UnitTestLog unitLog = new Tests.UnitTestLog();
unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
@@ -83,35 +78,14 @@ public static void Init()
.WithParameter("signature", "JMQKzXgfqNo-HaHuabC0gq0X6IkVMHa9AWBCg6BGN1Q=")
.WithResponse(expected)
.WithStatusCode(System.Net.HttpStatusCode.OK));

pubnub.Grant().Channels(new [] { channel }).AuthKeys(new [] { authKey }).Read(true).Write(true).Manage(true).TTL(20)
.Execute(new PNAccessManagerGrantResultExt((result, status)=>
{
if (result != null)
{
Debug.WriteLine("PNAccessManagerGrantResult={0}", pubnub.JsonPluggableLibrary.SerializeToJsonString(result));
if (result.Channels != null && result.Channels.Count > 0)
{
var read = result.Channels[channel][authKey].ReadEnabled;
var write = result.Channels[channel][authKey].WriteEnabled;
if (read && write)
{
receivedGrantMessage = true;
}
}
}
grantManualEvent.Set();
}));

Thread.Sleep(1000);

grantManualEvent.WaitOne();

if (string.IsNullOrEmpty(PubnubCommon.GrantToken))
{
await GenerateTestGrantToken(pubnub);
}
authToken = PubnubCommon.GrantToken;
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;

Assert.IsTrue(receivedGrantMessage, "WhenPushIsRequested Grant access failed.");
}

[TearDown]
@@ -151,7 +125,7 @@ public static void ThenPublishMpnsToastShouldReturnSuccess()
}

server.RunOnHttps(false);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

MpnsToastNotification toast = new MpnsToastNotification();
toast.text1 = "hardcode message";
@@ -215,7 +189,7 @@ public static void ThenPublishMpnsFlipTileShouldReturnSuccess()
}

server.RunOnHttps(false);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

MpnsFlipTileNotification tile = new MpnsFlipTileNotification();
tile.title = "front title";
@@ -284,7 +258,7 @@ public static void ThenPublishMpnsCycleTileShouldReturnSuccess()
}

server.RunOnHttps(false);
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string channel = "hello_my_channel";

@@ -354,7 +328,7 @@ public static void ThenPublishMpnsIconicTileShouldReturnSuccess()

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

string channel = "hello_my_channel";

@@ -429,7 +403,7 @@ public static void ThenAuditPushChannelProvisionsShouldReturnSuccess()

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -487,7 +461,7 @@ public static async Task ThenWithAsyncAuditPushChannelProvisionsShouldReturnSucc

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -542,7 +516,7 @@ public static void ThenAPNS2AddDeviceToPushChannelShouldReturnSuccess()

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -606,7 +580,7 @@ public static async Task ThenWithAsyncAPNS2AddDeviceToPushChannelShouldReturnSuc

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -672,7 +646,7 @@ public static void ThenAPNS2RemovePushChannelFromDeviceShouldReturnSuccess()

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -736,7 +710,7 @@ public static async Task ThenWithAsyncAPNS2RemovePushChannelFromDeviceShouldRetu

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -802,7 +776,7 @@ public static void ThenAPNS2ListPushChannelsFromDeviceShouldReturnSuccess()

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -865,7 +839,7 @@ public static async Task ThenWithAsyncAPNS2ListPushChannelsFromDeviceShouldRetur

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

#if NET40
PNResult<PNPushListProvisionsResult> resp = Task.Factory.StartNew(async () => await pubnub.AuditPushChannelProvisions()
@@ -925,7 +899,7 @@ public static void ThenAPNS2RemoveDeviceFromPushShouldReturnSuccess()

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

@@ -988,7 +962,7 @@ public static async Task ThenWithAsyncAPNS2RemoveDeviceFromPushShouldReturnSucce

server.RunOnHttps(false);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

manualResetEventWaitTimeout = (PubnubCommon.EnableStubTest) ? 1000 : 310 * 1000;

71 changes: 14 additions & 57 deletions src/UnitTests/PubnubApi.Tests/WhenSubscribedToAChannel.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using MockServer;
using System.Diagnostics;
using System.Threading.Tasks;
using PubnubApi.Security.Crypto;
using PubnubApi.Security.Crypto.Cryptors;

@@ -16,6 +17,7 @@ public class WhenSubscribedToAChannel : TestHarness
static int manualResetEventWaitTimeout = 310 * 1000;
private static string authKey = "myauth";
private static string channel = "hello_my_channel";
private static string authToken;

private static Pubnub pubnub;
private static Server server;
@@ -29,7 +31,7 @@ void IPubnubLog.WriteToLog(string logText)
}

[SetUp]
public static void Init()
public static async Task Init()
{
UnitTestLog unitLog = new Tests.UnitTestLog();
unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
@@ -78,59 +80,14 @@ public static void Init()
.WithResponse(expected)
.WithStatusCode(System.Net.HttpStatusCode.OK));

ManualResetEvent grantManualEvent = new ManualResetEvent(false);
pubnub.Grant().Channels(channelsGrant).AuthKeys(new [] { authKey }).Read(true).Write(true).Manage(true).TTL(20)
.Execute(new PNAccessManagerGrantResultExt(
(r, s) =>
{
try
{
if (r != null)
{
Debug.WriteLine("PNAccessManagerGrantResult={0}", pubnub.JsonPluggableLibrary.SerializeToJsonString(r));
if (r.Channels != null && r.Channels.Count > 0)
{
foreach (KeyValuePair<string, Dictionary<string, PNAccessManagerKeyData>> channelKP in r.Channels)
{
string receivedChannel = channelKP.Key;
if (Array.IndexOf(channelsGrant, receivedChannel) > -1)
{
var read = r.Channels[receivedChannel][authKey].ReadEnabled;
var write = r.Channels[receivedChannel][authKey].WriteEnabled;
if (read && write)
{
receivedGrantMessage = true;
}
else
{
receivedGrantMessage = false;
}
}
else
{
receivedGrantMessage = false;
break;
}
}
}
}
}
catch { /* ignore */ }
finally
{
grantManualEvent.Set();
}
}));

Thread.Sleep(1000);

grantManualEvent.WaitOne();

if (string.IsNullOrEmpty(PubnubCommon.GrantToken))
{
await GenerateTestGrantToken(pubnub);
}
authToken = PubnubCommon.GrantToken;
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;

Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannel Grant access failed.");
}

[TearDown]
@@ -162,7 +119,7 @@ public static void ThenMissingSubscribeKeyShouldReturnException()
};
server.RunOnHttps(true);

pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);

Assert.Throws<MissingMemberException>(() =>
{
@@ -250,7 +207,7 @@ private static void CommonComplexMessageSubscribeShouldReturnReceivedMessageBase
subscribeManualEvent.Set();
}
});
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

string channel = "hello_my_channel";
@@ -458,7 +415,7 @@ public static void ThenSubscribeShouldReturnConnectStatus()
}
subscribeManualEvent.Set();
});
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

string channel = "hello_my_channel";
@@ -538,7 +495,7 @@ public static void ThenMultiSubscribeShouldReturnConnectStatus()
}
subscribeManualEvent.Set();
});
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

manualResetEventWaitTimeout = 310 * 1000;
@@ -654,7 +611,7 @@ public static void ThenMultiSubscribeShouldReturnConnectStatusSSL()
}
subscribeManualEvent.Set();
});
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

manualResetEventWaitTimeout = 310 * 1000;
@@ -791,7 +748,7 @@ public static void ThenSubscriberShouldBeAbleToReceiveManyMessages()
subscribeManualEvent.Set();
}
});
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

manualResetEventWaitTimeout = 310 * 1000;
21 changes: 10 additions & 11 deletions src/UnitTests/PubnubApi.Tests/WhenSubscribedToAChannel2.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using MockServer;
using System.Diagnostics;
using System.Threading.Tasks;
using PubnubApi.Security.Crypto;
using PubnubApi.Security.Crypto.Cryptors;

@@ -27,6 +28,7 @@ public class WhenSubscribedToAChannel2 : TestHarness
private static string[] channelsGrant = { "hello_my_channel", "hello_my_channel1", "hello_my_channel2" };
private static string authKey = "myauth";
private static string currentTestCase = "";
private static string authToken;

private static Pubnub pubnub;

@@ -41,7 +43,7 @@ void IPubnubLog.WriteToLog(string logText)
}

[SetUp]
public static void Init()
public static async Task Init()
{
UnitTestLog unitLog = new Tests.UnitTestLog();
unitLog.LogLevel = MockServer.LoggingMethod.Level.Verbose;
@@ -91,17 +93,14 @@ public static void Init()
.WithResponse(expected)
.WithStatusCode(System.Net.HttpStatusCode.OK));

pubnub.Grant().Channels(channelsGrant).AuthKeys(new [] { authKey }).Read(true).Write(true).Manage(true).TTL(20).Execute(new UTGrantResult());

Thread.Sleep(3000);

grantManualEvent.WaitOne();

if (string.IsNullOrEmpty(PubnubCommon.GrantToken))
{
await GenerateTestGrantToken(pubnub);
}
authToken = PubnubCommon.GrantToken;
pubnub.Destroy();
pubnub.PubnubUnitTest = null;
pubnub = null;

Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannel2 Grant access failed.");
}

[TearDown]
@@ -156,7 +155,7 @@ private static void CommonSubscribeShouldReturnReceivedMessageBasedOnParams(stri
server.RunOnHttps(ssl);

SubscribeCallback listenerSubCallack = new UTSubscribeCallback();
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

manualResetEventWaitTimeout = 310 * 1000;
@@ -353,7 +352,7 @@ private static void CommonSubscribeShouldReturnEmojiMessageBasedOnParams(string
server.RunOnHttps(ssl);

SubscribeCallback listenerSubCallack = new UTSubscribeCallback();
pubnub = createPubNubInstance(config);
pubnub = createPubNubInstance(config, authToken);
pubnub.AddListener(listenerSubCallack);

manualResetEventWaitTimeout = 310 * 1000;

Unchanged files with check annotations Beta

}
}
private void MessageEmitter<T>(Pubnub pubnubInstance, PNMessageResult<T> messageResult)

Check warning on line 186 in src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs

GitHub Actions / Acceptance tests

Type parameter 'T' has the same name as the type parameter from outer type 'SubscribeEndpoint<T>'

Check warning on line 186 in src/Api/PubnubApi/EndPoint/PubSub/SubscribeEndpoint.cs

GitHub Actions / Integration and Unit tests

Type parameter 'T' has the same name as the type parameter from outer type 'SubscribeEndpoint<T>'
{
foreach (var listener in SubscribeListenerList)
{
namespace PubnubApi.EventEngine.Presence.Common
{
public class PresenceInput

Check warning on line 6 in src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs

GitHub Actions / Acceptance tests

'PresenceInput' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 6 in src/Api/PubnubApi/EventEngine/Presence/Common/PresenceInput.cs

GitHub Actions / Integration and Unit tests

'PresenceInput' overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
public IEnumerable<string> Channels { get; set; } = Enumerable.Empty<string>();
public IEnumerable<string> ChannelGroups { get; set; } = Enumerable.Empty<string>();
}
public class HandshakeReconnectSuccessEvent : HandshakeSuccessEvent {
public PNStatus Status;

Check warning on line 39 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Acceptance tests

'HandshakeReconnectSuccessEvent.Status' hides inherited member 'HandshakeSuccessEvent.Status'. Use the new keyword if hiding was intended.

Check warning on line 39 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Integration and Unit tests

'HandshakeReconnectSuccessEvent.Status' hides inherited member 'HandshakeSuccessEvent.Status'. Use the new keyword if hiding was intended.
public SubscriptionCursor Cursor;

Check warning on line 40 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Acceptance tests

'HandshakeReconnectSuccessEvent.Cursor' hides inherited member 'HandshakeSuccessEvent.Cursor'. Use the new keyword if hiding was intended.

Check warning on line 40 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Integration and Unit tests

'HandshakeReconnectSuccessEvent.Cursor' hides inherited member 'HandshakeSuccessEvent.Cursor'. Use the new keyword if hiding was intended.
public override string Name { get; set; } = "HANDSHAKE_RECONNECT_SUCCESS";
}
public class HandshakeReconnectFailureEvent : HandshakeFailureEvent
{
public IEnumerable<string> Channels;

Check warning on line 46 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Acceptance tests

'HandshakeReconnectFailureEvent.Channels' hides inherited member 'HandshakeFailureEvent.Channels'. Use the new keyword if hiding was intended.

Check warning on line 46 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Integration and Unit tests

'HandshakeReconnectFailureEvent.Channels' hides inherited member 'HandshakeFailureEvent.Channels'. Use the new keyword if hiding was intended.
public IEnumerable<string> ChannelGroups;

Check warning on line 47 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Acceptance tests

'HandshakeReconnectFailureEvent.ChannelGroups' hides inherited member 'HandshakeFailureEvent.ChannelGroups'. Use the new keyword if hiding was intended.

Check warning on line 47 in src/Api/PubnubApi/EventEngine/Subscribe/Events/SubscriptionEvents.cs

GitHub Actions / Integration and Unit tests

'HandshakeReconnectFailureEvent.ChannelGroups' hides inherited member 'HandshakeFailureEvent.ChannelGroups'. Use the new keyword if hiding was intended.
public override string Name { get; set; } = "HANDSHAKE_RECONNECT_FAILURE";
}
namespace PubnubApi.EventEngine.Presence.States
{
public abstract class APresenceState : Core.State

Check warning on line 7 in src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs

GitHub Actions / Acceptance tests

'APresenceState' overrides Object.Equals(object o) but does not override Object.GetHashCode()

Check warning on line 7 in src/Api/PubnubApi/EventEngine/Presence/States/APresenceState.cs

GitHub Actions / Integration and Unit tests

'APresenceState' overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
public PresenceInput Input { get; set; } = new PresenceInput(); // empty by default
};
}
protected TransitionResult HandleLeftEvent(Events.LeftEvent e)

Check warning on line 28 in src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs

GitHub Actions / Acceptance tests

'StoppedState.HandleLeftEvent(LeftEvent)' hides inherited member 'APresenceState.HandleLeftEvent(LeftEvent)'. Use the new keyword if hiding was intended.

Check warning on line 28 in src/Api/PubnubApi/EventEngine/Presence/States/StoppedState.cs

GitHub Actions / Integration and Unit tests

'StoppedState.HandleLeftEvent(LeftEvent)' hides inherited member 'APresenceState.HandleLeftEvent(LeftEvent)'. Use the new keyword if hiding was intended.
{
var newInput = this.Input - e.Input;
{
List<object> returnMessage = new List<object>();
if (config.CryptoModule != null || config.CipherKey.Length > 0)

Check warning on line 33 in src/Api/PubnubApi/Security/SecureMessage.cs

GitHub Actions / Acceptance tests

'PNConfiguration.CipherKey' is obsolete: 'CipherKey is deprecated, please use CryptoModule instead.'
{
config.CryptoModule ??= new CryptoModule(new LegacyCryptor(config.CipherKey, config.UseRandomInitializationVector, pubnubLog), null);

Check warning on line 35 in src/Api/PubnubApi/Security/SecureMessage.cs

GitHub Actions / Acceptance tests

'PNConfiguration.CipherKey' is obsolete: 'CipherKey is deprecated, please use CryptoModule instead.'
object[] myObjectArray = (from item in messageList
select item as object).ToArray();
object[] enumerable = myObjectArray[0] as object[];
if (fileContentBytes != null) {
requestState.GotJsonResponse = true;
byte[] outputBytes;
if (string.IsNullOrEmpty(currentFileCipherKey) && string.IsNullOrEmpty(config.CipherKey) && config.CryptoModule == null) {

Check warning on line 104 in src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs

GitHub Actions / Integration and Unit tests

'PNConfiguration.CipherKey' is obsolete: 'CipherKey is deprecated, please use CryptoModule instead.'
outputBytes = fileContentBytes;
} else {
CryptoModule currentCryptoModule = !string.IsNullOrEmpty(currentFileCipherKey) ? new CryptoModule(new LegacyCryptor(currentFileCipherKey, true, pubnubLog), null) : (config.CryptoModule ??= new CryptoModule(new LegacyCryptor(config.CipherKey, true, pubnubLog), null));

Check warning on line 107 in src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs

GitHub Actions / Integration and Unit tests

'PNConfiguration.CipherKey' is obsolete: 'CipherKey is deprecated, please use CryptoModule instead.'
try {
outputBytes = currentCryptoModule.Decrypt(fileContentBytes);
LoggingMethod.WriteToLog(pubnubLog, $"[{DateTime.Now.ToString(CultureInfo.InvariantCulture)}], Stream length (after Decrypt)= {fileContentBytes.Length}", config.LogVerbosity);