public void CanAttach_should_throw_execption_if_client_id_is_null() { var command = new AttachClient(); ValidationAssert.Throws(() => GuardAppClients.CanAttach(clients_0, command), new ValidationError("Client id is required.", "Id")); }
public AppDomainObject AttachClient(AttachClient command) { ThrowIfNotCreated(); RaiseEvent(SimpleMapper.Map(command, new AppClientAttached())); return(this); }
protected Task On(AttachClient command, CommandContext context) { return(handler.UpdateSyncedAsync <AppDomainObject>(context, a => { GuardAppClients.CanAttach(a.Snapshot.Clients, command); a.AttachClient(command); })); }
protected Task On(AttachClient command, CommandContext context) { return(handler.UpdateAsync <AppDomainObject>(context, a => { a.AttachClient(command, keyGenerator.GenerateKey()); context.Succeed(EntityCreatedResult.Create(a.Clients[command.Id], a.Version)); })); }
public AppDomainObject AttachClient(AttachClient command) { Guard.Valid(command, nameof(command), () => "Cannot attach client"); ThrowIfNotCreated(); RaiseEvent(SimpleMapper.Map(command, new AppClientAttached())); return(this); }
public void CanAttach_should_not_throw_exception_if_client_is_free() { var command = new AttachClient { Id = "ios" }; var clients_1 = clients_0.Add("android", "secret"); GuardAppClients.CanAttach(clients_1, command); }
public void CanAttach_should_throw_exception_if_client_already_exists() { var command = new AttachClient { Id = "android" }; clients.Add("android", "secret"); Assert.Throws <ValidationException>(() => GuardAppClients.CanAttach(clients, command)); }
public void CanAttach_should_throw_exception_if_client_already_exists() { var command = new AttachClient { Id = "android" }; var clients_1 = clients_0.Add("android", "secret"); ValidationAssert.Throws(() => GuardAppClients.CanAttach(clients_1, command), new ValidationError("A client with the same id already exists.")); }
public Task HandleAsync(CommandContext context, NextDelegate next) { if (context.IsCompleted && context.Command is CreateApp createApp) { var command = new AttachClient { Id = "default", AppId = createApp.AppId }; context.CommandBus.PublishAsync(command).Forget(); } return(next(context)); }
public void AttachClient_should_create_events() { var command = new AttachClient { Id = clientId }; CreateApp(); sut.AttachClient(CreateCommand(command)); sut.GetUncomittedEvents() .ShouldHaveSameEvents( CreateEvent(new AppClientAttached { Id = clientId, Secret = command.Secret }) ); }
public async Task HandleAsync(CommandContext context, NextDelegate next) { await next(context); if (context.IsCompleted && context.Command is CreateApp createApp) { var appId = NamedId.Of(createApp.AppId, createApp.Name); var command = new AttachClient { Id = "default", AppId = appId }; await context.CommandBus.PublishAsync(command); } }
public static void CanAttach(AppClients clients, AttachClient command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot attach client.", e => { if (string.IsNullOrWhiteSpace(command.Id)) { e(Not.Defined("Client id"), nameof(command.Id)); } else if (clients.ContainsKey(command.Id)) { e("A client with the same id already exists."); } }); }
public static void CanAttach(AppClients clients, AttachClient command) { Guard.NotNull(command, nameof(command)); Validate.It(e => { if (string.IsNullOrWhiteSpace(command.Id)) { e(Not.Defined("ClientId"), nameof(command.Id)); } else if (clients.ContainsKey(command.Id)) { e(T.Get("apps.clients.idAlreadyExists")); } }); }
public static void CanAttach(AppClients clients, AttachClient command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot attach client.", error => { if (string.IsNullOrWhiteSpace(command.Id)) { error(new ValidationError("Client id is required.", nameof(command.Id))); } else if (clients.ContainsKey(command.Id)) { error(new ValidationError("Client id already added.", nameof(command.Id))); } }); }
public void AttachClient_should_create_events() { var command = new AttachClient { Id = clientId }; CreateApp(); sut.AttachClient(CreateCommand(command)); Assert.True(sut.Snapshot.Clients.ContainsKey(clientId)); sut.GetUncomittedEvents() .ShouldHaveSameEvents( CreateEvent(new AppClientAttached { Id = clientId, Secret = command.Secret }) ); }
public async Task AttachClient_should_create_events_and_update_state() { var command = new AttachClient { Id = clientId }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.True(sut.Snapshot.Clients.ContainsKey(clientId)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppClientAttached { Id = clientId, Secret = command.Secret }) ); }
private void AttachClient(AttachClient command) { Raise(command, new AppClientAttached()); }
public void AttachClient(AttachClient command) { RaiseEvent(SimpleMapper.Map(command, new AppClientAttached())); }
public static ClientDto FromCommand(AttachClient command) { return(SimpleMapper.Map(command, new ClientDto { Name = command.Id, Role = Roles.Editor })); }
protected Task On(AttachClient command, CommandContext context) { return(handler.UpdateAsync <AppDomainObject>(context, a => a.AttachClient(command))); }
public static ClientDto FromCommand(AttachClient command) { return(SimpleMapper.Map(command, new ClientDto { Name = command.Id, Permission = AppClientPermission.Editor })); }
public void CanAttach_should_throw_execption_if_client_id_is_null() { var command = new AttachClient(); Assert.Throws <ValidationException>(() => GuardAppClients.CanAttach(clients, command)); }