|
20 | 20 | // SOFTWARE.
|
21 | 21 |
|
22 | 22 | using System;
|
| 23 | +using System.CodeDom.Compiler; |
23 | 24 | using System.Collections;
|
24 | 25 | using System.Collections.Concurrent;
|
25 | 26 | using System.Collections.Generic;
|
@@ -329,6 +330,35 @@ public void SerializeWithCRNewLine()
|
329 | 330 | result.Should().Be(expectedResult);
|
330 | 331 | }
|
331 | 332 |
|
| 333 | + |
| 334 | + /// <summary> |
| 335 | + /// Tests the serialization of a dictionary containing a list of strings using IndentedTextWriter. |
| 336 | + /// </summary> |
| 337 | + [Fact] |
| 338 | + public void SerializeWithTabs() |
| 339 | + { |
| 340 | + var tabString = " "; |
| 341 | + using var writer = new StringWriter(); |
| 342 | + using var indentedTextWriter = new IndentedTextWriter(writer, tabString) { Indent = 2 }; |
| 343 | + |
| 344 | + //create a dictionary with a list of strings to test the tabbed serialization |
| 345 | + var items = new List<string> { "item 1", "item 2" }; |
| 346 | + var list = new Dictionary<string, List<string>> { { "key", items } }; |
| 347 | + |
| 348 | + SerializerBuilder |
| 349 | + .Build() |
| 350 | + .Serialize(indentedTextWriter, list); |
| 351 | + |
| 352 | + //split serialized output into lines |
| 353 | + var lines = indentedTextWriter.InnerWriter.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None); |
| 354 | + |
| 355 | + //expected indentation |
| 356 | + var indent = string.Join(string.Empty, Enumerable.Repeat(tabString, indentedTextWriter.Indent).ToList()); |
| 357 | + |
| 358 | + //check that the serialized lines (excluding the first and last) start with the expected indentation |
| 359 | + lines.Skip(1).Take(lines.Length - 2).Where(element => element.StartsWith(indent)).Should().HaveCount(items.Count); |
| 360 | + } |
| 361 | + |
332 | 362 | [Fact]
|
333 | 363 | public void DeserializeExplicitType()
|
334 | 364 | {
|
|
0 commit comments