Skip to content

Commit 8da9aaf

Browse files
committed
fix: serialize enumerable properties
#18
1 parent 2c348f2 commit 8da9aaf

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

.npmrc

-1
This file was deleted.

src/Aguacongas.AspNetCore.Authentication/ContractResolver.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Serialization;
55
using System;
6+
using System.Collections;
67
using System.Reflection;
78

89
namespace Aguacongas.AspNetCore.Authentication
@@ -29,7 +30,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
2930
var property = base.CreateProperty(member, memberSerialization);
3031
var propertyInfo = member as PropertyInfo;
3132
var propertyType = propertyInfo?.PropertyType;
32-
property.ShouldSerialize = instance => propertyType != null && !propertyType.IsInterface && propertyInfo.CanWrite && !propertyType.IsSubclassOf(typeof(Delegate));
33+
property.ShouldSerialize = instance => propertyType != null && (!propertyType.IsInterface || typeof(IEnumerable).IsAssignableFrom(propertyType)) && !propertyType.IsSubclassOf(typeof(Delegate));
3334

3435
return property;
3536
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Authentication.OAuth;
2+
using Xunit;
3+
4+
namespace Aguacongas.AspNetCore.Authentication.Test
5+
{
6+
public class AuthenticationSchemeOptionsSerializerTest
7+
{
8+
[Fact]
9+
public void SerializeOptions_should_serialize_OAuthOptionsScope()
10+
{
11+
var oAuthOptions = new OAuthOptions
12+
{
13+
ClientId = "test",
14+
};
15+
16+
oAuthOptions.Scope.Add("test");
17+
18+
var sut = new AuthenticationSchemeOptionsSerializer();
19+
20+
var result = sut.SerializeOptions(oAuthOptions, typeof(OAuthOptions));
21+
22+
var expected = sut.DeserializeOptions(result, typeof(OAuthOptions)) as OAuthOptions;
23+
24+
Assert.Contains(expected.Scope, value => value == "test");
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)