Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 6afb301

Browse files
committed
Add test for serializing dapper dynamic results to JSON and CSV
1 parent a179178 commit 6afb301

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
using ServiceStack.Common.Tests.Models;
4+
using ServiceStack.OrmLite.Dapper;
5+
using ServiceStack.Text;
6+
7+
namespace ServiceStack.OrmLite.Tests.Issues
8+
{
9+
[TestFixture]
10+
public class CsvTests : OrmLiteTestBase
11+
{
12+
[Test]
13+
public void Can_serialize_Dapper_results_to_CSV()
14+
{
15+
using (var db = OpenDbConnection())
16+
{
17+
db.DropAndCreateTable<Poco>();
18+
19+
db.Insert(new Poco { Id = 1, Name = "Foo" });
20+
db.Insert(new Poco { Id = 2, Name = "Bar" });
21+
22+
var results = db.Query("select * from Poco");
23+
24+
var json = JsonSerializer.SerializeToString(results);
25+
Assert.That(json, Is.EqualTo("[{\"Id\":1,\"Name\":\"Foo\"},{\"Id\":2,\"Name\":\"Bar\"}]"));
26+
27+
var csv = CsvSerializer.SerializeToCsv(results);
28+
Assert.That(csv.NormalizeNewLines(), Is.EqualTo("Id,Name\n1,Foo\n2,Bar\n"));
29+
}
30+
}
31+
}
32+
}

tests/ServiceStack.OrmLite.Tests/ServiceStack.OrmLite.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
<Compile Include="Issues\ComplexJoinWithAlias.cs" />
139139
<Compile Include="Issues\CompositeIndexNamingStrategyIssue.cs" />
140140
<Compile Include="Issues\CreateTableAliasTest.cs" />
141+
<Compile Include="Issues\CsvTests.cs" />
141142
<Compile Include="Issues\CustomFieldTests.cs" />
142143
<Compile Include="Issues\LoadReferencesCaseSensitiveTest.cs" />
143144
<Compile Include="Issues\LoadSelectIssue.cs" />

tests/ServiceStack.OrmLite.Tests/Shared/Poco.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
public class Poco
44
{
5+
public int Id { get; set; }
56
public string Name { get; set; }
67
}
78
}

0 commit comments

Comments
 (0)