Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit d256022

Browse files
committed
Added the missing CaseSensitivityFixture
1 parent 0d92757 commit d256022

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

Diff for: src/Nancy.Testing.Tests/CaseSensitivityFixture.cs

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
namespace Nancy.Testing.Tests
2+
{
3+
using Xunit;
4+
using Nancy.Tests;
5+
using Nancy.ModelBinding;
6+
7+
public class CaseSensitivityFixture
8+
{
9+
private Browser browser;
10+
11+
public class MainModule : NancyModule
12+
{
13+
public MainModule()
14+
{
15+
Get["/"] = _ =>
16+
{
17+
string name = Request.Query.animal.HasValue ? Request.Query.animal : "";
18+
return name;
19+
};
20+
21+
Get["/{ANIMAL}"] = args =>
22+
{
23+
string name = args.animal.HasValue ? args.animal : "";
24+
return name;
25+
};
26+
27+
Get["/animal"] = _ =>
28+
{
29+
Animal animal = this.Bind<Animal>();
30+
return animal.Type;
31+
};
32+
}
33+
}
34+
35+
public class Animal
36+
{
37+
public string Type { get; set; }
38+
}
39+
40+
public CaseSensitivityFixture()
41+
{
42+
var bootstrapper = new ConfigurableBootstrapper(with =>
43+
{
44+
with.Module<MainModule>();
45+
});
46+
47+
this.browser = new Browser(bootstrapper);
48+
}
49+
50+
[Fact]
51+
public void Should_pull_query_parameter_with_different_case()
52+
{
53+
StaticConfiguration.CaseSensitive = false;
54+
string animal = "dog";
55+
var response = browser.Get("/", with =>
56+
{
57+
with.Query("ANIMAL", animal);
58+
});
59+
60+
response.Body.AsString().ShouldEqual(animal);
61+
}
62+
63+
[Fact]
64+
public void Should_not_pull_query_parameter_with_different_case_when_sensitivity_is_on()
65+
{
66+
StaticConfiguration.CaseSensitive = true;
67+
string animal = "dog";
68+
var response = browser.Get("/", with =>
69+
{
70+
with.Query("ANIMAL", animal);
71+
});
72+
73+
response.Body.AsString().ShouldEqual("");
74+
}
75+
76+
[Fact]
77+
public void Should_pull_parameter_with_different_case()
78+
{
79+
StaticConfiguration.CaseSensitive = false;
80+
string animal = "dog";
81+
var response = browser.Get("/dog", with =>
82+
{
83+
});
84+
85+
response.Body.AsString().ShouldEqual(animal);
86+
}
87+
88+
[Fact]
89+
public void Should_not_pull_parameter_with_different_case_when_sensitivity_is_on()
90+
{
91+
StaticConfiguration.CaseSensitive = true;
92+
string animal = "dog";
93+
var response = browser.Get("/dog", with =>
94+
{
95+
});
96+
97+
response.Body.AsString().ShouldEqual("");
98+
}
99+
100+
[Fact]
101+
public void Should_bind_with_different_case()
102+
{
103+
StaticConfiguration.CaseSensitive = false;
104+
string animal = "dog";
105+
var response = browser.Get("/animal", with =>
106+
{
107+
with.Query("TYPE", animal);
108+
});
109+
110+
response.Body.AsString().ShouldEqual(animal);
111+
}
112+
113+
[Fact]
114+
public void Should_not_bind_with_different_case_when_sensitivity_is_on()
115+
{
116+
StaticConfiguration.CaseSensitive = true;
117+
string animal = "dog";
118+
var response = browser.Get("/animal", with =>
119+
{
120+
with.Query("TYPE", animal);
121+
});
122+
123+
response.Body.AsString().ShouldEqual("");
124+
}
125+
126+
127+
}
128+
}

0 commit comments

Comments
 (0)