예제 #1
0
		public void Publishes()
		{
			var repository = new InMemoryRecordMapper<FakePublicationRecord>();
			var blobStorage = new InMemoryBlobStorage();
			var serializer = new JsonMessageSerializer();
			var transport = new InMemoryMessageChannel();
			var registry = new PublicationRegistry<FakePublicationRecord, FakePublicationRecord>(
				repository, blobStorage, serializer);

			var publisher = new DefaultPublisher(registry, transport);

			var start = DateTime.Now;
			var createdBy = new Guid("C60696AF-F2F8-44EB-B9A1-7967693AC466");
			var identifier = new Guid("EF994892-F442-4681-AD1C-217BB11A6D38");
			var message = new FakeMessage { Created = start, CreatedBy = createdBy, Identifier = identifier };

			var recordId = publisher.PublishMessage(message);
			Assert.NotNull(recordId);
			Assert.AreNotEqual(Guid.Empty, recordId);

			var record = registry.GetPublicationRecord(recordId);
			Assert.NotNull(record);
			Assert.AreEqual(typeof(FakeMessage), record.MessageType);

			var retrieved = registry.GetMessage(record.MessageLocation, record.MessageType);
			Assert.NotNull(retrieved);
			Assert.AreEqual(message.Identifier, retrieved.Identifier);
			Assert.AreEqual(message.Created.ToString(), retrieved.Created.ToString());
			Assert.AreEqual(message.Identifier, retrieved.Identifier);
		}
예제 #2
0
		public void Setup()
		{
			var container = new WindsorContainer();
			var processor = new FakeMessageProcessor();
			container.Register(Component.For<FakeMessageProcessor>().Instance(processor));

			container.Register(
				Component.For<IPublicationRegistry<IPublicationRecord, IPublicationRecord>>().ImplementedBy<FakeRegistry>());
			container.Register(
				Component.For<IRecordMapper<FakePublicationRecord>>().ImplementedBy<InMemoryRecordMapper<FakePublicationRecord>>());
			container.Register(Component.For<IBlobStorage>().ImplementedBy<InMemoryBlobStorage>());
			container.Register(Component.For<IMessageSerializer>().ImplementedBy<JsonMessageSerializer>());

			container.Register(Component.For<FakeMessageProcessor2>().Instance(new FakeMessageProcessor2()));
			container.Register(Component.For<FakeMultipleMessageProcessor>().Instance(new FakeMultipleMessageProcessor()));

			_registry = new FakeRegistry(
				new InMemoryRecordMapper<FakePublicationRecord>(), new InMemoryBlobStorage(), new JsonMessageSerializer());

			var locator = new WindsorServiceLocator(container);

			_dispatcher = new MultitaskingMessageDispatcher<IPublicationRegistry<IPublicationRecord, IPublicationRecord>>(
				locator, _registry);

			_transport = new InMemoryMessageChannel();
		}