public void when_write_and_read_envelope() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var streamer = new EnvelopeStreamer(serializer); var date = DateTime.UtcNow; var savedBytes = streamer.SaveEnvelopeData(new ImmutableEnvelope("EnvId", date, new SerializerTest1 { Name = "Test1" }, new[] { new MessageAttribute("key1", "val1"), new MessageAttribute("key2", "val2"), })); var envelope = streamer.ReadAsEnvelopeData(savedBytes); Assert.AreEqual("EnvId", envelope.EnvelopeId); Assert.AreEqual(date, envelope.CreatedUtc); Assert.AreEqual(2, envelope.Attributes.Count); Assert.AreEqual("key1", envelope.Attributes.ToArray()[0].Key); Assert.AreEqual("val1", envelope.Attributes.ToArray()[0].Value); Assert.AreEqual("key2", envelope.Attributes.ToArray()[1].Key); Assert.AreEqual("val2", envelope.Attributes.ToArray()[1].Value); Assert.AreEqual(typeof(SerializerTest1), envelope.Message.GetType()); Assert.AreEqual("Test1", (envelope.Message as SerializerTest1).Name); }
public void when_send_message() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var streamer = new EnvelopeStreamer(serializer); var queueWriter = new FileQueueWriter(new DirectoryInfo(_path), "test"); var sender = new MessageSender(streamer, queueWriter); sender.Send(new SerializerTest1("Name1"), "EnvId", new[] { new MessageAttribute("key1", "val1"), new MessageAttribute("key2", "val2"), }); sender.Send(new SerializerTest1("Name1"), "EnvId"); Assert.AreEqual(2, Directory.GetFiles(_path).Length); }
public void Test() { // this test will start a simple web server on port 8082 (with a CQRS engine) // You might need to reserve that port or run test as admin. Check out unit test // output for the exact command line on port reservation (or MSDN docs) // // netsh http add urlacl url=http://+:8082/ user=RINAT-R5\Rinat.Abdullin // after starting the test, navigate you browser to localhost:8082/index.htm // and try dragging the image around // in-memory structure to capture mouse movement // statistics var stats = new MouseStats(); // we accept a message just of this type, using a serializer var messages = new[] { typeof(MouseMoved), typeof(MouseClick) }; var serializer = new MyJsonSerializer(messages); var streamer = new EnvelopeStreamer(serializer); var store = new MemoryAccount(); var atomic = store.CreateNuclear().Factory; // let's configure our custom Http server to // 1. serve resources // 2. serve MouseStats View // 3. accept commands var environment = new HttpEnvironment { Port = 8082 }; var builder = new CqrsEngineBuilder(streamer); builder.AddProcess(new Listener(environment, new EmbeddedResourceHttpRequestHandler(typeof(MouseMoved).Assembly, "Snippets.HttpEndpoint"), new MouseStatsRequestHandler(stats), new HeatMapRequestHandler(atomic.GetEntityReader<unit, HeatMapView>()), new MouseEventsRequestHandler(store.CreateQueueWriter("inbox"), serializer, streamer))); builder.Handle(store.CreateInbox("inbox"), envelope => { if (envelope.Items.Any(i => i.Content is MouseMoved)) { MouseStatHandler(envelope, stats); } else if (envelope.Items.Any(i => i.Content is MouseClick)) { MouseClickHandler(envelope, atomic.GetEntityWriter<unit, PointsView>()); } }); builder.AddProcess(new HeatMapGenerateTask(atomic.GetEntityReader<unit, PointsView>(), atomic.GetEntityWriter<unit, HeatMapView>())); Process.Start("http://localhost:8082/index.htm"); // this is a test, so let's block everything builder.Build().RunForever(); }
public void SetUp() { _storeRecords = new List<StoreRecord>(); _serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), typeof(string) }); _path = Path.Combine(Path.GetTempPath(), "MessageStorePublisher", Guid.NewGuid().ToString()); _appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(_path)); _appendOnlyStore.Initialize(); _store = new MessageStore(_appendOnlyStore, _serializer); var streamer = new EnvelopeStreamer(_serializer); var queueWriter = new TestQueueWriter(); _sender = new MessageSender(streamer, queueWriter); var store = new FileDocumentStore(Path.Combine(_path, "lokad-cqrs-test"), new DocumentStrategy()); _nuclearStorage = new NuclearStorage(store); _publisher = new MessageStorePublisher(_store, _sender, _nuclearStorage, DoWePublishThisRecord); }
public void create_MessageSender() { var path = Path.Combine(Path.GetTempPath(), "lokad-cqrs-test", Guid.NewGuid().ToString()); var config = FileStorage.CreateConfig(new DirectoryInfo(path)); var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2) }); var streamer = new EnvelopeStreamer(serializer); var sender = config.CreateMessageSender(streamer, "QueueName"); Assert.IsNotNull(sender); }