forked from oskardudycz/EventSourcing.NetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewNotRequiredProperty.cs
47 lines (39 loc) · 1.35 KB
/
NewNotRequiredProperty.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
using System.Text.Json;
using FluentAssertions;
using Xunit;
using V1 = ECommerce.V1;
namespace EventsVersioning.Tests.SimpleMappings;
public class NewNotRequiredProperty
{
public record ShoppingCartOpened(
Guid ShoppingCartId,
Guid ClientId,
// Adding new not required property as nullable
DateTime? IntializedAt
);
[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.IntializedAt.Should().BeNull();
}
[Fact]
public void Should_BeBackwardCompatible()
{
// Given
var @event = new ShoppingCartOpened(Guid.NewGuid(), Guid.NewGuid(), DateTime.UtcNow);
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);
}
}