This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 632
/
JsvFormatterTests.cs
84 lines (75 loc) · 1.95 KB
/
JsvFormatterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using NUnit.Framework;
using ServiceStack.Common.Tests.Models;
namespace ServiceStack.Text.Tests.Utils
{
[TestFixture]
public class JsvFormatterTests
{
[Test]
public void Can_PrettyFormat_generic_type()
{
var model = new ModelWithIdAndName { Id = 1, Name = "Name" };
var modelStr = model.Dump();
Assert.That(modelStr,
Is.EqualTo(
"{"
+ Environment.NewLine
+ "\tId: 1,"
+ Environment.NewLine
+ "\tName: Name"
+ Environment.NewLine
+ "}"
));
}
[Test]
public void Can_PrettyFormat_object()
{
object model = new ModelWithIdAndName { Id = 1, Name = "Name" };
var modelStr = model.Dump();
Console.WriteLine(modelStr);
Assert.That(modelStr,
Is.EqualTo(
"{"
+ Environment.NewLine
+ "\tId: 1,"
+ Environment.NewLine
+"\tName: Name"
+ Environment.NewLine
+ "}"
));
}
internal class TestModel
{
public TestModel()
{
this.Int = 1;
this.String = "One";
this.DateTime = DateTime.UtcNow.Date;
this.Guid = Guid.NewGuid();
this.EmptyIntList = new List<int>();
this.IntList = new List<int> { 1, 2, 3 };
this.StringList = new List<string> { "one", "two", "three" };
this.StringIntMap = new Dictionary<string, int>
{
{"a", 1},{"b", 2},{"c", 3},
};
}
public int Int { get; set; }
public string String { get; set; }
public DateTime DateTime { get; set; }
public Guid Guid { get; set; }
public List<int> EmptyIntList { get; set; }
public List<int> IntList { get; set; }
public List<string> StringList { get; set; }
public Dictionary<string, int> StringIntMap { get; set; }
}
[Test]
public void Can_DumpModel()
{
var model = new TestModel();
Console.WriteLine(model.Dump());
}
}
}