10/13/2013 - IndustrialEraStarted - adding a web request factory

This commit is contained in:
moozzyk 2014-10-13 15:12:46 -07:00
Родитель 841da2b6e6
Коммит 0c890e2190
9 изменённых файлов: 102 добавлений и 34 удалений

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

@ -99,6 +99,7 @@
<ClInclude Include="..\..\stdafx.h" />
<ClInclude Include="..\..\targetver.h" />
<ClInclude Include="..\..\url_builder.h" />
<ClInclude Include="..\..\web_request_factory.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\connection.cpp" />

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

@ -51,6 +51,9 @@
<ClInclude Include="..\..\..\..\include\signalrclient\web_exception.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\web_request_factory.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\stdafx.cpp">

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

@ -11,12 +11,6 @@ namespace signalr
{
namespace http_sender
{
template<typename T>
static pplx::task<utility::string_t> get(const web::uri &url)
{
get(T(url));
}
template<typename T>
static pplx::task<utility::string_t> get(T &request)
{

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

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#pragma once
#include <cpprest\base_uri.h>
namespace signalr
{
template<typename T>
class web_request_factory
{
public:
virtual T create_web_request(const web::uri &url) const
{
return T(url);
}
};
}

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

@ -86,6 +86,8 @@
<ItemGroup>
<ClInclude Include="..\..\stdafx.h" />
<ClInclude Include="..\..\targetver.h" />
<ClInclude Include="..\..\test_web_request_factory.h" />
<ClInclude Include="..\..\web_request_stub.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\http_sender_tests.cpp" />

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

@ -21,6 +21,12 @@
<ClInclude Include="..\..\targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\web_request_stub.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\test_web_request_factory.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\stdafx.cpp">

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

@ -4,35 +4,9 @@
#include "stdafx.h"
#include <cpprest\basic_types.h>
#include <cpprest\asyncrt_utils.h>
#include "http_sender.h"
#include "signalrclient\web_exception.h"
using namespace signalr;
struct web_request_stub
{
unsigned short m_status_code;
utility::string_t m_reason_code;
utility::string_t m_response_body;
utility::string_t m_method;
utility::string_t m_user_agent_string;
void set_method(const utility::string_t &method)
{
m_method = method;
}
void set_user_agent(const utility::string_t &user_agent_string)
{
m_user_agent_string = user_agent_string;
}
pplx::task<web_response> get_response()
{
return pplx::task_from_result<web_response>(
web_response{ m_status_code, m_reason_code, pplx::task_from_result<utility::string_t>(m_response_body) });
}
};
#include "http_sender.h"
#include "web_request_stub.h"
TEST(http_sender_get_response, request_sent_using_get_method)
{

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

@ -0,0 +1,27 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#pragma once
#include "web_request_factory.h"
#include "web_request_stub.h"
using namespace signalr;
template<typename T>
class test_web_request_factory : public web_request_factory<T>
{
private:
T m_web_request;
public:
test_web_request_factory(const T &web_request)
: m_web_request(web_request)
{ }
T create_web_request(const web::uri &) const
{
return m_web_request;
}
};

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

@ -0,0 +1,42 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#pragma once
#include <cpprest\basic_types.h>
#include "signalrclient\web_response.h"
using namespace signalr;
struct web_request_stub
{
web::uri m_url;
unsigned short m_status_code;
utility::string_t m_reason_phrase;
utility::string_t m_response_body;
utility::string_t m_method;
utility::string_t m_user_agent_string;
web_request_stub(const web::uri &url) : m_url(url)
{ }
web_request_stub(unsigned short status_code, const utility::string_t &reason_phrase, const utility::string_t &response_body = _XPLATSTR(""))
: m_status_code(status_code), m_reason_phrase(reason_phrase), m_response_body(response_body)
{ }
void set_method(utility::string_t method)
{
m_method = method;
}
void set_user_agent(utility::string_t user_agent_string)
{
m_method = m_user_agent_string;
}
pplx::task<web_response> get_response()
{
return pplx::task_from_result<web_response>(
web_response{ m_status_code, m_reason_phrase, pplx::task_from_result<utility::string_t>(m_response_body) });
}
};