static object PassThroughEventStorage(object @event, ITypeNameMapper mapper) { var options = TypeSerializersOptions.Default; options.SymmetricCipher = new AesGcmSymmetricCipher(new byte[] { 0, 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 }); var manager = new EventStoreManager(options); var storage = new MemoryEventFileStorage(); var appender = manager.AppendToStore(storage); var events = new[] { @event }; appender.Store(null, events); manager = new EventStoreManager(options); manager.SetNewTypeNameMapper(mapper); var eventObserver = new EventStoreTest.StoringEventObserver(); manager.OpenReadOnlyStore(storage).ReadFromStartToEnd(eventObserver); return(eventObserver.Events[0][0]); }
public void CustomEventIsReadFromSecondSplit() { var manager = new EventStoreManager(); manager.CompressionStrategy = new NoCompressionStrategy(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var appender = manager.AppendToStore(new MemoryEventFileStorage(4096, 4096)); var first = appender.CurrentFileStorage; var user = new User { Name = "A", Age = 1 }; while (appender.CurrentFileStorage == first) { appender.Store(null, new object[] { user }); } var second = appender.CurrentFileStorage; manager = new EventStoreManager(); manager.CompressionStrategy = new NoCompressionStrategy(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var reader = manager.OpenReadOnlyStore(second); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { user } }, eventObserver.Events); }
public void SkipListOnUpgrade() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEventList), "UserEvent")); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var userA = new User { Name = "A", Age = 1 }; var userB = new User { Name = "B", Age = 2 }; var userEvent = new UserEventList { Id = 10, List = new List <User> { userA, userB, userA } }; appender.Store(null, new object[] { userEvent }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEvent), "UserEvent")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEvent)eventObserver.Events[0][0]; Assert.Equal(10, readUserEvent.Id); Assert.Null(readUserEvent.User1); }
public void UpgradeToLessObjectProperties() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEvent), "UserEvent")); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var user = new User { Name = "A", Age = 1 }; var userEvent = new UserEvent { Id = 10, User1 = user, User2 = user }; appender.Store(null, new object[] { userEvent, new User { Name = "B" } }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEventLess), "UserEvent")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEventLess)eventObserver.Events[0][0]; Assert.Equal("A", readUserEvent.User2.Name); Assert.Equal(10, readUserEvent.Id); Assert.Equal("B", ((User)eventObserver.Events[0][1]).Name); }
public void TypeMapperCanForceSkipEvents() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new FullNameTypeMapper()); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var user = new User { Name = "ABC", Age = 88 }; var userEvent = new UserEvent { Id = 10, User1 = user, User2 = user }; var userEventMore = new UserEventMore { Id = 11, User1 = user, User2 = user }; appender.Store(null, new object[] { userEvent, userEventMore }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new SelectiveTypeMapper("BTDBTest.EventStoreTest+UserEvent")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new SimpleEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Single(eventObserver.Events[0]); var readUserEvent = (UserEventMore)eventObserver.Events[0][0]; Assert.Same(readUserEvent.User1, readUserEvent.User2); }
public void SurvivesListVsIList() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(SomethingWithoutList), "Some")); var file = new MemoryEventFileStorage(); var file2 = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var ev = new SomethingWithList(); appender.Store(null, new object[] { ev }); var ev2 = new SomethingWithNestedIList { B = new Dictionary <ulong, IList <string> > { { 1, new List <string> { "a1" } } } }; appender.Store(null, new object[] { ev2 }); var appender2 = manager.AppendToStore(file); appender2.Store(null, new object[] { ev2 }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(SomethingWithList), "Some")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); reader = manager.OpenReadOnlyStore(file2); reader.ReadFromStartToEnd(eventObserver); }
static object PassThroughEventStorage(object @event, ITypeNameMapper mapper) { var manager = new EventStoreManager(); var storage = new MemoryEventFileStorage(); var appender = manager.AppendToStore(storage); var events = new[] { @event }; appender.Store(null, events); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(mapper); var eventObserver = new EventStoreTest.StoringEventObserver(); manager.OpenReadOnlyStore(storage).ReadFromStartToEnd(eventObserver); return(eventObserver.Events[0][0]); }
public void Read() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(ClassWithChangedUINTtoULONG), "BTDBTest.EventStoreTest+Credit")); using (var file = new StreamEventFileStorage(new MemoryStream(Convert.FromBase64String(base64EventFile)))) { var appender = manager.AppendToStore(file); var observer = new StoringEventObserver(); appender.ReadFromStartToEnd(observer); Assert.Equal(observer.Events.Count, 1); Assert.Equal(observer.Events[0].Length, 1); var e = observer.Events[0][0] as Ev1; Assert.Equal(e.Credit.A, 1u); Assert.Equal(e.Credit.B, 2u); } }
public void CanWriteSimpleEventAndReadItIndependently() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var user = new User { Name = "A", Age = 1 }; appender.Store(null, new object[] { user }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { user } }, eventObserver.Events); }
public void UpgradeToDifferentEnumProperties() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(ApplicationInfo), "ApplicationInfo")); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var applicationInfo = new ApplicationInfo { Type = ApplicationsType.First }; appender.Store(null, new object[] { applicationInfo }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(ApplicationInfoPropertyEnumTypeChanged), "ApplicationInfo")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readApplicationInfo = (ApplicationInfoPropertyEnumTypeChanged)eventObserver.Events[0][0]; Assert.Equal(readApplicationInfo.Type, ApplicationsRenamedType.First); }