forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryStringSerializerTests.cs
More file actions
68 lines (59 loc) · 2.29 KB
/
QueryStringSerializerTests.cs
File metadata and controls
68 lines (59 loc) · 2.29 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
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Web;
using Funq;
using NUnit.Framework;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.Testing;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.WebHost.Endpoints.Support.Mocks;
namespace ServiceStack.Common.Tests
{
[TestFixture]
public class QueryStringSerializerTests
{
[Test]
public void Can_deserialize_TestRequest_QueryStringSerializer_output()
{
// Setup
var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly);
var restPath = new RestPath(typeof(TestRequest), "/service", "GET");
var restHandler = new RestHandler { RestPath = restPath };
var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}";
NameValueCollection queryString = HttpUtility.ParseQueryString(requestString);
var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection());
var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service");
Assert.That(request2.ListOfA.Count, Is.EqualTo(1));
Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2));
}
[Test]
public void QueryStringSerializer_TestRequest_output()
{
var testRequest = new TestRequest { ListOfA = new List<A> { new A { ListOfB = new List<B> { new B { Property = "prop1" }, new B { Property = "prop2" } } } } };
var str = QueryStringSerializer.SerializeToString(testRequest);
Assert.That(str, Is.EqualTo("ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}"));
}
public class TestService : ServiceInterface.Service
{
public object Get(TestRequest request)
{
return "OK";
}
}
public class TestRequest
{
public List<A> ListOfA { get; set; }
}
public class A
{
public List<B> ListOfB { get; set; }
}
public class B
{
public string Property { get; set; }
}
}
}