-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathLinkTemplateTests.cs
More file actions
67 lines (57 loc) · 1.73 KB
/
LinkTemplateTests.cs
File metadata and controls
67 lines (57 loc) · 1.73 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
using JSONAPI.Attributes;
using JSONAPI.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace JSONAPI.Tests.Json
{
[TestClass]
public class LinkTemplateTests
{
private class Post
{
public string Id { get; set; }
public string Title { get; set; }
[SerializeAs(SerializeAsOptions.Link)]
[LinkTemplate("/users/{0}")]
public virtual User Author { get; set; }
}
private class User
{
public string Id { get; set; }
public string Name { get; set; }
}
private Post ThePost { get; set; }
[TestInitialize]
public void SetupModels()
{
ThePost = new Post
{
Id = "2",
Title = "How to fry an egg",
Author = new User
{
Id = "5",
Name = "Bob"
}
};
}
[TestMethod]
[DeploymentItem(@"Data\LinkTemplateTest.json")]
public void GetResourceWithLinkTemplateRelationship()
{
var formatter = new JsonApiFormatter
(
new JSONAPI.Core.PluralizationService()
);
var stream = new MemoryStream();
formatter.WriteToStreamAsync(typeof(Post), ThePost, stream, null, null);
// Assert
var expected = JsonHelpers.MinifyJson(File.ReadAllText("LinkTemplateTest.json"));
var output = Encoding.ASCII.GetString(stream.ToArray());
Trace.WriteLine(output);
Assert.AreEqual(output.Trim(), expected);
}
}
}