Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions JSONAPI.Tests/Json/JsonApiMediaFormaterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using JSONAPI.Tests.Models;
using Newtonsoft.Json;
Expand Down Expand Up @@ -117,6 +118,31 @@ public void SerializerIntegrationTest()
//Assert.AreEqual("[2,3,4]", sw.ToString());
}

[TestMethod]
[DeploymentItem(@"Data\SerializerIntegrationTest.json")]
public void SerializeArrayIntegrationTest()
{
// Arrange
//PayloadConverter pc = new PayloadConverter();
//ModelConverter mc = new ModelConverter();
//ContractResolver.PluralizationService = new PluralizationService();

JsonApiFormatter formatter = new JSONAPI.Json.JsonApiFormatter();
formatter.PluralizationService = new JSONAPI.Core.PluralizationService();
MemoryStream stream = new MemoryStream();

// Act
//Payload payload = new Payload(a.Posts);
//js.Serialize(jw, payload);
formatter.WriteToStreamAsync(typeof(Post), a.Posts.ToArray(), stream, (System.Net.Http.HttpContent)null, (System.Net.TransportContext)null);

// Assert
string output = System.Text.Encoding.ASCII.GetString(stream.ToArray());
Trace.WriteLine(output);
Assert.AreEqual(output.Trim(), File.ReadAllText("SerializerIntegrationTest.json").Trim());
//Assert.AreEqual("[2,3,4]", sw.ToString());
}

[TestMethod]
public void DeserializeCollectionIntegrationTest()
{
Expand Down
5 changes: 3 additions & 2 deletions JSONAPI/Json/JsonApiFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,9 @@ private bool IsMany(dynamic value = null)

private bool IsMany(Type type)
{
//TODO: Should we check for arrays also? (They aren't generics.)
return (type.GetInterfaces().Contains(typeof(IEnumerable)) && type.IsGenericType);
return
type.IsArray ||
(type.GetInterfaces().Contains(typeof(IEnumerable)) && type.IsGenericType);
}

private Type GetSingleType(Type type)//dynamic value = null)
Expand Down