Пример #1
0
        public void ExecuteTest()
        {
            var bus = new CommandBus(ServiceFactory.CreateContainer(null
                                                                    , f => f.Mock <SimpleCommand>((context, command) => command.ResultValue = command.Value * 2)));

            Assert.Equal(10, bus.Execute(new SimpleCommand()
            {
                Value = 5
            }).ResultValue);
            Assert.Equal(0, bus.Execute(new SimpleCommand()
            {
                Value = 5
            }, (context, command) => false).ResultValue);
        }
Пример #2
0
 public async Task DeleteColor(string key)
 {
     await CommandBus.Execute(new RemoveColorCommand
     {
         Key = key
     });
 }
Пример #3
0
 public async Task DeleteImage(string key)
 {
     await CommandBus.Execute(new RemoveImageUrlCommand
     {
         Key = key
     });
 }
Пример #4
0
        public async Task SavePreviewData()
        {
            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Inbox", Color = "#0063AF"
            }));

            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Work", Color = "#0F893E"
            }));

            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Shopping list", Color = "#AC008C"
            }));

            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Vacation", Color = "#F7630D"
            }));

            var folders = await FolderQuery.GetAll();

            var folder  = folders.FirstOrDefault();
            var folder2 = folders.Skip(1).FirstOrDefault();
            await CommandBus.Execute(new SaveNoteCommand(new NoteModel {
                Id = Guid.NewGuid(), FolderId = folder.Id, Title = "Buy milk"
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel
            {
                Id = Guid.NewGuid(),
                FolderId = folder.Id,
                Title = "Walk Max with bike",
                Reminder = new ReminderModel
                {
                    DateTime = DateTime.Today + TimeSpan.FromHours(7.25),
                    Recurrence = new DaysOfWeekRecurrenceModel
                    {
                        Every = 2,
                        DaysOfWeek = DaysOfWeek.Weekends
                    }
                }
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel {
                Id = Guid.NewGuid(), FolderId = folder.Id, Title = "Call mom", Reminder = new ReminderModel {
                    DateTime = DateTime.Today + TimeSpan.FromHours(15)
                }, IsFlagged = true
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel
            {
                Id = Guid.NewGuid(),
                FolderId = folder.Id,
                Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
                Text = "Proin et diam at lorem egestas ullamcorper. Curabitur non eleifend mi. Praesent eu sem elementum, rutrum neque id, sollicitudin dolor. Proin molestie ullamcorper sem a hendrerit. Integer ac sapien erat. Morbi vehicula venenatis dolor, non aliquet nibh mattis sed.",
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel {
                Id = Guid.NewGuid(), FolderId = folder2.Id, Title = "Test note", IsFlagged = true
            }));
        }
Пример #5
0
 public async Task DeleteLocalizedString(CultureInfo culture, string key)
 {
     await CommandBus.Execute(new RemoveLocalizedStringCommand
     {
         Culture = culture,
         Key     = key
     });
 }
Пример #6
0
        private CommandResult ExecuteArrangeAndAct(
            ICommandHandler <BlankSimpleTestCommand> getCommandHandlerRetVal = null,
            string commandPreHandleResult = "")
        {
            _commandHandlerProvider
            .Stub(x => x.GetCommandHandler <BlankSimpleTestCommand>())
            .Return(getCommandHandlerRetVal);

            _prerequisitesChecker
            .Stub(x => x.Check(Arg <BlankSimpleTestCommand> .Is.Anything))
            .Return(String.IsNullOrEmpty(commandPreHandleResult) ? new CheckResult() : new CheckResult()
            {
                ContainsError = true,
                Message       = commandPreHandleResult
            });

            return(_bus.Execute(new BlankSimpleTestCommand()));
        }
Пример #7
0
        public async Task Register(string email, string password)
        {
            var command = new RegisterNewUserCommand
            {
                Email    = email,
                Password = _sha512Service.Calculate(password)
            };

            await CommandBus.Execute(command);
        }
Пример #8
0
        public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }

            //Dependencies Initialization
            //In XVS this is done automatically via MEF, here we need to do it manually
            var fingerprintRetriever = new FingerprintRetriever();
            var settings             = new InMemoryRemoteServerSettings();
            var dialogProvider       = new TestDialogProvider();
            var progress             = new Progress <string>(x => Console.WriteLine(x));
            var errorsManager        = new TestErrorsManager();
            var asyncManager         = new AsyncManager();

            EventStream = new EventStream();

            //The Server Source represents a type of server that you want to support connection
            //If you want to connect against a Linux Server, a Mac Server, a Windows Server, an IoT Server, etc,
            //you would need to define a Server Source for each of those types
            var serverSource = new TestServerSource(fingerprintRetriever,
                                                    settings,
                                                    dialogProvider,
                                                    progress,
                                                    errorsManager,
                                                    asyncManager,
                                                    EventStream);

            //Dependencies initialization for the command handlers
            //In XVS this is done automatically via MEF, here we need to do it manually
            ServerSourceManager = new RemoteServerSourceManager();

            var connectionManager = new TestServerConnectionManager(ServerSourceManager, asyncManager, EventStream);

            //Command handlers registration
            //The command handlers are needed to be registered in the Command Bus,
            //in order to let the XMA framework to invoke and handle commands and events
            //In XVS this is done automatically via MEF, here we need to do it manually
            var handlers = new List <ICommandHandler> {
                new DisconnectServerHandler(ServerSourceManager),
                new RegisterAgentsHandler(ServerSourceManager),
                new RegisterServerSourceHandler(ServerSourceManager, connectionManager),
                new SelectServerHandler(ServerSourceManager),
                new StartAgentHandler(ServerSourceManager),
                new StartConsoleHandler(ServerSourceManager)
            };

            CommandBus = new CommandBus(handlers);

            //This is how we register every server source defined
            CommandBus.Execute(new RegisterServerSource(serverSource, connectAutomatically: true));

            isInitialized = true;
        }
Пример #9
0
        public void HappyPath()
        {
            var command          = Substitute.For <ICommand>();
            var commandValidator = Substitute.For <ICommandValidator <ICommand> >();
            var commandHandler   = Substitute.For <ICommandHandler <ICommand> >();

            var commandBus = new CommandBus(t => commandValidator, t => commandHandler);

            var commandResult = commandBus.Execute(command);

            Assert.True(commandResult.WasSuccessful());
            commandValidator.Received(1).Validate(Arg.Any <ICommand>());
            commandHandler.Received(1).Execute(Arg.Any <ICommand>());
        }
Пример #10
0
        static void Main()
        {
            var       container = ObjectFactory.CreateContainer();
            var       bus       = new CommandBus(container);
            string    s         = null;
            const int testCount = 10 * 10000;

            for (int i = 0; i < 5; i++)
            {
                CodeTimer.TimeLine("Call", testCount, x => s    = bus.Call(new TestCommand()));
                CodeTimer.TimeLine("Execute", testCount, x => s = bus.Execute(new TestCommand()).Result);
                Console.WriteLine();
            }
            Console.ReadLine();
        }
Пример #11
0
        public void ValidationErrors()
        {
            var validationsErrors = new[] { new ValidationError("Id", "Value is not valid", -1) };
            var command           = Substitute.For <ICommand>();
            var commandValidator  = Substitute.For <ICommandValidator <ICommand> >();

            commandValidator.Validate(Arg.Any <ICommand>()).Returns(validationsErrors);
            var commandHandler = Substitute.For <ICommandHandler <ICommand> >();
            var commandBus     = new CommandBus(t => commandValidator, t => commandHandler);

            var commandResult = commandBus.Execute(command);

            Assert.False(commandResult.WasSuccessful());
            Assert.Equal(commandResult.ValidationErrors[0], validationsErrors[0]);
            commandValidator.Received(1).Validate(Arg.Any <ICommand>());
            commandHandler.DidNotReceive().Execute(Arg.Any <ICommand>());
        }
Пример #12
0
        public void ExecuteExceptionTest()
        {
            var bus = new CommandBus(ServiceFactory.CreateContainer(null
                                                                    , f => f.Mock <SimpleCommand>((context, command) =>
            {
                throw new NotSupportedException();
            })));
            Exception catchException = null;

            Assert.Throws <NotSupportedException>(() => bus.Execute(new SimpleCommand()
            {
                Value = 5
            }, null, (context, command, exception) =>
            {
                catchException = exception;
            }));
            Assert.IsType <NotSupportedException>(catchException);
        }
Пример #13
0
        private async Task <AccessTokenModel> GenerateRefreshAndAccessToken(Guid userId)
        {
            var refreshToken = _randomStringGenerationService.Generate(length: 128);

            var token = _accessTokenService.Create(new AuthPayload
            {
                UserId = userId
            },
                                                   refreshToken);

            await CommandBus.Execute(new SetRefreshTokenCommand
            {
                UserId       = userId,
                RefreshToken = refreshToken
            });

            return(new AccessTokenModel
            {
                RefreshToken = refreshToken,
                AccessToken = token
            });
        }
Пример #14
0
        public void TypeCheck()
        {
            var command                      = new TestComand();
            var commandValidator             = new TestComandValidator();
            var commandHandler               = new TestComandHandler();
            var requestedComandHandlerType   = typeof(void);
            var requestedComandValidatorType = typeof(void);
            var commandBus                   = new CommandBus(t =>
            {
                requestedComandValidatorType = t;
                return(commandValidator);
            }, t =>
            {
                requestedComandHandlerType = t;
                return(commandHandler);
            });

            commandBus.Execute(command);

            Assert.Equal(typeof(ICommandHandler <TestComand>), requestedComandHandlerType);
            Assert.Equal(typeof(ICommandValidator <TestComand>), requestedComandValidatorType);
        }
Пример #15
0
 public async Task AddColor(AddColorCommand localizedString)
 {
     await CommandBus.Execute(localizedString);
 }
Пример #16
0
 public async Task UpdateImage(UpdateImageUrlCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #17
0
 public async Task AddImage(AddImageUrlCommand localizedString)
 {
     await CommandBus.Execute(localizedString);
 }
Пример #18
0
 public async Task UpdateLocalizedString(UpdateLocalizedStringCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #19
0
 public ActionResult Entry(HolidayEntryCommand command)
 {
     CommandBus.Execute(command);
     Notifier.Success("Holiday entered for {0} until {1}", command.DateFrom.Value.ToShortDateString(), command.DateTo.Value.ToShortDateString());
     return(RedirectToAction("Entry", "Day"));
 }
Пример #20
0
 public async Task AddOrUpdateLocalizedStrings(AddOrUpdateLocalizedStringsCommand localizedString)
 {
     await CommandBus.Execute(localizedString);
 }
Пример #21
0
 public async Task AddLocalizedString(AddLocalizedStringCommand localizedString)
 {
     await CommandBus.Execute(localizedString);
 }
Пример #22
0
 public async Task UpdateColor(UpdateColorCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #23
0
 public void ExecuteCommand(ICommand cmd)
 {
     CommandBus.Execute(cmd);
     //Configuration.CommandBus.Execute(cmd);
 }
Пример #24
0
 public async Task Create(AddPriceCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #25
0
 public async Task Delete(DeleteProductCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #26
0
 public ActionResult Entry(DayEntryCommand command)
 {
     CommandBus.Execute(command);
     Notifier.Success("Entry saved for {0}", command.Date);
     return(RedirectToAction("Index", "Month", new { command.Date.Year, command.Date.Month }));
 }
Пример #27
0
 public async Task Create(CreateProductCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #28
0
 public async Task UpdateCategory(UpdateCategoryCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #29
0
 public async Task Update(UpdateProductCommand command)
 {
     await CommandBus.Execute(command);
 }
Пример #30
0
 public async Task DeleteCategory(DeleteCategoryCommand command)
 {
     await CommandBus.Execute(command);
 }