forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodingTests.cs
More file actions
89 lines (77 loc) · 3.09 KB
/
EncodingTests.cs
File metadata and controls
89 lines (77 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Text;
using NUnit.Framework;
namespace ServiceStack.WebHost.Endpoints.Tests
{
//[Route("/HelloWorld/Greeting/{FirstName}/{LastName}", "GET")]
[Route("/HelloWorld/Greeting/{FirstName}", "GET")]
[Restrict(RequestAttributes.InternalNetworkAccess)]
public class HelloWorldName : IReturn<HelloWorldGreeting>
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class HelloWorldGreeting
{
public string Greeting { get; set; }
}
public class HelloWorldService : Service
{
public HelloWorldGreeting Get(HelloWorldName request)
{
var answer = new HelloWorldGreeting
{
Greeting = "Hello " + request.FirstName + " " + request.LastName
};
return answer;
}
}
public class EncodingTestsAppHost : AppHostHttpListenerBase
{
public EncodingTestsAppHost() : base("EncodingTests", typeof(HelloWorldService).GetAssembly()) { }
public override void Configure(Funq.Container container) {}
}
[TestFixture]
public class EncodingTests
{
private EncodingTestsAppHost appHost;
[OneTimeSetUp]
public void TestFixtureSetUp()
{
appHost = new EncodingTestsAppHost();
appHost.Init();
appHost.Start(Config.AbsoluteBaseUri);
}
[OneTimeTearDown]
public void TestFixtureTearDown()
{
appHost.Dispose();
}
private HelloWorldGreeting PerformRequest(string firstName, string lastName)
{
var client = new JsonServiceClient(Config.ServiceStackBaseUri);
var query = string.Format("/HelloWorld/Greeting/{0}?lastname={1}", firstName, lastName);
return client.Get<HelloWorldGreeting>(query);
}
[Test]
public void Can_Get_Greeting_When_Querystring_Contains_Non_ASCII_Chars()
{
var firstName = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Pål"));
var lastName = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Smådalø"));
Assert.That(PerformRequest(firstName, lastName).Greeting, Is.EqualTo(string.Format("Hello {0} {1}", firstName, lastName)));
}
[Test]
public void Can_Get_Greeting_When_Only_Url_Contains_Non_ASCII_Chars()
{
var firstName = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Pål"));
var lastName = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Smith"));
Assert.That(PerformRequest(firstName, lastName).Greeting, Is.EqualTo(string.Format("Hello {0} {1}", firstName, lastName)));
}
[Test]
public void Can_Get_Greeting_When_Querystring_Contains_Only_ASCII_Chars()
{
var firstName = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("John"));
var lastName = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Smith"));
Assert.That(PerformRequest(firstName, lastName).Greeting, Is.EqualTo(string.Format("Hello {0} {1}", firstName, lastName)));
}
}
}