Skip to content

Commit 2c8792a

Browse files
committed
changes PagedResult.Items from IList to List for xml serialization to work.
1 parent 3d128f0 commit 2c8792a

8 files changed

+68
-5
lines changed

PagedResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public PagedResult()
3636
/// <summary>
3737
/// Collection containing items in the current page.
3838
/// </summary>
39-
public IList<T> Items { get; set; }
39+
public List<T> Items { get; set; }
4040

4141
/// <summary>
4242
/// Calculates &amp; returns the hashcode of the current object.

tests/AsynchronousTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace tests
88
{
99
[TestFixture]
10+
[SingleThreaded]
1011
internal class AsynchronousTests : TestBaseContext
1112
{
1213
[SetUp]

tests/SynchronousTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace tests
66
{
77
[TestFixture]
8+
//[SingleThreaded]
89
internal class SynchronousTests : TestBaseContext
910
{
1011
[SetUp]
@@ -56,6 +57,7 @@ public void Pg_Skip_Count()
5657
Log(paged);
5758
}
5859
[Order(2)]
60+
[RequiresThread]
5961
[TestCase(Category = SYNC_TESTS)]
6062
public void Pg_With_Items()
6163
{

tests/TestBase.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ internal class TestBase
66
{
77
internal const string SYNC_TESTS = "Synchronous";
88
internal const string ASYNC_TESTS = "Asynchronous";
9+
internal const string SERIAL_TESTS = "Serialization";
910

1011
internal void Log(object obj)
1112
=> Console.WriteLine(obj);

tests/TestBaseContext.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
2+
using NUnit.Framework;
23

34
namespace tests
45
{
@@ -9,7 +10,7 @@ internal class TestBaseContext : TestBase
910

1011
public TestBaseContext()
1112
{ }
12-
13+
1314
protected TestDbContext Context
1415
{
1516
get

tests/TestDbContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public TestDbContext(DbContextOptions<TestDbContext> options)
1010

1111
public DbSet<Car> Cars { get; set; }
1212
}
13-
internal class Car
13+
public class Car
1414
{
1515
public int Id { get; set; }
1616
}

tests/UnitTests.cs

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
1+
using System.IO;
2+
using System.Xml;
3+
using System.Xml.Serialization;
4+
using Common;
5+
using NUnit.Framework;
6+
using Paginator.EntityFrameworkCore;
7+
18
namespace tests
29
{
10+
[TestFixture]
311
internal class UnitTests : TestBaseContext
412
{
5-
13+
[SetUp]
14+
public void Setup()
15+
{
16+
InitContx();
17+
}
18+
19+
[TestCase(Category = SERIAL_TESTS)]
20+
public void ToJson()
21+
{
22+
Add(new Car());
23+
Add(new Car());
24+
Add(new Car());
25+
Add(new Car());
26+
27+
var paged = Context.Cars.Paginate(1, 2, true);
28+
29+
string json = paged.ToJson();
30+
31+
Assert.IsNotEmpty(json);
32+
Assert.That(json.IsValidJson());
33+
34+
System.Console.WriteLine(json);
35+
}
36+
37+
[TestCase(Category = SERIAL_TESTS)]
38+
public void ToXml()
39+
{
40+
Add(new Car());
41+
Add(new Car());
42+
Add(new Car());
43+
Add(new Car());
44+
45+
var paged = Context.Cars.Paginate(1, 2, true);
46+
47+
XmlSerializer xsSubmit = new XmlSerializer(paged.GetType());
48+
var xml = "";
49+
50+
using (var sww = new StringWriter())
51+
{
52+
using (XmlWriter writer = XmlWriter.Create(sww))
53+
{
54+
xsSubmit.Serialize(writer, paged);
55+
xml = sww.ToString(); // Your XML
56+
}
57+
}
58+
59+
Assert.IsNotEmpty(xml);
60+
61+
System.Console.WriteLine(xml);
62+
}
663
}
764
}

tests/tests.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<ItemGroup>
1010
<PackageReference Include="Moq" Version="4.16.1" />
1111
<PackageReference Include="NUnit" Version="3.13.2" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
1414
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.15" />
15+
<PackageReference Include="Shared.Common" Version="1.3.6" />
1516
</ItemGroup>
1617

1718
<ItemGroup>

0 commit comments

Comments
 (0)