Building negotiate request relative uri.

This commit is contained in:
moozzyk 2014-09-29 14:34:01 -07:00
Родитель 22de2f51ce
Коммит a6c6c5335b
9 изменённых файлов: 72 добавлений и 4 удалений

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

@ -6,8 +6,16 @@ namespace signalr
{
class connection
{
private:
web::uri m_base_uri;
utility::string_t m_querystring;
public:
connection(utility::string_t uri, utility::string_t queryString = U(""));
connection(const utility::string_t& url, const utility::string_t& querystring = U(""))
: m_base_uri(url), m_querystring(querystring)
{
}
~connection();
SIGNALRCLIENT_API pplx::task<void> start();

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

@ -91,8 +91,10 @@
<ClInclude Include="..\..\..\..\include\signalrclient\trace_level.h" />
<ClInclude Include="..\..\..\..\include\signalrclient\transport_type.h" />
<ClInclude Include="..\..\..\..\include\signalrclient\_exports.h" />
<ClInclude Include="..\..\constants.h" />
<ClInclude Include="..\..\stdafx.h" />
<ClInclude Include="..\..\targetver.h" />
<ClInclude Include="..\..\url_builder.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\connection.cpp" />

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

@ -33,6 +33,12 @@
<ClInclude Include="..\..\..\..\include\signalrclient\trace_level.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\url_builder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\constants.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\stdafx.cpp">

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

@ -0,0 +1,5 @@
#pragma once
#include "cpprest\basic_types.h"
#define PROTOCOL _XPLATSTR("1.4")

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

@ -5,4 +5,3 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

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

@ -0,0 +1,21 @@
#include <cpprest\http_client.h>
#include "constants.h"
using namespace web;
namespace signalr {
namespace url_builder
{
uri_builder build_uri(const utility::string_t &command, const utility::string_t &query_string)
{
return uri_builder(command)
.append_query(_XPLATSTR("clientProtocol"), PROTOCOL)
.append_query(query_string);
}
uri build_negotiate(const utility::string_t &query_string)
{
return build_uri(_XPLATSTR("negotiate"), query_string).to_uri();
}
}
}

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

@ -58,7 +58,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\gtest-1.7.0\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\gtest-1.7.0\include;..\..\..\..\include;..\..\..\..\src\signalrclient;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -87,11 +87,12 @@
<ClInclude Include="..\..\targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\SignalRClientTests.cpp" />
<ClCompile Include="..\..\signalrclienttests.cpp" />
<ClCompile Include="..\..\stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\..\url_builder_tests.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\src\SignalRClient\Build\VS2013\SignalRClient.vcxproj">

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

@ -29,6 +29,9 @@
<ClCompile Include="..\..\SignalRClientTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\url_builder_tests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

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

@ -0,0 +1,23 @@
#include "stdafx.h"
#include "url_builder.h"
using namespace web;
using namespace signalr;
TEST(url_builder_negotiate, url_correct_if_query_string_empty)
{
ASSERT_EQ(
uri(_XPLATSTR("negotiate?clientProtocol=1.4")),
signalr::url_builder::build_negotiate(_XPLATSTR("")));
}
TEST(url_builder, url_correct_if_query_string_not_empty)
{
ASSERT_EQ(
uri(_XPLATSTR("negotiate?clientProtocol=1.4&q1=1&q2=2")),
signalr::url_builder::build_negotiate(_XPLATSTR("q1=1&q2=2")));
ASSERT_EQ(
uri(_XPLATSTR("negotiate?clientProtocol=1.4&q1=1&q2=2")),
signalr::url_builder::build_negotiate(_XPLATSTR("&q1=1&q2=2")));
}