private static async Task Go() { Console.WriteLine("Starting"); Console.WriteLine("Dependency Injection - Register All"); // Dependency Injection var di = new TinyDependencyInjection(); di.AddDependency(Dependency.Create().For <ICommandHandler <ICommand> >().Use <Declaration_CommandHandler>()); di.AddDependency(Dependency.Create().For <IRepository <Declaration> >().Use <DeclarationEventsRepository <Declaration> >().SetBehaviour(DIBehaviour.Singleton)); di.AddDependency(Dependency.Create().For <IRepository <Event> >().Use <DeclarationRepository <Event> >().SetBehaviour(DIBehaviour.Singleton)); di.AddDependency(Dependency.Create().For <IRepository <Event> >().Use <DeclarationRepository <Event> >().SetBehaviour(DIBehaviour.Singleton)); di.AddDependency(Dependency.Create().For <IQueryHandler <Declaration_GetQuery, Declaration> >().Use <Declaration_QueryHandler>().SetBehaviour(DIBehaviour.Singleton)); di.Init(); // Init All Objects // CommandBus - need for send Command. var CommandBus = new CommandBus(di); // QueryBus - need for send Queries and Receive Data var QueryBus = new QueryBus(di); Console.WriteLine("Create two Entities"); // Create two commands which Create Declaration objects in Repos and Write to EventRepo var CreateCommand1 = new Declaration_CreateCommand() { Id = "1", Title = "CreateCommand1", Description = "This is First Command1" }; await CommandBus.SendAsync(CreateCommand1); var CreateCommand2 = new Declaration_CreateCommand() { Id = "2", Title = "CreateCommand2", Description = "This is First Command2" }; await CommandBus.SendAsync(CreateCommand2); Console.WriteLine("Get Data From First Entity"); // Create query and get data about first Declaration object from repo var Get1Query = new Declaration_GetQuery() { Id = "1" }; var res1 = await QueryBus.GetAsync <Declaration_GetQuery, Declaration>(Get1Query); var Get2Query = new Declaration_GetQuery() { Id = "2" }; var res2 = await QueryBus.GetAsync <Declaration_GetQuery, Declaration>(Get2Query); Console.WriteLine(string.Format("Id = {0}; Title = {1}; Description = {2}", res1.Id, res1.Title, res1.Description)); Console.WriteLine(string.Format("Id = {0}; Title = {1}; Description = {2}", res2.Id, res2.Title, res2.Description)); }
public async Task Test1() { //Larva.MessageProcess.LoggerManager.SetLoggerProvider(new Log4NetLoggerProvider()); var consumer = new CommandConsumer(); consumer.Initialize(new ConsumerSettings { AmqpUri = new Uri("amqp://*****:*****@localhost/test") }, "MessageProcess_CommandTopic", 4, false, 1, new IInterceptor[] { new PerformanceCounterInterceptor() }, typeof(CommandTests).Assembly); consumer.Start(); var commandBus = new CommandBus(); commandBus.Initialize(new ProducerSettings { AmqpUri = new Uri("amqp://*****:*****@localhost/test") }, "MessageProcess_CommandTopic", 4, IPEndPoint.Parse("127.0.0.1:5000")); commandBus.Start(); for (var i = 1; i <= 5; i++) { for (var j = 1; j <= 5; j++) { await commandBus.SendAsync(new Command1($"Test{i}")); } } Thread.Sleep(1000); commandBus.Shutdown(); Thread.Sleep(10000); consumer.Shutdown(); }
public async Task <ActionResult> Index() { var cmd = new TestCommand("nameA", "pwdB"); await CommandBus.SendAsync(cmd); return(View()); }
public async Task SendAsync_ArgumentNullExceptionWhichCommand() { // Arrange var bus = new CommandBus(); // Act Task task = bus.SendAsync <ICommand>(null); // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => await task); }
public async Task SendAsync_Should_Handle_The_HandleAsync() { Dictionary <Type, ICommandHandler> commandHandlers = new Dictionary <Type, ICommandHandler>(); var commandBus = new CommandBus(); CommandHandler commandHandler = new CommandHandler(); await commandBus.SubscribeAsync(commandHandler); var testCommand = new TestCommand(); await commandBus.SendAsync(testCommand); Assert.True(testCommand.TestCommandValue); }
Given_TestCommand_AndTestCommandHandlerNotRegistered_When_SendAsync_Then_HandlerNotFoundExceptionIsThrown() { //Arrange var command = new TestCommand(); Func <Type, object> resolver = type => { return(null); }; var commandBus = new CommandBus(resolver); //Act Func <Task> handleAction = () => commandBus.SendAsync(command); //Assert Assert.ThrowsAsync <HandlerNotFoundException>(() => handleAction.Invoke()); }
public async Task Given_TestCommand_When_SendAsync_Then_CommandHandlerIsFired() { //Arrange var command = new TestCommand(); var commandHandler = new TestCommandHandler(); Func <Type, object> resolver = type => { return(commandHandler); }; var commandBus = new CommandBus(resolver); //Act await commandBus.SendAsync(command); //Assert Assert.That(commandHandler.IsFired, Is.True); }
Given_TestCommand_AndTestCommandHandlerNotRegistered_When_SendAsync_Then_ActivationExceptionIsThrown() { //Arrange var services = new ServiceCollection(); var serviceProvider = services.BuildServiceProvider(); var command = new TestCommand(); var commandBus = new CommandBus(serviceProvider.GetService); //Act Func <Task> handleAction = () => commandBus.SendAsync(command); //Assert Assert.ThrowsAsync <HandlerNotFoundException>(() => handleAction.Invoke()); }
public async Task Given_TestCommand_When_SendAsync_Then_CommandHandlerIsFired() { //Arrange var services = new ServiceCollection(); var command = new TestCommand(); var commandHandler = new TestCommandHandler(); services.AddScoped <ICommandHandler <TestCommand> >(provider => commandHandler); var serviceProvider = services.BuildServiceProvider(); var commandBus = new CommandBus(serviceProvider.GetService); //Act await commandBus.SendAsync(command); //Assert Assert.That(commandHandler.IsFired, Is.True); }
public async Task <ActionResult> IndexLoop() { Stopwatch sw = Stopwatch.StartNew(); int i = 1000, j = 10; var taskList = new List <Task>(); while (j-- > 0) { i = 10000; while (i-- > 0) { var cmd = new TestCommand("nameA", "pwdB"); taskList.Add(CommandBus.SendAsync(cmd)); } await Task.WhenAll(taskList); } sw.Stop(); ViewBag.Time = sw.ElapsedMilliseconds / 1000; return(View()); }
public Task Post(AddTodoDto dto) { return(CommandBus.SendAsync(new AddTodoCommand(dto.Title))); }
public Task PutTodo(Guid id, Guid todoId, [FromBody] UpdateTodoDto payload) { return(CommandBus.SendAsync(new UpdateTodoCommand(id, todoId, payload.IsComplete, payload.Text))); }
public Task PostTodo(Guid id, [FromBody] AddTodoDto payload) { return(CommandBus.SendAsync(new AddTodoCommand(id, payload.Text))); }
public Task Put(Guid id, [FromBody] UpdateTodoListDto payload) { return(CommandBus.SendAsync(new UpdateTodoListCommand(id, payload.Name))); }
public Task DeregisterDevice(DeregisterFcmExternalUserDeviceCommand parameters) { return(CommandBus.SendAsync(parameters)); }
public Task DeregisterDevice(DeregisterApnsDeviceCommand parameters) { return(CommandBus.SendAsync(parameters)); }
public Task <IQueryable <TodoReadModel> > Get() { return(CommandBus.SendAsync(new GetTodosQuery())); }
public Task PushNotification(PushExternalApnsNotificationCommand parameters) { return(CommandBus.SendAsync(parameters)); }
public Task RegisterDevice(RegisterApnsExternalUserDeviceCommand parameters) { return(CommandBus.SendAsync(parameters)); }
public Task RegisterDevice(RegisterFcmDeviceCommand parameters) { return(CommandBus.SendAsync(parameters)); }
public Task <ICommandResult> SendCommandAsync <TCommand>(TCommand command) where TCommand : ICommand { return(CommandBus.SendAsync(this, command)); }
public Task <IQueryable <TodoListDto> > Get() { return(CommandBus.SendAsync(new GetTodoListsQuery())); }
public Task Post([FromBody] CreateTodoListDto payload) { return(CommandBus.SendAsync(new CreateTodoListCommand(payload.Id, payload.Name))); }