Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root=true
[*]
indent_size = 4
indent_style = tab
46 changes: 38 additions & 8 deletions source/Cucumber.SimpleDb.Test/Cucumber.SimpleDb.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\net40\System.IO.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=2.2.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.2.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Runtime">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\net40\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="Moq">
Expand All @@ -43,6 +66,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Fakes\FakeMessageHandler.cs" />
<Compile Include="SimpleDbAttributeValueConversionTest.cs" />
<Compile Include="SimpleDbAttributeValueAnyTest.cs" />
<Compile Include="SimpleDbAttributeValueEveryTest.cs" />
Expand All @@ -56,7 +80,6 @@
<Compile Include="Session\SimpleDbSessionTests.cs" />
<Compile Include="Transport\SimpleDbRestServiceTests.cs" />
<Compile Include="Transport\AwsRestServiceTest.cs" />
<Compile Include="Transport\CaptureUriRequestProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LINQ\Translation\SimpleDbQueryableTest.cs" />
<Compile Include="Transport\PassThroughAwsRestService.cs" />
Expand All @@ -74,14 +97,21 @@
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(SolutionDir).nuget\NuGet.targets" />
<ItemGroup>
<Folder Include="LINQ\IntegrationTests\" />
<Folder Include="Utilities\" />
<Folder Include="Session\" />
<Folder Include="Transport\" />
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
</Project>
28 changes: 28 additions & 0 deletions source/Cucumber.SimpleDb.Test/Fakes/FakeMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Cucumber.SimpleDb.Test.Fakes
{
//http://stackoverflow.com/questions/10693955/stubbing-or-mocking-asp-net-web-api-httpclient
internal class FakeHttpMessageHandler : HttpMessageHandler
{
private readonly HttpResponseMessage _responseMessage;
private readonly Action<HttpRequestMessage> _requestFilter;

public FakeHttpMessageHandler(HttpResponseMessage responseMessage, Action<HttpRequestMessage> requestFilter)
{
_responseMessage = responseMessage;
_requestFilter = requestFilter;
}

public HttpRequestMessage RequestMessage { get; private set; }

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
_requestFilter(request);
return Task.Factory.StartNew(() => _responseMessage, cancellationToken);
}
}
}
81 changes: 72 additions & 9 deletions source/Cucumber.SimpleDb.Test/Transport/AwsRestServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,88 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using Cucumber.SimpleDb.Test.Fakes;
using NUnit.Framework;
using System.Collections.Specialized;
using Cucumber.SimpleDb.Transport;

