public void TestFindInverseFunction() { FakeServer server = new FakeServer(); PrivateObject canvas = new PrivateObject(typeof(Canvas)); object[] paramsSelectClick = new object[] { null, null }; canvas.Invoke("btnEvent_One_Click", paramsSelectClick); //red rectangle object[] paramsMouseClick = new object[] { null, new MouseEventArgs(MouseButtons.Left, 1, 100, 100, 0) }; canvas.Invoke("pnlCenter_MouseClick", paramsMouseClick); object[] paramsbtnUndoClick = new object[] { null, null }; canvas.Invoke("btnUndo_Click", paramsbtnUndoClick); NUnit.Framework.Assert.AreEqual(0, Canvas.Objects.Count); }
public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent, EventReceived <FirstTestEvent> eventReceived) { var host = TestUtils.CreateNybusHost(nybus => { nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.SubscribeToEvent(eventReceived); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <FirstTestEvent> >())); }
public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand, CommandReceived <FirstTestCommand> commandReceived) { var host = TestUtils.CreateNybusHost(nybus => { nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.SubscribeToCommand(commandReceived); }); await host.StartAsync(); await host.Bus.InvokeCommandAsync(testCommand); await host.StopAsync(); Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >())); }
public async Task Outgoing_Events_are_marked_via_MessageAttribute(FakeServer server, AttributeTestEvent testEvent, EventReceivedAsync <ThirdTestEvent> eventReceived) { var host = CreateNybusHost(nybus => { nybus.SubscribeToEvent(eventReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <ThirdTestEvent> >()), Times.Once); }
public async Task Outgoing_commands_are_marked_via_MessageAttribute(FakeServer server, AttributeTestCommand testCommand, CommandReceivedAsync <ThirdTestCommand> commandReceived) { var host = CreateNybusHost(nybus => { nybus.SubscribeToCommand(commandReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); }); await host.StartAsync(); await host.Bus.InvokeCommandAsync(testCommand); await host.StopAsync(); Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <ThirdTestCommand> >()), Times.Once); }
public async Task Events_are_correctly_converted(FakeServer server, ThirdTestEvent testEvent, EventReceivedAsync <AttributeTestEvent> eventReceived) { var host = CreateNybusHost(nybus => { nybus.SubscribeToEvent(eventReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.Is <IEventContext <AttributeTestEvent> >(e => string.Equals(e.Event.Message, testEvent.Message))), Times.Once); }
public async Task Commands_are_correctly_converted(FakeServer server, ThirdTestCommand testCommand, CommandReceivedAsync <AttributeTestCommand> commandReceived) { var host = CreateNybusHost(nybus => { nybus.SubscribeToCommand(commandReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); }); await host.StartAsync(); await host.Bus.InvokeCommandAsync(testCommand); await host.StopAsync(); Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.Is <ICommandContext <AttributeTestCommand> >(c => string.Equals(c.Command.Message, testCommand.Message))), Times.Once); }
public async Task Issue90(FakeServer server, CommandReceivedAsync <FirstTestCommand> commandReceived, Exception exception, FirstTestCommand testCommand) { const int maxRetries = 5; Mock.Get(commandReceived) .Setup(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >())) .Throws(exception); var builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(new Dictionary <string, string> { ["Nybus:CommandErrorFilters:0:type"] = "retry", ["Nybus:CommandErrorFilters:0:maxRetries"] = maxRetries.Stringfy() }); var configuration = builder.Build(); var host = CreateNybusHost(nybus => { nybus.SubscribeToCommand(commandReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.UseConfiguration(configuration); }); await host.StartAsync(); await host.Bus.InvokeCommandAsync(testCommand); await Task.Delay(TimeSpan.FromMilliseconds(50)); await host.StopAsync(); Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >()), Times.Exactly(maxRetries)); }
public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent) { var handler = Mock.Of <FirstTestEventHandler>(); var host = CreateNybusHost(nybus => { nybus.SubscribeToEvent <FirstTestEvent, FirstTestEventHandler>(handler); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await host.StopAsync(); Mock.Get(handler).Verify(p => p.HandleAsync(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <FirstTestEvent> >()), Times.Once); }
public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent, [Frozen] EventReceivedAsync <SecondTestEvent> eventReceived, SecondTestEventHandler handler) { var host = CreateNybusHost(nybus => { nybus.SubscribeToEvent(eventReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.SubscribeToEvent <SecondTestEvent, SecondTestEventHandler>(); }, services => { services.AddSingleton(eventReceived); services.AddSingleton(handler); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <SecondTestEvent> >())); }
public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand, [Frozen] CommandReceivedAsync <SecondTestCommand> commandReceived, SecondTestCommandHandler handler) { var host = CreateNybusHost(nybus => { nybus.SubscribeToCommand(commandReceived); nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.SubscribeToCommand <SecondTestCommand, SecondTestCommandHandler>(); }, services => { services.AddSingleton(commandReceived); services.AddSingleton(handler); }); await host.StartAsync(); await host.Bus.InvokeCommandAsync(testCommand); await host.StopAsync(); Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <SecondTestCommand> >())); }
public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent, [Frozen] EventReceivedAsync <SecondTestEvent> eventReceived, SecondTestEventHandler handler) { var settings = new Dictionary <string, string> { ["Nybus:ErrorPolicy:ProviderName"] = "retry", ["Nybus:ErrorPolicy:MaxRetries"] = "5", }; var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings); var configuration = configurationBuilder.Build(); var host = CreateNybusHost(nybus => { nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.UseConfiguration(configuration); nybus.SubscribeToEvent <SecondTestEvent, SecondTestEventHandler>(); }, services => { services.AddSingleton(eventReceived); services.AddSingleton(handler); }); await host.StartAsync(); await host.Bus.RaiseEventAsync(testEvent); await host.StopAsync(); Mock.Get(eventReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <IEventContext <SecondTestEvent> >())); }
public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand, CommandReceivedAsync <SecondTestCommand> commandReceived) { var settings = new Dictionary <string, string> { ["Nybus:ErrorPolicy:ProviderName"] = "retry", ["Nybus:ErrorPolicy:MaxRetries"] = "5", }; var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings); var configuration = configurationBuilder.Build(); var host = TestUtils.CreateNybusHost(nybus => { nybus.UseRabbitMqBusEngine(rabbitMq => { rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory()); }); nybus.UseConfiguration(configuration); nybus.SubscribeToCommand <SecondTestCommand>(); }, services => { services.AddSingleton(commandReceived); services.AddSingleton <ICommandHandler <SecondTestCommand>, SecondTestCommandHandler>(); }); await host.StartAsync(); await host.Bus.InvokeCommandAsync(testCommand); await host.StopAsync(); Mock.Get(commandReceived).Verify(p => p(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <SecondTestCommand> >())); }