Add test for progress messages

This commit is contained in:
Xiaohongt 2015-03-24 15:45:24 -07:00
Родитель 3910efbc01
Коммит 40c0fba0f5
2 изменённых файлов: 72 добавлений и 0 удалений

Просмотреть файл

@ -304,3 +304,56 @@ TEST(hub_connection_tests, send_message_complex_type_return)
ASSERT_EQ(test.serialize(), U("{\"Address\":{\"Street\":\"main st\",\"Zip\":\"98052\"},\"Age\":15,\"Name\":\"test\"}"));
}
TEST(hub_connection_tests, progress_report)
{
auto hub_conn = std::make_shared<signalr::hub_connection>(url);
std::vector<int> vec;
auto hub_proxy = hub_conn->create_hub_proxy(U("hubConnection"));
hub_conn->start().then([&hub_proxy, &vec]()
{
return hub_proxy.invoke<web::json::value>(U("invokeWithProgress"), [&vec](const web::json::value& arguments)
{
vec.push_back(arguments.as_integer());
});
}).get();
ASSERT_EQ(vec.size(), 5);
for (size_t i = 0; i < vec.size(); i++)
{
ASSERT_EQ(vec[i], i);
}
}
TEST(hub_connection_tests, progress_report_with_return)
{
auto hub_conn = std::make_shared<signalr::hub_connection>(url);
std::vector<int> vec;
auto hub_proxy = hub_conn->create_hub_proxy(U("hubConnection"));
auto test = hub_conn->start().then([&hub_proxy, &vec]()
{
web::json::value obj{};
obj[0] = web::json::value(U("test"));
return hub_proxy.invoke<web::json::value>(U("invokeWithProgress"), obj, [&vec](const web::json::value& arguments)
{
vec.push_back(arguments.as_integer());
});
}).get();
ASSERT_EQ(test.serialize(), U("\"test done!\""));
ASSERT_EQ(vec.size(), 5);
for (size_t i = 0; i < vec.size(); i++)
{
ASSERT_EQ(vec[i], i);
}
}

Просмотреть файл

@ -59,5 +59,24 @@ namespace SelfHost
public string Street { get; set; }
public string Zip { get; set; }
}
public async Task InvokeWithProgress(IProgress<int> progress)
{
for (int i = 0; i < 5; i++)
{
await Task.Delay(10);
progress.Report(i);
}
}
public async Task<string> InvokeWithProgress(string jobName, IProgress<int> progress)
{
for (int i = 0; i < 5; i++)
{
await Task.Delay(10);
progress.Report(i);
}
return string.Format("{0} done!", jobName);
}
}
}