forked from JSONAPIdotNET/JSONAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkFormatterTests.cs
More file actions
41 lines (36 loc) · 1.6 KB
/
Copy pathLinkFormatterTests.cs
File metadata and controls
41 lines (36 loc) · 1.6 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
using System.Threading.Tasks;
using JSONAPI.Documents;
using JSONAPI.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json;
namespace JSONAPI.Tests.Json
{
[TestClass]
public class LinkFormatterTests : JsonApiFormatterTestsBase
{
[TestMethod]
public async Task Serialize_link_without_metadata()
{
ILink link = new Link("http://www.example.com", null);
var formatter = new LinkFormatter(null);
await AssertSerializeOutput(formatter, link, "Json/Fixtures/LinkFormatter/Serialize_link_without_metadata.json");
}
[TestMethod]
public async Task Serialize_link_with_metadata()
{
var mockMetadataFormatter = new Mock<IMetadataFormatter>(MockBehavior.Strict);
mockMetadataFormatter.Setup(m => m.Serialize(It.IsAny<IMetadata>(), It.IsAny<JsonWriter>()))
.Returns((IMetadata metadata, JsonWriter writer) =>
{
writer.WriteValue("IMetadata placeholder 1");
return Task.FromResult(0);
}).Verifiable();
var mockMetadata = new Mock<IMetadata>(MockBehavior.Strict);
ILink link = new Link("http://www.example.com", mockMetadata.Object);
var formatter = new LinkFormatter(mockMetadataFormatter.Object);
await AssertSerializeOutput(formatter, link, "Json/Fixtures/LinkFormatter/Serialize_link_with_metadata.json");
mockMetadataFormatter.Verify(s => s.Serialize(mockMetadata.Object, It.IsAny<JsonWriter>()), Times.Once);
}
}
}