public void Serializer_can_serialize_and_deserialize_polymorphic_types()
        {
            var withType     = new ExecutionOptions(DateTime.MaxValue, typeof(ScheduledCommandSuccessfullyProcessed), Guid.NewGuid().ToString(), TimeSpan.FromMinutes(1));
            var serializer   = new DomainSerializer();
            var bytes        = serializer.ToBinary(withType);
            var deserialized = (ExecutionOptions)serializer.FromBinary(bytes, typeof(ExecutionOptions));

            Assert.True(deserialized.SuccesEventType == withType.SuccesEventType);
        }
 public async Task <DomainEvent[]> Load(string id)
 {
     return((await _rawDataRepo.Load(id)).Select(d =>
     {
         try
         {
             return _serializer.FromBinary(d.Payload,
                                           Type.GetType(d.Manifest));
         }
         catch (NullReferenceException ex)
         {
             throw new PersistanceFailureException(d, ex);
         }
     }).Cast <DomainEvent>().ToArray());
 }
Example #3
0
        public void Test()
        {
            _original = (SampleDomainEvent) new SampleDomainEvent(1223, Guid.NewGuid().ToString()).CloneForProcess(Guid.NewGuid().ToString());
            var ser   = new DomainSerializer();
            var bytes = ser.ToBinary(_original);

            _restored = (SampleDomainEvent)ser.FromBinary(bytes, typeof(SampleDomainEvent));
            //processId_should_be_equal()
            Assert.Equal(_original.ProcessId, _restored.ProcessId);
            //CreatedTime_should_be_equal()
            Assert.Equal(_original.CreatedTime, _restored.CreatedTime);
            //SourceId_should_be_equal()
            Assert.Equal(_original.SourceId, _restored.SourceId);
            //Parameter_should_be_equal()
            Assert.Equal(_original.Parameter, _restored.Parameter);
        }
        public async Task<Version<T>[]> Load<T>(string id) where T : class, IAggregate
        {
            var snapshotType = _snapshotsConstructor.GetSnapshot(_aggregatesConstructor.BuildEmpty<T>())
                                                    .GetType();

            var serializer = new DomainSerializer();
            
            using (var snapshotItemsRepo = new RawSnapshotsRepository(option))
            {
                return (await snapshotItemsRepo.Load(EntityActorName.New<T>(id).
                                                           Name)).Select(s =>
                                                                         {
                                                                             var memento = (IMemento) serializer.FromBinary(s.Snapshot, snapshotType);
                                                                             var aggregate = (T) _aggregatesConstructor.Build(typeof(T), id, memento);
                                                                             return new Version<T>(aggregate, s.Timestamp);
                                                                         }).
                                                                  ToArray();
            }
        }