public DomainEventsJsonAkkaSerializer(ExtendedActorSystem system) : base(system) { Serializer = new Lazy <WireJsonSerializer>(() => { var ext = system.GetExtension <DomainEventsJsonSerializationExtension>(); if (ext == null) { throw new ArgumentNullException(nameof(ext), $"Cannot get {typeof(DomainEventsJsonSerializationExtension).Name} extension"); } if (ext.Settings != null) { return(new WireJsonSerializer(ext.Settings)); } var settings = DomainSerializer.GetDefaultSettings(); foreach (var c in ext.Converters) { settings.Converters.Add(c); } return(new WireJsonSerializer(settings)); }); }
public void Test() { var state = new SoftwareProgrammingState(Guid.NewGuid().ToString(), "123", Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); var processStateAggregate = new ProcessStateAggregate <SoftwareProgrammingState>(state); processStateAggregate.ReceiveMessage(state, Guid.NewGuid().ToString()); processStateAggregate.ClearUncommitedEvents(); var jsonSerializerSettings = DomainSerializer.GetDefaultSettings(); jsonSerializerSettings.TraceWriter = new XUnitTraceWriter(_testOutputHelper); var json = JsonConvert.SerializeObject(processStateAggregate, jsonSerializerSettings); var restoredState = JsonConvert.DeserializeObject <ProcessStateAggregate <SoftwareProgrammingState> >(json, jsonSerializerSettings); restoredState.ClearUncommitedEvents(); //CoffeMachineId_should_be_equal() Assert.Equal(processStateAggregate.State.CoffeeMachineId, restoredState.State.CoffeeMachineId); // Id_should_be_equal() Assert.Equal(processStateAggregate.Id, restoredState.Id); //State_should_be_equal() Assert.Equal(processStateAggregate.State.CurrentStateName, restoredState.State.CurrentStateName); }
public void Test() { _aggregate = new SampleAggregate(Guid.NewGuid(), "test"); _aggregate.ChangeState(10); _aggregate.ClearEvents(); var jsonString = JsonConvert.SerializeObject(_aggregate, DomainSerializer.GetDefaultSettings()); _restoredAggregate = JsonConvert.DeserializeObject <SampleAggregate>(jsonString, DomainSerializer.GetDefaultSettings()); }
public void Collections_should_be_deserialized() { var initialEvent = new Event(new[] { new Payload(new[] { new SubObject_V1("10", "123") }) }); var settings = DomainSerializer.GetDefaultSettings(); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsAssignableFrom <SubObject_V1>(restoredEvent.PayloadProp?.FirstOrDefault()?.Property?.FirstOrDefault()); }
public void Objects_with_custom_constructor_are_deserialized() { var initialEvent = new Event(new Payload(new SubObject_V1("10", "123"))); var settings = DomainSerializer.GetDefaultSettings(); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsAssignableFrom <SubObject_V1>(restoredEvent?.Payload?.Property); }
public void All_occurance_should_be_upgraded() { var initialEvent = new Event(new Payload(new SubObject_V1("10", "123"))); var settings = DomainSerializer.GetDefaultSettings(); settings.Converters.Add(new SubObjectConverter()); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsAssignableFrom <SubObject_V2>(restoredEvent.Payload.Property); }
public void All_occurance_should_be_upgraded_with_implicit_collection_set() { //Should get an exception due to different serialized value var initialEvent = new Event(new[] { new Payload(new [] { new SubObject_V1("10", "123") }) }); var settings = DomainSerializer.GetDefaultSettings(); settings.Converters.Add(new SubObjectConverter()); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); Console.WriteLine(serializedValue); Assert.Throws <ArgumentException>(() => JsonConvert.DeserializeObject <Event>(serializedValue, settings)); }
public void All_occurance_should_be_upgraded() { var initialEvent = new Event(new [] { new Payload(new ISubObject[] { new SubObject_V1("10", "123") }) }); var settings = DomainSerializer.GetDefaultSettings(); settings.Converters.Add(new SubObjectConverter()); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); Console.WriteLine(serializedValue); var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsInstanceOf <SubObject_V2>(restoredEvent.Payload?.FirstOrDefault()?.Property?.FirstOrDefault()); }
public void Propert_is_upgraded() { var initialEvent = new Event { Payload = new SubObject_V1 { Name = "10", Value = "123" } }; var settings = DomainSerializer.GetDefaultSettings(); settings.Converters.Add(new SubObjectConverter()); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsAssignableFrom <SubObject_V2>(restoredEvent.Payload); }
public void Test() { _aggregate = new Balloon(Guid.NewGuid().ToString(), "test"); _aggregate.WriteNewTitle(10); _aggregate.ClearUncommitedEvents(); var jsonSerializerSettings = DomainSerializer.GetDefaultSettings(); jsonSerializerSettings.TraceWriter = new XUnitTraceWriter(_testOutputHelper); var jsonString = JsonConvert.SerializeObject(_aggregate, jsonSerializerSettings); _restoredAggregate = JsonConvert.DeserializeObject <Balloon>(jsonString, jsonSerializerSettings); _restoredAggregate.ClearUncommitedEvents(); // Values_should_be_equal() Assert.Equal(_aggregate.Title, _restoredAggregate.Title); //Ids_should_be_equal() Assert.Equal(_aggregate.Id, _restoredAggregate.Id); }
public void Property_upgraded_from_serialized_value() { var settings = DomainSerializer.GetDefaultSettings(); settings.Converters.Add(new SubObjectConverter()); var serializedValue = @"{ ""$id"": ""1"", ""Payload"": { ""$id"": ""2"", ""$type"": """ + typeof(SubObject_V1).AssemblyQualifiedName + @""", ""Name"": ""10"", ""Value"": ""123"" } }"; var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsInstanceOf <SubObject_V2>(restoredEvent.Payload); }
public void All_old_objects_should_be_updated() { var initialEvent = new Event() { Payload = new Payload() { Property = new SubObject_V1() { Name = "10", Value = "123" } } }; var settings = DomainSerializer.GetDefaultSettings(); settings.Converters.Add(new SubObjectConverter()); var serializedValue = JsonConvert.SerializeObject(initialEvent, settings); var restoredEvent = JsonConvert.DeserializeObject <Event>(serializedValue, settings); Assert.IsInstanceOf <SubObject_V2>(restoredEvent.Payload.Property); }