예제 #1
0
        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));
        }
예제 #2
0
        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();
        }
예제 #3
0
        public async Task <ActionResult> Index()
        {
            var cmd = new TestCommand("nameA", "pwdB");
            await CommandBus.SendAsync(cmd);

            return(View());
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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());
        }
예제 #7
0
        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);
        }
예제 #8
0
        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());
        }
예제 #9
0
        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);
        }
예제 #10
0
        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());
        }
예제 #11
0
 public Task Post(AddTodoDto dto)
 {
     return(CommandBus.SendAsync(new AddTodoCommand(dto.Title)));
 }
예제 #12
0
 public Task PutTodo(Guid id, Guid todoId, [FromBody] UpdateTodoDto payload)
 {
     return(CommandBus.SendAsync(new UpdateTodoCommand(id, todoId, payload.IsComplete, payload.Text)));
 }
예제 #13
0
 public Task PostTodo(Guid id, [FromBody] AddTodoDto payload)
 {
     return(CommandBus.SendAsync(new AddTodoCommand(id, payload.Text)));
 }
예제 #14
0
 public Task Put(Guid id, [FromBody] UpdateTodoListDto payload)
 {
     return(CommandBus.SendAsync(new UpdateTodoListCommand(id, payload.Name)));
 }
예제 #15
0
 public Task DeregisterDevice(DeregisterFcmExternalUserDeviceCommand parameters)
 {
     return(CommandBus.SendAsync(parameters));
 }
 public Task DeregisterDevice(DeregisterApnsDeviceCommand parameters)
 {
     return(CommandBus.SendAsync(parameters));
 }
예제 #17
0
 public Task <IQueryable <TodoReadModel> > Get()
 {
     return(CommandBus.SendAsync(new GetTodosQuery()));
 }
예제 #18
0
 public Task PushNotification(PushExternalApnsNotificationCommand parameters)
 {
     return(CommandBus.SendAsync(parameters));
 }
예제 #19
0
 public Task RegisterDevice(RegisterApnsExternalUserDeviceCommand parameters)
 {
     return(CommandBus.SendAsync(parameters));
 }
예제 #20
0
 public Task RegisterDevice(RegisterFcmDeviceCommand parameters)
 {
     return(CommandBus.SendAsync(parameters));
 }
예제 #21
0
 public Task <ICommandResult> SendCommandAsync <TCommand>(TCommand command) where TCommand : ICommand
 {
     return(CommandBus.SendAsync(this, command));
 }
예제 #22
0
 public Task <IQueryable <TodoListDto> > Get()
 {
     return(CommandBus.SendAsync(new GetTodoListsQuery()));
 }
예제 #23
0
 public Task Post([FromBody] CreateTodoListDto payload)
 {
     return(CommandBus.SendAsync(new CreateTodoListCommand(payload.Id, payload.Name)));
 }