Skip to content

Commit 962be72

Browse files
author
Chris Santero
committed
use fixture file for metadata manager test
1 parent dc1dc20 commit 962be72

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using JSONAPI.Json;
43
using System.IO;
54
using JSONAPI.Tests.Models;
@@ -11,29 +10,28 @@ namespace JSONAPI.Tests.Core
1110
public class MetadataManagerTests
1211
{
1312
[TestMethod]
13+
[DeploymentItem(@"Data\MetadataManagerPropertyWasPresentRequest.json")]
1414
public void PropertyWasPresentTest()
1515
{
16-
// Arrange
16+
using (var inputStream = File.OpenRead("MetadataManagerPropertyWasPresentRequest.json"))
17+
{
18+
// Arrange
19+
JsonApiFormatter formatter = new JsonApiFormatter(new PluralizationService());
1720

18-
JsonApiFormatter formatter = new JSONAPI.Json.JsonApiFormatter(new JSONAPI.Core.PluralizationService());
19-
MemoryStream stream = new MemoryStream();
21+
var p = (Post) formatter.ReadFromStreamAsync(typeof(Post), inputStream, null, null).Result;
2022

21-
stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(@"{""posts"":{""id"":42,""links"":{""author"":""18""}}}"));
23+
// Act
24+
bool idWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Id"));
25+
bool titleWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Title"));
26+
bool authorWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Author"));
27+
bool commentsWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Comments"));
2228

23-
Post p;
24-
p = (Post)formatter.ReadFromStreamAsync(typeof(Post), stream, (System.Net.Http.HttpContent)null, (System.Net.Http.Formatting.IFormatterLogger)null).Result;
25-
26-
// Act
27-
bool idWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Id"));
28-
bool titleWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Title"));
29-
bool authorWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Author"));
30-
bool commentsWasSet = MetadataManager.Instance.PropertyWasPresent(p, p.GetType().GetProperty("Comments"));
31-
32-
// Assert
33-
Assert.IsTrue(idWasSet, "Id was not reported as set, but was.");
34-
Assert.IsFalse(titleWasSet, "Title was reported as set, but was not.");
35-
Assert.IsTrue(authorWasSet, "Author was not reported as set, but was.");
36-
Assert.IsFalse(commentsWasSet, "Comments was reported as set, but was not.");
29+
// Assert
30+
Assert.IsTrue(idWasSet, "Id was not reported as set, but was.");
31+
Assert.IsFalse(titleWasSet, "Title was reported as set, but was not.");
32+
Assert.IsTrue(authorWasSet, "Author was not reported as set, but was.");
33+
Assert.IsFalse(commentsWasSet, "Comments was reported as set, but was not.");
34+
}
3735
}
3836
}
3937
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"posts": {
3+
"id": "42",
4+
"links": {
5+
"author": "18"
6+
}
7+
}
8+
}

JSONAPI.Tests/JSONAPI.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
</ItemGroup>
105105
<ItemGroup>
106106
<None Include="app.config" />
107+
<None Include="Data\MetadataManagerPropertyWasPresentRequest.json">
108+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
109+
</None>
107110
<None Include="Data\ByteIdSerializationTest.json">
108111
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
109112
</None>

0 commit comments

Comments
 (0)