namespace Cucumber.SimpleDb.Test
{

[TestFixture ()]
public class AwsRestServiceTest
{
[Test ()]
public void ValidateRequestSignature ()
private HttpRequestMessage _requestMessage;
private HttpClient _httpClient;
[SetUp]
public void Setup()
{
var responseMessage = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("<All><Ok/></All>")
};
_httpClient = new HttpClient(new FakeHttpMessageHandler(responseMessage, req => _requestMessage = req));

}

[Test]
public void ExecuteRequest_ShouldSerializeArgumentsToRequest ()
{
string generatedUri = null;
var service = new AwsRestService ("myPublicKey", "myPrivateKey", new CaptureUriRequestProvider(uri => generatedUri = uri));
service.ExecuteRequest (new NameValueCollection {
var service = new AwsRestService("myPublicKey", "myPrivateKey", _httpClient);
var arguments = new NameValueCollection {
{ "Item.0.ItemName", "TestItem1" },
{ "Item.0.Attribute.0.Name", "TestAtt1" },
{ "Item.0.Attribute.0.Value", "123" }
});
//TODO: validate HMAC
};
service.ExecuteRequest(arguments);
Assert.NotNull(_requestMessage);

var requestData = _requestMessage.RequestUri.ToNameValueCollection();
Assert.NotNull(requestData);
Assert.IsTrue(requestData.Count > 0);
foreach(string key in arguments)
{
Assert.AreEqual(arguments[key], requestData[key]);
}

}

[Test]
public void ExecuteRequest_ShouldAddStandardArgumentsToRequest()
{
var service = new AwsRestService("myPublicKey", "myPrivateKey", _httpClient);
service.ExecuteRequest(new NameValueCollection());
Assert.NotNull(_requestMessage);

var requestData = _requestMessage.RequestUri.ToNameValueCollection();
Assert.NotNull(requestData);
Assert.IsTrue(requestData.Count > 0);
new[]
{
"AWSAccessKeyId",
"SignatureVersion",
"SignatureMethod",
"Timestamp",
"Version"
}.ToList()
.ForEach(key => Assert.IsNotNullOrEmpty(requestData[key]));
Assert.AreEqual("myPublicKey", requestData["AWSAccessKeyId"]);
}

[Test]
public void ExecuteRequest_ShouldAddSignatureToRequest()
{
var service = new AwsRestService("myPublicKey", "myPrivateKey", _httpClient);
service.ExecuteRequest(new NameValueCollection());
Assert.NotNull(_requestMessage);

var requestData = _requestMessage.RequestUri.ToNameValueCollection();
Assert.NotNull(requestData);
Assert.IsTrue(requestData.Count > 0);
Assert.IsNotNullOrEmpty(requestData["Signature"]);

//TODO: (CV) Should assert the actual signature. Need to move the signature generation logic out of the AwsRequestService class
}
}
}

This file was deleted.

11 changes: 11 additions & 0 deletions source/Cucumber.SimpleDb.Test/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.18.0" newVersion="2.2.18.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
3 changes: 3 additions & 0 deletions source/Cucumber.SimpleDb.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.3" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net40" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net40" />
<package id="NUnit" version="2.6.3" targetFramework="net40" />
</packages>
46 changes: 43 additions & 3 deletions source/Cucumber.SimpleDb/Cucumber.SimpleDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<RootNamespace>Cucumber.SimpleDb</RootNamespace>
<AssemblyName>Cucumber.SimpleDb</AssemblyName>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand All @@ -33,6 +35,29 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\net40\System.IO.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=2.2.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.2.18.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Runtime">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\net40\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks">
<HintPath>..\packages\Microsoft.Bcl.1.1.3\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -41,6 +66,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\HttpMethodExtensions.cs" />
<Compile Include="Extensions\QueryStringRelatedExtensions.cs" />
<Compile Include="Session\ISessionAttribute.cs" />
<Compile Include="Session\ISessionItem.cs" />
<Compile Include="Session\ISession.cs" />
Expand Down Expand Up @@ -96,16 +123,29 @@
<Compile Include="Transport\IAwsRestService.cs" />
<Compile Include="Transport\AwsRestService.cs" />
<Compile Include="Transport\SimpleDbRestService.cs" />
<Compile Include="Transport\WebRequestProvider.cs" />
<Compile Include="Transport\IWebRequestProvider.cs" />
<Compile Include="Linq\Translation\ImplicitSelect.cs" />
<Compile Include="Linq\Structure\CountExpression.cs" />
<Compile Include="Linq\Structure\ScalarExpression.cs" />
<Compile Include="Utilities\StringUtilities.cs" />
<Compile Include="SimpleDbQueryable.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
21 changes: 21 additions & 0 deletions source/Cucumber.SimpleDb/Extensions/HttpMethodExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;

namespace Cucumber.SimpleDb
{
internal static class HttpMethodExtensions
{
private static readonly IEnumerable<HttpMethod> NoBodyHttpMethods = new[]
{
//Not sure if this is the full list. Need to confirm with RFC.
HttpMethod.Get,
HttpMethod.Head
};

public static bool CanHaveContent(this HttpMethod httpMethod)
{
return NoBodyHttpMethods.All(a => a != httpMethod);
}
}
}
Loading