public void SerializableJson_ObjectToContainerToObject_ExplicitAlgorithm() { Support.MyDataSet original = MakeMyDataSet(); int setCount = original.coll.Count; string password = "******"; string salt = "JustAsEasy"; SymmetricAlgorithm algorithm = new DESCryptoServiceProvider(); string transitContent = ObjectJsonSerializer <Support.MyDataSet> .CreateTransitContainerForObject(original, password, salt, algorithm); Support.MyDataSet result = ObjectJsonSerializer <Support.MyDataSet> .CreateObjectFromTransitContainer(transitContent, password, salt, algorithm); Assert.AreEqual(result.s1, original.s1, "s1 not same"); Assert.AreEqual(result.i16, original.i16, "i16 not same"); Assert.AreEqual(result.i32, original.i32, "i32 not same"); Assert.AreEqual(result.i64, original.i64, "i64 not same"); Assert.AreEqual(result.Timestamp, original.Timestamp, "Timestamp not same"); Assert.AreEqual(result.coll.Count, setCount, "coll.Count not " + setCount.ToString()); Assert.AreEqual(result.coll.Count, original.coll.Count, "coll.Count not same"); for (int index = 0; index < setCount; index++) { Assert.AreEqual(result.coll[index], original.coll[index], "coll[] not same at index " + index.ToString()); } }
public void SaveEventsTest() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee { Id = aggregateRootId }; var event1 = new NameChangedEvent("daxnet"); var event2 = new TitleChangedEvent("title"); var event3 = new RegisteredEvent(); event1.AttachTo(employee); event2.AttachTo(employee); event3.AttachTo(employee); var storeConfig = new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()); var payloadSerializer = new ObjectJsonSerializer(); var store = new PostgreSqlEventStore(storeConfig, payloadSerializer); store.Save(new List <DomainEvent> { event1, event2, event3 }); }
public void SerializableJson_ObjectToContainerToObject_ImplicitAlgorithm() { Support.MyDataSet original = MakeMyDataSet(); int setCount = original.coll.Count; string password = "******"; string salt = "JustAsEasy"; string rawContent = ObjectJsonSerializer <Support.MyDataSet> .CreateDocumentFormat(original); //int rawContentLength = rawContent.Length; string transitContent = ObjectJsonSerializer <Support.MyDataSet> .CreateTransitContainerForObject(original, password, salt); //int transitContentLength = transitContent.Length; Support.MyDataSet result = ObjectJsonSerializer <Support.MyDataSet> .CreateObjectFromTransitContainer(transitContent, password, salt); Assert.AreEqual(result.s1, original.s1, "s1 not same"); Assert.AreEqual(result.i16, original.i16, "i16 not same"); Assert.AreEqual(result.i32, original.i32, "i32 not same"); Assert.AreEqual(result.i64, original.i64, "i64 not same"); Assert.AreEqual(result.Timestamp, original.Timestamp, "Timestamp not same"); Assert.AreEqual(result.coll.Count, setCount, "coll.Count not " + setCount.ToString()); Assert.AreEqual(result.coll.Count, original.coll.Count, "coll.Count not same"); for (int index = 0; index < setCount; index++) { Assert.AreEqual(result.coll[index], original.coll[index], "coll[] not same at index " + index.ToString()); } }
private void btnLoadDocumentJSON_Click(object sender, EventArgs e) { this.lblFileSizeJSON.Text = "Deserializing the JSON file"; AbortRequested = false; ObjectEnabling(false); MassiveReadJSON = ObjectJsonSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .LoadDocumentFormat(this.lblFileNameJSON.Text); this.lblFileSizeJSON.Text = "Comparing deserialized JSON file content against original"; this.lblFileSizeJSON.Refresh(); if (!CompareMassiveJSONs()) { MessageBox.Show("The JSON deserialized object does not match the original."); } MassiveReadJSON = null; this.lblFileSizeJSON.Text = "Deserializing the JSON GZ file"; this.lblFileSizeJSON.Refresh(); MassiveReadJSON = ObjectJsonSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .LoadCompressedDocumentFormat(this.lblFileNameJSON.Text + ".gz"); this.lblFileSizeJSON.Text = "Comparing deserialized JSON GZ file content against original"; this.lblFileSizeJSON.Refresh(); if (!CompareMassiveJSONs()) { MessageBox.Show("The JSON GZ deserialized object does not match the original."); } this.lblFileSizeJSON.Text = "Forcing garbage collection"; this.lblFileSizeJSON.Refresh(); MassiveReadXML = null; this.lblFileSizeJSON.Text = "Idle"; ObjectEnabling(true); }
public void LoadEventsTest() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); var event1 = new NameChangedEvent("daxnet"); var event2 = new TitleChangedEvent("title"); var event3 = new RegisteredEvent(); event1.AttachTo(employee); event2.AttachTo(employee); event3.AttachTo(employee); var storeConfig = new AdoNetEventStoreConfiguration(PostgreSQLFixture.ConnectionString, new GuidKeyGenerator()); var payloadSerializer = new ObjectJsonSerializer(); var store = new PostgreSqlEventStore(storeConfig, payloadSerializer); store.Save(new List <DomainEvent> { event1, event2, event3 }); var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId); Assert.Equal(3, events.Count()); }
private void btnBuild3GbJSON_Click(object sender, EventArgs e) { AbortRequested = false; ObjectEnabling(false); PhraseGenerator pg = new PhraseGenerator(); MassiveXML.Clear(); long TotalSize = 0; int OuterIndex = 0; while (!AbortRequested && TotalSize < 25000000L) { OuterIndex++; this.lblFileSizeJSON.Text = string.Format("{0} bytes and still working", Formatting.KiloToYotta(TotalSize)); this.lblFileSizeJSON.Refresh(); Application.DoEvents(); System.Threading.Thread.Sleep(100); long ThisSize = 0; SerializableDictionary <int, string> Localized = new SerializableDictionary <int, string>(); int InnerIndex = 0; while (!AbortRequested && ThisSize < 10000000L) { foreach (string Phrase in pg.GetPhrase(1000)) { InnerIndex++; Localized.Add(InnerIndex, Phrase); ThisSize += (long)Phrase.Length; } Application.DoEvents(); } MassiveJSON.Add(OuterIndex, Localized); TotalSize += ThisSize; } if (!AbortRequested) { this.lblFileSizeJSON.Text = string.Format("{0} bytes..Saving JSON file", Formatting.KiloToYotta(TotalSize)); this.lblFileSizeJSON.Refresh(); ObjectJsonSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .SaveDocumentFormat(MassiveJSON, this.lblFileNameJSON.Text); this.lblFileSizeJSON.Text = string.Format("{0} bytes..Saving JSON GZ file", Formatting.KiloToYotta(TotalSize)); this.lblFileSizeJSON.Refresh(); ObjectJsonSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .SaveCompressedDocumentFormat(MassiveJSON, this.lblFileNameJSON.Text + ".gz"); string rawSize = Formatting.KiloToYotta((double)new FileInfo(this.lblFileNameJSON.Text).Length); string gzSize = Formatting.KiloToYotta((double)new FileInfo(this.lblFileNameJSON.Text + ".gz").Length); this.lblFileSizeJSON.Text = string.Format("Save Complete: Memory = {0}, JSON = {1}, JSON.GZ = {2}", TotalSize, rawSize, gzSize); //new FileInfo(this.lblFileNameJSON.Text).Length, //new FileInfo(this.lblFileNameJSON.Text + ".gz").Length); this.lblFileSizeJSON.Refresh(); } else { this.lblFileSizeJSON.Text = "Aborted by operator"; } ObjectEnabling(true); }
public void TypedSerializeDeserializeTest() { var customer = Customer.CreateOne(); var ser = new ObjectJsonSerializer(); var bin = ser.Serialize(typeof(Customer), customer); var customer2 = (Customer)ser.Deserialize(bin, typeof(Customer)); Assert.Equal(customer.Id, customer2.Id); Assert.Equal(customer.Name, customer2.Name); Assert.Equal(customer.Email, customer2.Email); Assert.Equal(customer.DateRegistered, customer2.DateRegistered); }
public void NoTypeSerializeDeserializeTest() { Customer customer = Customer.CreateOne(); var ser = new ObjectJsonSerializer(); var bin = ser.Serialize(customer); Customer customer2 = ser.Deserialize <Customer>(bin); Assert.Equal(customer.Id, customer2.Id); Assert.Equal(customer.Name, customer2.Name); Assert.Equal(customer.Email, customer2.Email); Assert.Equal(customer.DateRegistered, customer2.DateRegistered); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Reads the host machine which runs the RabbitMQ. var rabbitHost = this.Configuration["rabbit:host"]; // Reads the RabbitMQ exchange setting. var rabbitExchangeName = this.Configuration["rabbit:exchange"]; // Reads the name of the event queue. var rabbitEventQueueName = this.Configuration["rabbit:eventQueue"]; // Reads the name of the command queue. var rabbitCommandQueueName = this.Configuration["rabbit:commandQueue"]; // Reads connection string of the event store database. var eventStoreConnectionString = this.Configuration["mssql:event.db"]; // Reads connection string of the query database. var queryDatabaseConnectionString = this.Configuration["mssql:query.db"]; // Event/Command subscribers/publishers var connectionFactory = new ConnectionFactory { HostName = rabbitHost }; var messageSerializer = new MessageJsonSerializer(); var messageHandlerExecutionContext = new ServiceProviderMessageHandlerExecutionContext(services, x => x.BuildServiceProvider()); var eventSubscriber = new RabbitEventBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic, rabbitEventQueueName); eventSubscriber.Subscribe <AccountCreatedEvent, AccountCreatedEventHandler>(); eventSubscriber.Subscribe <TextContentChangedEvent, TextContentChangedEventHandler>(); var commandSender = new RabbitCommandBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic); var commandSubscriber = new RabbitCommandBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic, rabbitCommandQueueName); commandSubscriber.Subscribe <PostTextCommand, PostTextCommandHandler>(); services.AddSingleton <IEventSubscriber>(eventSubscriber); services.AddSingleton <ICommandSender>(commandSender); services.AddSingleton <ICommandSubscriber>(commandSubscriber); // Domain Repository var eventStorageConfig = new AdoNetEventStoreConfiguration(eventStoreConnectionString); var objectSerializer = new ObjectJsonSerializer(); services.AddSingleton <ISnapshotProvider, SuppressedSnapshotProvider>(); services.AddTransient <IEventPublisher>(x => new RabbitEventBus(connectionFactory, messageSerializer, messageHandlerExecutionContext, rabbitExchangeName, ExchangeType.Topic)); services.AddTransient <IEventStore>(x => new SqlServerEventStore(eventStorageConfig, objectSerializer)); services.AddTransient <IDomainRepository, EventSourcingDomainRepository>(); // Add framework services. services.AddMvc(); }
public void LoadEventsWithMinMaxSequenceTest() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); var event1 = new NameChangedEvent("daxnet") { Sequence = 1 }; var event2 = new TitleChangedEvent("title") { Sequence = 2 }; var event3 = new RegisteredEvent() { Sequence = 3 }; event1.AttachTo(employee); event2.AttachTo(employee); event3.AttachTo(employee); var storeConfig = new AdoNetEventStoreConfiguration(SQLServerFixture.ConnectionString, new GuidKeyGenerator()); var payloadSerializer = new ObjectJsonSerializer(); var store = new SqlServerEventStore(storeConfig, payloadSerializer); store.Save(new List <DomainEvent> { event1, event2, event3 }); var events = store.Load <Guid>(typeof(Employee).AssemblyQualifiedName, aggregateRootId, 1, 3).ToList(); Assert.Equal(3, events.Count); Assert.IsType <NameChangedEvent>(events[0]); Assert.IsType <TitleChangedEvent>(events[1]); Assert.IsType <RegisteredEvent>(events[2]); }