-
Notifications
You must be signed in to change notification settings - Fork 370
/
HistorySerializationTests.cs
80 lines (65 loc) · 2.87 KB
/
HistorySerializationTests.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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Text.Json;
using FluentAssertions;
using Microsoft.DotNet.Interactive.Jupyter.Protocol;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
namespace Microsoft.DotNet.Interactive.Jupyter.Tests
{
public class HistorySerializationTests
{
[Fact]
public void Can_serialize_history_reply()
{
var historyReply = new HistoryReply(new HistoryElement[]
{
new InputHistoryElement(0, 0, "input value"),
new InputHistoryElement(1, 0, "input value"),
new InputOutputHistoryElement(2, 0, "input value", "output result")
});
var serialized = JsonSerializer.Serialize(historyReply);
serialized.Should().Be(@"{""history"":[[0,0,""input value""],[1,0,""input value""],[2,0,[""input value"",""output result""]]]}");
}
[Fact]
public void Can_serialize_empty_history_reply()
{
var historyReply = new HistoryReply(new HistoryElement[]{});
var serialized = JsonSerializer.Serialize(historyReply);
serialized.Should().Be(@"{""history"":[]}");
}
[Fact]
public void Can_serialize_null_history_reply()
{
var historyReply = new HistoryReply();
var serialized = JsonSerializer.Serialize(historyReply);
serialized.Should().Be(@"{""history"":[]}");
}
[Fact]
public void Can_deserialize_history_reply()
{
var serialized = @"{""history"":[[0,0,""input value""],[1,0,""input value""],[2,0,[""input value"",""output result""]]]}";
var historyReply = JsonSerializer.Deserialize<HistoryReply>(serialized);
historyReply.Should().BeEquivalentToRespectingRuntimeTypes(new HistoryReply(new HistoryElement[]
{
new InputHistoryElement(0, 0, "input value"),
new InputHistoryElement(1, 0, "input value"),
new InputOutputHistoryElement(2, 0, "input value", "output result")
}));
}
[Fact]
public void Can_deserialize_empty_history_reply()
{
var serialized = @"{""history"":[]}";
var historyReply = JsonSerializer.Deserialize<HistoryReply>(serialized);
historyReply.Should().BeEquivalentToRespectingRuntimeTypes(new HistoryReply(new HistoryElement[]{}));
}
[Fact]
public void Can_deserialize_null_history_reply()
{
var serialized = @"{""history"":null}";
var historyReply = JsonSerializer.Deserialize<HistoryReply>(serialized);
historyReply.Should().BeEquivalentToRespectingRuntimeTypes(new HistoryReply());
}
}
}