Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple query string values with the same key #70

Merged
merged 1 commit into from Sep 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CommonAssemblyInfo.cs
@@ -1,5 +1,5 @@
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Mark Rendle")]
[assembly: AssemblyProduct("Simple.Web")]
Expand Down
27 changes: 27 additions & 0 deletions src/Sandbox/GetEnumerable.cs
@@ -0,0 +1,27 @@
namespace Sandbox
{
using System.Collections.Generic;
using System.Linq;

using Simple.Web;
using Simple.Web.Behaviors;

[UriTemplate("/enumerable")]
public class GetEnumerable : IGet, IOutput<EnumerableModel>
{
public Status Get()
{
this.Output = new EnumerableModel { Messages = this.Message.ToArray() };
return 200;
}

public IEnumerable<string> Message { get; set; }

public EnumerableModel Output { get; set; }
}

public class EnumerableModel
{
public string[] Messages { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Sandbox/Sandbox.csproj
Expand Up @@ -99,6 +99,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ExceptionHandler.cs" />
<Compile Include="GetEnumerable.cs" />
<Compile Include="GetError.cs" />
<Compile Include="GetModel.cs" />
<Compile Include="Models\Form.cs" />
Expand Down Expand Up @@ -160,6 +161,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Views\EnumerableQSArg.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
17 changes: 17 additions & 0 deletions src/Sandbox/Views/EnumerableQSArg.cshtml
@@ -0,0 +1,17 @@
@model Sandbox.EnumerableModel

<!DOCTYPE html>

<html>
<head>
<title>title</title>
</head>
<body>
<div>
@foreach (var message in Model.Messages)
{
<br/>@message
}
</div>
</body>
</html>
6 changes: 3 additions & 3 deletions src/Simple.Web.Autofac.Tests/HandlerFactoryBuilderTests.cs
@@ -1,11 +1,11 @@
using System;
using Autofac;
using System;
using System.Collections.Generic;
using Autofac;

namespace Simple.Web.Autofac.Tests
{
using System.Reflection;
using CodeGeneration;
using System.Reflection;
using Xunit;

public class HandlerFactoryBuilderTests
Expand Down
4 changes: 2 additions & 2 deletions src/Simple.Web.Autofac.Tests/HandlersModuleTests.cs
@@ -1,5 +1,5 @@
using System.Reflection;
using Autofac;
using Autofac;
using System.Reflection;
using Xunit;

namespace Simple.Web.Autofac.Tests
Expand Down
96 changes: 90 additions & 6 deletions src/Simple.Web.Tests/HandlerBuilderFactoryTests.cs
Expand Up @@ -11,7 +11,7 @@ public class HandlerBuilderFactoryTests
public void CreatesTypeWithParameterlessConstructorUsingDefaultContainer()
{
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof (ParameterlessConstructorType));
var actualFunc = target.BuildHandlerBuilder(typeof(ParameterlessConstructorType));
var actual = actualFunc(new Dictionary<string, string>());
Assert.IsType<ParameterlessConstructorType>(actual.Handler);
}
Expand All @@ -20,7 +20,7 @@ public void CreatesTypeWithParameterlessConstructorUsingDefaultContainer()
public void CreatingTypeWithNoParameterlessConstructorUsingDefaultContainerThrowsInvalidOperationException()
{
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof (NoParameterlessConstructorType));
var actualFunc = target.BuildHandlerBuilder(typeof(NoParameterlessConstructorType));
Assert.Throws<InvalidOperationException>(() => actualFunc(new Dictionary<string, string>()));
}

Expand All @@ -29,25 +29,109 @@ public void SetsGuidPropertyCorrectly()
{
var guid = new Guid("FA37E0B4-2DB9-4471-BC6C-229748F417CA");
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof (GuidHolder));
var actual = (GuidHolder)actualFunc(new Dictionary<string, string>{{"Guid",guid.ToString()}}).Handler;
var actualFunc = target.BuildHandlerBuilder(typeof(GuidHolder));
var actual = (GuidHolder)actualFunc(new Dictionary<string, string> { { "Guid", guid.ToString() } }).Handler;
Assert.Equal(guid, actual.Guid);
}

[Fact]
public void SetsEnumerableGuidPropertyCorrectly()
{
var guidCollection = new[]
{
new Guid("FA37E0B4-2DB9-4471-BC6C-229748F417CA"),
new Guid("47A210D9-7E5D-480A-9300-B2CF1443C496")
};
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof(EnumerableGuidHolder));
var actual = (EnumerableGuidHolder)actualFunc(new Dictionary<string, string> { { "Guids", "FA37E0B4-2DB9-4471-BC6C-229748F417CA\t47A210D9-7E5D-480A-9300-B2CF1443C496" } }).Handler;
Assert.Equal(guidCollection, actual.Guids);
}

[Fact]
public void SetsEnumerableStringPropertyCorrectly()
{
var stringCollection = new[]
{
"hello",
"world"
};
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof(EnumerableStringHolder));
var actual = (EnumerableStringHolder)actualFunc(new Dictionary<string, string> { { "Strings", "hello\tworld" } }).Handler;
Assert.Equal((IEnumerable<string>)stringCollection, (IEnumerable<string>)actual.Strings);
}

[Fact]
public void SetsEnumerableEnumPropertyCorrectly()
{
var enumCollection = new[]
{
Enterprise.Kirk,
Enterprise.Spock
};
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof(EnumerableEnumHolder));
var actual = (EnumerableEnumHolder)actualFunc(new Dictionary<string, string> { { "Trekkers", "Kirk\tSpock" } }).Handler;
Assert.Equal((IEnumerable<Enterprise>)enumCollection, (IEnumerable<Enterprise>)actual.Trekkers);
}

[Fact]
public void SetsSingleEnumPropertyCorrectly()
{
var target = new HandlerBuilderFactory(new Configuration());
var actualFunc = target.BuildHandlerBuilder(typeof(SingleEnumHolder));
var actual = (SingleEnumHolder)actualFunc(new Dictionary<string, string> { { "Trekker", "Uhura" } }).Handler;
Assert.Equal(Enterprise.Uhura, actual.Trekker);
}
}

class NoParameterlessConstructorType
{
public NoParameterlessConstructorType(int n)
{

}
}

class ParameterlessConstructorType
{

}

class GuidHolder
{
public Guid? Guid { get; set; }
}

class EnumerableGuidHolder
{
public IEnumerable<Guid> Guids { get; set; }
}

class EnumerableStringHolder
{
public IEnumerable<string> Strings { get; set; }
}

enum Enterprise
{
Kirk,
McCoy,
Scott,
Spock,
Uhura,
Chekov,
Zulu
}

class EnumerableEnumHolder
{
public IEnumerable<Enterprise> Trekkers { get; set; }
}

class SingleEnumHolder
{
public Enterprise Trekker { get; set; }
}
}