Skip to content

Commit baea808

Browse files
pragnagopamathewc
authored andcommitted
NotificationHub test fixes
1 parent 4f99d7d commit baea808

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

test/WebJobs.Script.Tests/CSharpEndToEndTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ public async Task DocumentDB()
3131
await DocumentDBTest();
3232
}
3333

34-
[Fact(Skip = "Currently broken")]
34+
[Fact]
3535
public async Task NotificationHub()
3636
{
37-
await NotificationHubTest();
37+
await NotificationHubTest("NotificationHubOut");
3838
}
3939

40-
[Fact(Skip = "Currently broken")]
40+
[Fact]
4141
public async Task NotificationHub_Out_Notification()
4242
{
4343
await Fixture.TouchProjectJson("NotificationHubOutNotification");
44-
await NotificationHubTest();
44+
await NotificationHubTest("NotificationHubOutNotification");
4545
}
4646

4747
[Fact]

test/WebJobs.Script.Tests/EndToEndTestsBase.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected async Task DocumentDBTest()
6969
Assert.Equal(doc.Id, id);
7070
}
7171

72-
protected async Task NotificationHubTest()
72+
protected async Task NotificationHubTest(string functionName)
7373
{
7474
// NotificationHub tests need the following environment vars:
7575
// "AzureWebJobsNotificationHubsConnectionString" -- the connection string for NotificationHubs
@@ -78,11 +78,27 @@ protected async Task NotificationHubTest()
7878
{
7979
{ "input", "Hello" }
8080
};
81-
82-
//Only verifying the call succeeds. It is not possible to verify
83-
//actual push notificaiton is delivered as they are sent only to
84-
//client applications that registered with NotificationHubs
85-
await Fixture.Host.CallAsync("NotificationHubOut", arguments);
81+
82+
try
83+
{
84+
//Only verifying the call succeeds. It is not possible to verify
85+
//actual push notificaiton is delivered as they are sent only to
86+
//client applications that registered with NotificationHubs
87+
await Fixture.Host.CallAsync(functionName, arguments);
88+
}
89+
catch (Exception ex)
90+
{
91+
// Node: Check innerException, CSharp: check innerExcpetion.innerException
92+
if (VerifyNotificationHubExceptionMessage(ex.InnerException)
93+
|| VerifyNotificationHubExceptionMessage(ex.InnerException.InnerException))
94+
{
95+
//Expected if using NH without any registrations
96+
}
97+
else
98+
{
99+
throw;
100+
}
101+
}
86102
}
87103

88104
protected async Task EasyTablesTest(bool writeToQueue = true)
@@ -197,5 +213,16 @@ protected static string RemoveByteOrderMarkAndWhitespace(string s)
197213
string byteOrderMark = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
198214
return s.Trim().Replace(" ", string.Empty).Replace(byteOrderMark, string.Empty);
199215
}
216+
217+
protected static bool VerifyNotificationHubExceptionMessage(Exception exception)
218+
{
219+
if ((exception.Source == "Microsoft.Azure.NotificationHubs")
220+
&& exception.Message.Contains("notification has no target applications"))
221+
{
222+
//Expected if using NH without any registrations
223+
return true;
224+
}
225+
return false;
226+
}
200227
}
201228
}

test/WebJobs.Script.Tests/NodeEndToEndTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public async Task DocumentDB()
4545
await DocumentDBTest();
4646
}
4747

48-
[Fact(Skip = "Currently broken")]
48+
[Fact]
4949
public async Task NotificationHub()
5050
{
51-
await NotificationHubTest();
51+
await NotificationHubTest("NotificationHubOut");
5252
}
5353

5454
[Fact]

0 commit comments

Comments
 (0)