-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathContractEvolutionTests.cs
More file actions
49 lines (42 loc) · 1.59 KB
/
ContractEvolutionTests.cs
File metadata and controls
49 lines (42 loc) · 1.59 KB
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
using System.Text.Json;
using System.Text.Json.Protobuf.Tests;
using Protobuf.System.Text.Json.Tests.Utils;
using Xunit;
namespace Protobuf.System.Text.Json.Tests;
public class ContractEvolutionTests
{
[Fact]
public void Should_deserialize_a_new_version_of_a_message_using_the_old_version_of_the_contract()
{
// Arrange
var msg = new MessageWithVersionMismatchV2
{
DoubleProperty = 1d,
FloatProperty = 2f,
RepeatedInt32Property = {1, 2, 3}
};
var jsonSerializerOptions = TestHelper.CreateJsonSerializerOptions();
// Act
var payload = JsonSerializer.Serialize(msg, jsonSerializerOptions);
var deserialized = JsonSerializer.Deserialize<MessageWithVersionMismatch>(payload, jsonSerializerOptions);
// Assert
Assert.NotNull(deserialized);
Assert.Equal(msg.DoubleProperty, deserialized.DoubleProperty);
}
[Fact]
public void Should_deserialize_the_old_version_of_a_message_using_the_new_version_of_the_contract()
{
// Arrange
var msg = new MessageWithVersionMismatch
{
DoubleProperty = 1d,
};
var jsonSerializerOptions = TestHelper.CreateJsonSerializerOptions();
// Act
var payload = JsonSerializer.Serialize(msg, jsonSerializerOptions);
var deserialized = JsonSerializer.Deserialize<MessageWithVersionMismatchV2>(payload, jsonSerializerOptions);
// Assert
Assert.NotNull(deserialized);
Assert.Equal(msg.DoubleProperty, deserialized.DoubleProperty);
}
}