Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

Commit 40c0fba

Browse files
committed
Add test for progress messages
1 parent 3910efb commit 40c0fba

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

test/signalrclient-e2e-tests/hub_connection_tests.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,56 @@ TEST(hub_connection_tests, send_message_complex_type_return)
304304

305305
ASSERT_EQ(test.serialize(), U("{\"Address\":{\"Street\":\"main st\",\"Zip\":\"98052\"},\"Age\":15,\"Name\":\"test\"}"));
306306
}
307+
308+
TEST(hub_connection_tests, progress_report)
309+
{
310+
auto hub_conn = std::make_shared<signalr::hub_connection>(url);
311+
std::vector<int> vec;
312+
313+
auto hub_proxy = hub_conn->create_hub_proxy(U("hubConnection"));
314+
315+
hub_conn->start().then([&hub_proxy, &vec]()
316+
{
317+
return hub_proxy.invoke<web::json::value>(U("invokeWithProgress"), [&vec](const web::json::value& arguments)
318+
{
319+
vec.push_back(arguments.as_integer());
320+
});
321+
322+
}).get();
323+
324+
ASSERT_EQ(vec.size(), 5);
325+
326+
for (size_t i = 0; i < vec.size(); i++)
327+
{
328+
ASSERT_EQ(vec[i], i);
329+
}
330+
}
331+
332+
TEST(hub_connection_tests, progress_report_with_return)
333+
{
334+
auto hub_conn = std::make_shared<signalr::hub_connection>(url);
335+
std::vector<int> vec;
336+
337+
auto hub_proxy = hub_conn->create_hub_proxy(U("hubConnection"));
338+
339+
auto test = hub_conn->start().then([&hub_proxy, &vec]()
340+
{
341+
web::json::value obj{};
342+
obj[0] = web::json::value(U("test"));
343+
344+
return hub_proxy.invoke<web::json::value>(U("invokeWithProgress"), obj, [&vec](const web::json::value& arguments)
345+
{
346+
vec.push_back(arguments.as_integer());
347+
});
348+
349+
}).get();
350+
351+
ASSERT_EQ(test.serialize(), U("\"test done!\""));
352+
353+
ASSERT_EQ(vec.size(), 5);
354+
355+
for (size_t i = 0; i < vec.size(); i++)
356+
{
357+
ASSERT_EQ(vec[i], i);
358+
}
359+
}

test/signalrclient-testhost/Connections/HubConnection.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,24 @@ public class Address
5959
public string Street { get; set; }
6060
public string Zip { get; set; }
6161
}
62+
63+
public async Task InvokeWithProgress(IProgress<int> progress)
64+
{
65+
for (int i = 0; i < 5; i++)
66+
{
67+
await Task.Delay(10);
68+
progress.Report(i);
69+
}
70+
}
71+
72+
public async Task<string> InvokeWithProgress(string jobName, IProgress<int> progress)
73+
{
74+
for (int i = 0; i < 5; i++)
75+
{
76+
await Task.Delay(10);
77+
progress.Report(i);
78+
}
79+
return string.Format("{0} done!", jobName);
80+
}
6281
}
6382
}

0 commit comments

Comments
 (0)