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

Commit bd9878b

Browse files
committed
Add CSV test showing deserialization is dependent on headers
1 parent fbe7388 commit bd9878b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/ServiceStack.Text.Tests/CsvSerializerTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
34
using System.IO;
@@ -134,6 +135,39 @@ public void Does_Serialize_back_into_Array()
134135
Assert.That(dto.GetType().IsArray);
135136
}
136137

138+
public class SubMovie
139+
{
140+
public DateTime ReleaseDate { get; set; }
141+
public string Title { get; set; }
142+
public decimal Rating { get; set; }
143+
public string ImdbId { get; set; }
144+
}
145+
146+
[Test]
147+
public void Does_serialize_partial_DTO_in_order_of_Headers()
148+
{
149+
var subMovies = MoviesData.Movies.Map(x => x.ConvertTo<SubMovie>());
150+
var csv = CsvSerializer.SerializeToString(subMovies);
151+
152+
csv.Print();
153+
Assert.That(csv, Is.StringStarting("ReleaseDate,Title,Rating,ImdbId\r\n"));
154+
155+
var movies = csv.FromCsv<List<Movie>>();
156+
157+
Assert.That(movies.Count, Is.EqualTo(subMovies.Count));
158+
for (int i = 0; i < subMovies.Count; i++)
159+
{
160+
var actual = movies[i];
161+
var expected = MoviesData.Movies[i];
162+
163+
Assert.That(actual.Id, Is.EqualTo(0));
164+
Assert.That(actual.ReleaseDate, Is.EqualTo(expected.ReleaseDate));
165+
Assert.That(actual.Title, Is.EqualTo(expected.Title));
166+
Assert.That(actual.Rating, Is.EqualTo(expected.Rating));
167+
Assert.That(actual.ImdbId, Is.EqualTo(expected.ImdbId));
168+
}
169+
}
170+
137171
[Test]
138172
public void Can_Serialize_MovieResponse_Dto()
139173
{

0 commit comments

Comments
 (0)