forked from Redth/PushSharp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBrokerTests.cs
92 lines (72 loc) · 2.26 KB
/
BrokerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using NUnit.Framework;
using System;
using PushSharp.Core;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;
using PushSharp.Apple;
using Newtonsoft.Json.Linq;
using System.Threading;
namespace PushSharp.Tests
{
[TestFixture]
[Category ("Core")]
public class BrokerTests
{
[Test]
public void Broker_Send_Many ()
{
var succeeded = 0;
var failed = 0;
var attempted = 0;
var broker = new TestServiceBroker ();
broker.OnNotificationFailed += (notification, exception) => {
failed++;
};
broker.OnNotificationSucceeded += (notification) => {
succeeded++;
};
broker.Start ();
broker.ChangeScale (1);
var c = Log.StartCounter ();
for (int i = 1; i <= 1000; i++) {
attempted++;
broker.QueueNotification (new TestNotification { TestId = i });
}
broker.Stop ();
c.StopAndLog ("Test Took {0} ms");
Assert.AreEqual (attempted, succeeded);
Assert.AreEqual (0, failed);
}
[Test]
#pragma warning disable 1998
public async Task Broker_Some_Fail ()
#pragma warning restore 1998
{
var succeeded = 0;
var failed = 0;
var attempted = 0;
const int count = 10;
var failIds = new [] { 3, 5, 7 };
var broker = new TestServiceBroker ();
broker.OnNotificationFailed += (notification, exception) =>
failed++;
broker.OnNotificationSucceeded += (notification) =>
succeeded++;
broker.Start ();
broker.ChangeScale (1);
var c = Log.StartCounter ();
for (int i = 1; i <= count; i++) {
attempted++;
broker.QueueNotification (new TestNotification {
TestId = i,
ShouldFail = failIds.Contains (i)
});
}
broker.Stop ();
c.StopAndLog ("Test Took {0} ms");
Assert.AreEqual (attempted - failIds.Length, succeeded);
Assert.AreEqual (failIds.Length, failed);
}
}
}