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); }
public async Task DeleteColor(string key) { await CommandBus.Execute(new RemoveColorCommand { Key = key }); }
public async Task DeleteImage(string key) { await CommandBus.Execute(new RemoveImageUrlCommand { Key = key }); }
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 })); }
public async Task DeleteLocalizedString(CultureInfo culture, string key) { await CommandBus.Execute(new RemoveLocalizedStringCommand { Culture = culture, Key = key }); }
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())); }
public async Task Register(string email, string password) { var command = new RegisterNewUserCommand { Email = email, Password = _sha512Service.Calculate(password) }; await CommandBus.Execute(command); }
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; }
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>()); }
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(); }
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>()); }
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); }
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 }); }
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); }
public async Task AddColor(AddColorCommand localizedString) { await CommandBus.Execute(localizedString); }
public async Task UpdateImage(UpdateImageUrlCommand command) { await CommandBus.Execute(command); }
public async Task AddImage(AddImageUrlCommand localizedString) { await CommandBus.Execute(localizedString); }
public async Task UpdateLocalizedString(UpdateLocalizedStringCommand command) { await CommandBus.Execute(command); }
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")); }
public async Task AddOrUpdateLocalizedStrings(AddOrUpdateLocalizedStringsCommand localizedString) { await CommandBus.Execute(localizedString); }
public async Task AddLocalizedString(AddLocalizedStringCommand localizedString) { await CommandBus.Execute(localizedString); }
public async Task UpdateColor(UpdateColorCommand command) { await CommandBus.Execute(command); }
public void ExecuteCommand(ICommand cmd) { CommandBus.Execute(cmd); //Configuration.CommandBus.Execute(cmd); }
public async Task Create(AddPriceCommand command) { await CommandBus.Execute(command); }
public async Task Delete(DeleteProductCommand command) { await CommandBus.Execute(command); }
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 })); }
public async Task Create(CreateProductCommand command) { await CommandBus.Execute(command); }
public async Task UpdateCategory(UpdateCategoryCommand command) { await CommandBus.Execute(command); }
public async Task Update(UpdateProductCommand command) { await CommandBus.Execute(command); }
public async Task DeleteCategory(DeleteCategoryCommand command) { await CommandBus.Execute(command); }