Skip to content

Commit

Permalink
try set value inner for enumerable type bug fix, null check
Browse files Browse the repository at this point in the history
  • Loading branch information
gencebay committed Feb 16, 2018
1 parent 58b9f42 commit 60dfe9a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/NetCoreStack.Proxy/DefaultModelContentResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ private void TrySetValueInner(string key, ProxyModelMetadata modelMetadata, Mode
var index = 0;
foreach (var v in values)
{
if (v == null)
{
continue;
}

var propKey = $"{key}[{index}]";
var propValue = propertyInfo?.GetValue(v);
ResolveInternal(elementModelMetadata, result, propValue, isTopLevelObject:false, prefix: propKey);
Expand Down
2 changes: 1 addition & 1 deletion src/NetCoreStack.Proxy/NetCoreStack.Proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="NetCoreStack.Contracts" Version="2.0.5" />
<PackageReference Include="NetCoreStack.Contracts" Version="2.0.6" />
<PackageReference Include="NetCoreStack.DispatchProxyAsync" Version="2.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.2" />
<PackageReference Include="NetCoreStack.Contracts" Version="2.0.5" />
<PackageReference Include="NetCoreStack.Contracts" Version="2.0.6" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions test/NetCoreStack.Proxy.Test.Contracts/TypesModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using NetCoreStack.Contracts;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -66,6 +67,12 @@ public class Foo
public IEnumerable<int> IEnumerableInt { get; set; }
}

public class FooColumns
{
public string String { get; set; }
public List<Column> IEnumerableColumns { get; set; }
}

public class Bar
{
public string String { get; set; }
Expand Down
42 changes: 41 additions & 1 deletion test/NetCoreStack.Proxy.Tests/ModelTypeTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using NetCoreStack.Proxy.Internal;
using NetCoreStack.Contracts;
using NetCoreStack.Proxy.Internal;
using NetCoreStack.Proxy.Test.Contracts;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Xunit;

Expand Down Expand Up @@ -167,6 +170,25 @@ public void ProxyModelMetadataInfoForFooModel()
Assert.Equal(6, contentResult.Dictionary.Count);
}

[Fact]
public void ProxyModelMetadataInfoForFooModelNull()
{
Foo model = new Foo
{
String = "Foo string value!",
IEnumerableInt = null
};

var contentResult = GetResolvedContentResult(model);

var expect = new Dictionary<string, string>()
{
["String"] = "Foo string value!"
};

Assert.Equal(expect, contentResult.Dictionary);
}

[Fact]
public void ProxyModelMetadataInfoForBarModel()
{
Expand Down Expand Up @@ -414,6 +436,24 @@ public void ProxyModelMetadataInfoForFileModel()
Assert.Equal("some_text_file.txt", files["InnerFileModel.Files[0]"].FileName);
}

[Fact]
public void FooColumnEnumerableNullItemTest()
{
var objStr = File.ReadAllText("ObjFile.txt");
CollectionRequest collection = JsonConvert.DeserializeObject<CollectionRequest>(objStr);

var fooColums = new FooColumns {
IEnumerableColumns = new List<Column>()
};
foreach (var item in collection.Columns)
{
fooColums.IEnumerableColumns.Add(item);
}

var contentResult = GetResolvedContentResult(collection);
Assert.True(true);
}

[Fact]
public void XmlSerializationTest()
{
Expand Down
3 changes: 3 additions & 0 deletions test/NetCoreStack.Proxy.Tests/NetCoreStack.Proxy.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ObjFile.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions test/NetCoreStack.Proxy.Tests/ObjFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Metadata":"NetCoreStack.Domain.Contracts.AlbumKnockoutValidatorViewModel","Draw":1,"Length":10,"Start":0,"Text":null,"Search":null,"Filters":null,"Order":null,"Columns":[{"Data":"id","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"genreId","Meta":"Int64?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"artist","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"title","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"title","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"title","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"title","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"title","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"title","Meta":"String?","Composer":"","Searchable":true,"Orderable":true,"Search":null},{"Data":"price","Meta":"Decimal?","Composer":"","Searchable":true,"Orderable":true,"Search":null},null]}
Binary file modified test/NetCoreStack.Proxy.Tests/httplive.db
Binary file not shown.

0 comments on commit 60dfe9a

Please sign in to comment.