public void Exceptions_are_made_available_as_messages() { var evt = new ManualResetEvent(false); ExceptionOccurred capturedMessage = null; var bus = BusSetup.StartWith <AsyncConfiguration>().Construct(); bus.Subscribe <MessageB>(msg => { throw new ArgumentException("Bad message"); }); bus.Subscribe <ExceptionOccurred>(x => { capturedMessage = x; evt.Set(); }); bus.Publish(new MessageB()); var signaled = evt.WaitOne(TimeSpan.FromSeconds(2)); if (!signaled) { Assert.Fail("Exception was never captured!"); } capturedMessage.Exception.ShouldBeOfType <AggregateException>(); var xes = ((AggregateException)capturedMessage.Exception).InnerExceptions; xes[0].ShouldBeOfType <ArgumentException>(); xes[0].Message.ShouldBeEqualTo("Bad message"); }
public void Subscription_push_can_be_dispatched_on_designated_thread_blocking_scenario() { var threadId = -2; var threadIdFromTest = -1; IBus bus = null; var resetEvent = new ManualResetEvent(false); var uiThread = new Thread( () => { var sync = Helpers.CreateDispatchContext(); var frame = new DispatcherFrame(); threadId = Thread.CurrentThread.ManagedThreadId; bus = BusSetup.StartWith <RichClientFrontend>().Construct(); bus.Observe <MessageB>().ObserveOn(sync).Subscribe(msg => { threadIdFromTest = Thread.CurrentThread.ManagedThreadId; frame.Continue = false; }); resetEvent.Set(); Dispatcher.PushFrame(frame); }); uiThread.Start(); resetEvent.WaitOne(); bus.Publish(new MessageB()); uiThread.Join(); threadIdFromTest.ShouldBeEqualTo(threadId); }
public MemBusAdapter(IocAdapter iocAdapter) { this.memBus = BusSetup.StartWith <AsyncConfiguration>() .Apply <IoCSupport>(s => s.SetAdapter(iocAdapter).SetHandlerInterface(typeof(IHandle <>))) .Construct(); }
public void A_shape_gets_access_to_services() { var testShaper = new TestShaper("Test"); BusSetup.StartWith <Conservative>(new BusSetupPutShapeOnMsgA(testShaper)).Construct(); testShaper.Services.ShouldNotBeNull(); }
public static void Main(string[] args) { var bus = BusSetup.StartWith <Conservative>() .Apply <FlexibleSubscribeAdapter>(a => { a.ByInterface(typeof(IEventHandler <>)); a.ByInterface(typeof(ICommandHandler <>)); }).Construct(); var someAwesomeUi = new SomeAwesomeUi(bus); using (store = WireupEventStore(bus)) { var repository = new EventStoreRepository(store, new AggregateFactory(), new ConflictDetector()); var handler = new CreateAccountCommandHandler(repository); var handler2 = new CloseAccountCommandHandler(repository); bus.Subscribe(handler); bus.Subscribe(handler2); bus.Subscribe(new KaChingNotifier()); bus.Subscribe(new OmgSadnessNotifier()); someAwesomeUi.CreateNewAccount(AggregateId, "Luiz", "@luizdamim"); someAwesomeUi.CloseAccount(AggregateId); } Console.ReadLine(); }
public IntegrationScenarioInteractionWithSubscriber() { _bus = BusSetup.StartWith <Conservative>() .Apply <FlexibleSubscribeAdapter>(a => a.RegisterMethods("Handle")) .Apply <BlockSpecialsIfsuspended>() .Construct(); }
/// <summary> /// </summary> /// <param name="zoneServer"> /// </param> /// <param name="playfieldIdentity"> /// </param> public Playfield(ZoneServer zoneServer, Identity playfieldIdentity) : base(Identity.None, playfieldIdentity) { this.server = zoneServer; this.playfieldBus = BusSetup.StartWith <AsyncConfiguration>().Construct(); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtomationMessageToClient>(SendAOtomationMessageToClient)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtomationMessageToPlayfield>(this.SendAOtomationMessageToPlayfield)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtomationMessageToPlayfieldOthers>( this.SendAOtomationMessageToPlayfieldOthers)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtomationMessageBodyToClient>(this.SendAOtomationMessageBodyToClient)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtomationMessageBodiesToClient>( this.SendAOtomationMessageBodiesToClient)); this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMSendPlayerSCFUs>(this.SendSCFUsToClient)); this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMExecuteFunction>(this.ExecuteFunction)); this.heartBeat = new Timer(this.HeartBeatTimer, null, 10, 0); this.statels = PlayfieldLoader.PFData[this.Identity.Instance].Statels; this.LoadMobSpawns(playfieldIdentity); this.LoadVendors(playfieldIdentity); this.LoadStaticDynels(playfieldIdentity); }
private static IBus ConstructBus(AppModel model) { var setup = BusSetup.StartWith <Conservative>(); setup.Apply(model.MemBusSetups.ToArray()); return(setup.Construct()); }
/// <summary> /// </summary> public ZoneServer() { // TODO: Get the Server id from chatengine or config file this.Id = 0x356; this.ClientDisconnected += this.ZoneServerClientDisconnected; // New Bus initialization this.zoneBus = BusSetup.StartWith <AsyncConfiguration>().Construct(); this.subscribedMessageHandlers.Clear(); IEnumerable <Type> types = Assembly.GetExecutingAssembly() .GetTypes() .Where( x => x.GetCustomAttributes(typeof(MessageHandlerAttribute), false) .Any( y => ((MessageHandlerAttribute)y).Direction != MessageHandlerDirection.OutboundOnly)); MethodInfo subscriptMethodInfo = typeof(ZoneServer).GetMethod( "SubscribeMessage", BindingFlags.NonPublic | BindingFlags.Instance); foreach (Type type in types) { Type[] temp = type.BaseType.GetGenericArguments(); MethodInfo generic = subscriptMethodInfo.MakeGenericMethod(new Type[] { temp[1], temp[0] }); generic.Invoke(this, null); } this.CheckSubscribedMessageHandlers(); }
public When_Using_Ioc_Support() { _testAdapter = new TestAdapter(); _bus = BusSetup .StartWith <Conservative>() .Apply <IoCSupport>(s => s.SetAdapter(_testAdapter).SetHandlerInterface(typeof(GimmeMsg <>))) .Construct(); }
// Test for https://github.com/flq/MemBus/issues/17 public void Large_number_of_subscribers() { var b = BusSetup.StartWith <AsyncConfiguration>().Construct(); for (var i = 0; i < 100000; i++) { b.Subscribe((int x) => Console.WriteLine(x)); } }
public void Resolvers_will_get_access_to_services() { var simpleResolver = new SimpleResolver(); using (BusSetup.StartWith <Conservative>(cb => cb.AddResolver(simpleResolver)).Construct()) { simpleResolver.Services.ShouldNotBeNull(); } }
public void A_disposed_bus_throws() { var bus = BusSetup.StartWith <Conservative>().Construct(); bus.Dispose(); (new Action(() => bus.Publish(new MessageA()))).Throws <ObjectDisposedException>(); (new Action(() => bus.Subscribe <MessageA>(msg => {}))).Throws <ObjectDisposedException>(); (new Action(() => bus.Observe <MessageA>())).Throws <ObjectDisposedException>(); }
public async Task using_the_awaitable_publish() { var b = BusSetup.StartWith <Conservative>().Construct(); var messageReceived = false; b.Subscribe((string h) => messageReceived = true); await b.PublishAsync("Hello"); Assert.True(messageReceived); }
public void fail_with_bad_types(Type handlerType) { Assert.Throws <ArgumentException>(() => BusSetup .StartWith <Conservative>() .Apply <IoCSupport>(s => s .SetAdapter(_testAdapter) .SetHandlerInterface(handlerType)) .Construct()); }
public When_Using_Ioc_Support_With_Type_Resolver() { _testAdapter = new TestAdapter(); _bus = BusSetup .StartWith <Conservative>() .Apply <IoCSupport>(s => s.SetAdapter(_testAdapter).SetHandlerInterface(typeof(GimmeMsgTypeResolver <>)) .SetMessageTypeResolver(msgT => msgT.GenericTypeArguments[0]) // unwrap from envelope ) .Construct(); }
public void Conventions_allow_changing_the_shape() { var sb = new StringBuilder(); var bus = BusSetup.StartWith <Conservative>(new BusSetupWithTestShapers(sb)).Construct(); using (bus.Subscribe <MessageB>(msg => { })) bus.Publish(new MessageB()); sb.ToString().ShouldBeEqualTo("AB"); }
public void The_default_is_applied_when_no_specials_apply() { var sb = new StringBuilder(); var bus = BusSetup.StartWith <Conservative>(new BusSetupWithDefaultShape(sb)).Construct(); using (bus.Subscribe <MessageA>(msg => { })) bus.Publish(new MessageA()); sb.ToString().ShouldBeEqualTo("Bar"); }
public void default_pubish_pipeline_is_replaceable() { var t = new PublishPipelineTester <MessageB>(); var b = BusSetup.StartWith <Conservative>() .Apply(cb => cb.ConfigurePublishing(cp => cp.DefaultPublishPipeline(t.Mock1Object))) .Construct(); b.Publish(new MessageB()); t.Mock1.VerifyCalled(); }
private static void Main() { var bus = BusSetup.StartWith <Fast>().Construct(); var s = new CompositeSubscriptionPerformanceTest(); for (var i = 0; i < 10; i++) { Run(s, bus); } Console.ReadLine(); }
public void Default_setup_provides_subscription_shape() { var received = 0; var b = BusSetup.StartWith <Conservative>().Construct(); using (b.Subscribe <MessageA>(msg => received++)) { b.Publish(new MessageA()); received.ShouldBeEqualTo(1); } }
public Unexpected_Disposal_Of_Subscriptions() { _bus = BusSetup.StartWith <Conservative>() .Apply <FlexibleSubscribeAdapter>(adp => adp.RegisterMethods("Handle")) .Construct(); _bus.Subscribe(_partnerInCrime1 = new Subscriber()); _bus.Subscribe(_partnerInCrime2 = new Subscriber()); // One disposes the other. That way we keep independent of call sequence _partnerInCrime1.Aquaint(_partnerInCrime2); _partnerInCrime2.Aquaint(_partnerInCrime1); }
public void A_disposed_subscription_is_gone() { int received = 0; var bus = BusSetup.StartWith <Conservative>().Construct(); var d = bus.Subscribe <MessageA>(msg => received++); bus.Publish(new MessageA()); received.ShouldBeEqualTo(1); d.Dispose(); bus.Publish(new MessageA()); received.ShouldBeEqualTo(1); }
public void Default_setup_routes_the_message_correctly() { var sub = new SubscriptionThatFakesHandles <MessageA>(); var b = BusSetup .StartWith <Conservative>(cb => cb.AddSubscription(sub)) .Construct(); var messageA = new MessageA(); b.Publish(messageA); sub.PushCalls.ShouldBeEqualTo(1); }
public static ILifetimeScope Build() { var builder = new ContainerBuilder(); builder.Register(c => { var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113)); connection.Connect(); return(connection); }).As <IEventStoreConnection>().SingleInstance(); builder.Register(c => { var context = c.Resolve <IComponentContext>(); return(BusSetup.StartWith <Conservative>() .Apply <IoCSupport>(s => s.SetAdapter(new AutofacAdaptor(context)).SetHandlerInterface(typeof(IConsume <>))) .Construct()); }).As <IBus>(); builder.Register(x => { var client = new MongoClient("mongodb://localhost"); return(client.GetServer()); }).As <MongoServer>().SingleInstance(); builder.Register(x => x.Resolve <MongoServer>().GetDatabase("Risk")) .As <MongoDatabase>() .InstancePerDependency(); builder.RegisterAssemblyTypes(typeof(IConsume <>).Assembly, Assembly.GetExecutingAssembly()).AsClosedTypesOf(typeof(IConsume <>)); builder.RegisterType <GetEventStoreRepository>().As <IRepository>(); builder.RegisterType <AcceptInvitationHandler>().As <ICommandHandler <AcceptInvitation> >(); builder.RegisterType <CreateLobbyHandler>().As <ICommandHandler <CreateLobby> >(); builder.RegisterType <InvitePlayerHandler>().As <ICommandHandler <InvitePlayer> >(); builder.RegisterType <LeaveLobbyHandler>().As <ICommandHandler <LeaveLobby> >(); builder.RegisterType <StartGameHandler>().As <ICommandHandler <StartGame> >(); builder.RegisterType <StartGameSetupHandler>().As <ICommandHandler <StartGameSetup> >(); builder.RegisterType <PlaceInfantryUnitHandler>().As <ICommandHandler <PlaceInfantryUnit> >(); builder.RegisterType <AutofacCommandHandlerResolver>().As <ICommandHandlerResolver>(); builder.RegisterType <CommandDispatcher>().AsSelf(); var container = builder.Build(); return(container); }
public void Using_shape_overload_directly_works() { var b = BusSetup.StartWith <Conservative>().Construct(); var counter = 0; using (var d = b.Subscribe((string s) => counter++, new ShapeToFilter <string>(s => s == "A"))) { d.ShouldNotBeNull(); b.Publish("A"); b.Publish("B"); } counter.ShouldBeEqualTo(1); }
public FlexibleSubscribingIntegrationContext() { Bus = BusSetup .StartWith <Conservative>() .Apply <FlexibleSubscribeAdapter>(ConfigureAdapter) .Construct(); Bus.Subscribe <object>(MessageCapturing); foreach (var endpoints in GetEndpoints()) { Bus.Subscribe(endpoints); } AdditionalSetup(); }
public void TestAutofacIoCAdapter() { var builder = new ContainerBuilder(); builder.RegisterModule(new IoCRegistration()); var container = builder.Build(); var _bus = BusSetup.StartWith <Conservative>() .Apply <IoCSupport>( s => s.SetAdapter(container.Resolve <IocAdapter>()).SetHandlerInterface(typeof(IHandle <>))) .Construct(); _bus.Publish(new DomainEvent1()); Assert.IsTrue(true); }
/// <summary> /// </summary> public Playfield() { this.playfieldBus = BusSetup.StartWith <AsyncConfiguration>().Construct(); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtMessageToClient>(SendAOtMessageToClient)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtMessageToPlayfield>(this.SendAOtMessageToPlayfield)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtMessageToPlayfieldOthers>(this.SendAOtMessageToPlayfieldOthers)); this.memBusDisposeContainer.Add( this.playfieldBus.Subscribe <IMSendAOtMessageBodyToClient>(this.SendAOtMessageBodyToClient)); this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMSendPlayerSCFUs>(this.SendSCFUsToClient)); this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMExecuteFunction>(this.ExecuteFunction)); this.Entities = new HashSet <IInstancedEntity>(); }
protected FlexibleSubscribingIntegrationContext() { Bus = BusSetup .StartWith <Conservative>() .Apply <FlexibleSubscribeAdapter>(ConfigureAdapter) .Construct(); Bus.Subscribe <object>(MessageCapturing); // ReSharper disable VirtualMemberCallInConstructor foreach (var endpoints in GetEndpoints()) { Bus.Subscribe(endpoints); } AdditionalSetup(); // ReSharper restore VirtualMemberCallInConstructor }