/
HalResourceListTests.cs
67 lines (59 loc) · 2.24 KB
/
HalResourceListTests.cs
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
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using ApprovalTests;
using ApprovalTests.Reporters;
using WebApi.Hal.Tests.Representations;
using Xunit;
namespace WebApi.Hal.Tests
{
public class HalResourceListTests
{
readonly RepresentationList<OrganisationRepresentation> representation;
public HalResourceListTests()
{
representation = new OrganisationListRepresentation(
new List<OrganisationRepresentation>
{
new OrganisationRepresentation(1, "Org1"),
new OrganisationRepresentation(2, "Org2")
});
}
[Fact]
[UseReporter(typeof(DiffReporter))]
public void organisation_list_get_xml_test()
{
// arrange
var mediaFormatter = new XmlHalMediaTypeFormatter();
var contentHeaders = new StringContent(string.Empty).Headers;
var type = representation.GetType();
// act
using (var stream = new MemoryStream())
{
mediaFormatter.WriteToStream(type, representation, stream, contentHeaders);
stream.Seek(0, SeekOrigin.Begin);
var serialisedResult = new StreamReader(stream).ReadToEnd();
// assert
Approvals.Verify(serialisedResult);
}
}
[Fact]
[UseReporter(typeof(DiffReporter))]
public void organisation_list_get_json_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeFormatter { Indent = true };
var contentHeaders = new StringContent(string.Empty).Headers;
var type = representation.GetType();
// act
using (var stream = new MemoryStream())
{
mediaFormatter.WriteToStreamAsync(type, representation, stream, contentHeaders, null).Wait();
stream.Seek(0, SeekOrigin.Begin);
var serialisedResult = new StreamReader(stream).ReadToEnd();
// assert
Approvals.Verify(serialisedResult);
}
}
}
}