-
-
Notifications
You must be signed in to change notification settings - Fork 519
/
NewRequiredProperty.cs
54 lines (45 loc) · 1.52 KB
/
NewRequiredProperty.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
using System.Text.Json;
using FluentAssertions;
using V1 = ECommerce.V1;
namespace EventsVersioning.Tests.SimpleMappings;
public class NewRequiredProperty
{
public enum ShoppingCartStatus
{
Pending = 1,
Opened = 2,
Confirmed = 3,
Cancelled = 4
}
public record ShoppingCartOpened(
Guid ShoppingCartId,
Guid ClientId,
// Adding new not required property as nullable
ShoppingCartStatus Status = ShoppingCartStatus.Opened
);
[Fact]
public void Should_BeForwardCompatible()
{
// Given
var oldEvent = new V1.ShoppingCartOpened(Guid.NewGuid(), Guid.NewGuid());
var json = JsonSerializer.Serialize(oldEvent);
// When
var @event = JsonSerializer.Deserialize<ShoppingCartOpened>(json);
@event.Should().NotBeNull();
@event!.ShoppingCartId.Should().Be(oldEvent.ShoppingCartId);
@event.ClientId.Should().Be(oldEvent.ClientId);
@event.Status.Should().Be(ShoppingCartStatus.Opened);
}
[Fact]
public void Should_BeBackwardCompatible()
{
// Given
var @event = new ShoppingCartOpened(Guid.NewGuid(), Guid.NewGuid(), ShoppingCartStatus.Pending);
var json = JsonSerializer.Serialize(@event);
// When
var oldEvent = JsonSerializer.Deserialize<V1.ShoppingCartOpened>(json);
oldEvent.Should().NotBeNull();
oldEvent!.ShoppingCartId.Should().Be(@event.ShoppingCartId);
oldEvent.ClientId.Should().Be(@event.ClientId);
}
}