Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        public AppDomainObject AttachClient(AttachClient command)
        {
            ThrowIfNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new AppClientAttached()));

            return(this);
        }
Exemplo n.º 3
0
        protected Task On(AttachClient command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppClients.CanAttach(a.Snapshot.Clients, command);

                a.AttachClient(command);
            }));
        }
Exemplo n.º 4
0
        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));
            }));
        }
Exemplo n.º 5
0
        public AppDomainObject AttachClient(AttachClient command)
        {
            Guard.Valid(command, nameof(command), () => "Cannot attach client");

            ThrowIfNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new AppClientAttached()));

            return(this);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 12
0
        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.");
                }
            });
        }
Exemplo n.º 13
0
        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"));
                }
            });
        }
Exemplo n.º 14
0
        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)));
                }
            });
        }
Exemplo n.º 15
0
        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
            })
                );
        }
Exemplo n.º 16
0
        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
            })
                );
        }
Exemplo n.º 17
0
 private void AttachClient(AttachClient command)
 {
     Raise(command, new AppClientAttached());
 }
Exemplo n.º 18
0
 public void AttachClient(AttachClient command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AppClientAttached()));
 }
Exemplo n.º 19
0
 public static ClientDto FromCommand(AttachClient command)
 {
     return(SimpleMapper.Map(command, new ClientDto {
         Name = command.Id, Role = Roles.Editor
     }));
 }
Exemplo n.º 20
0
 protected Task On(AttachClient command, CommandContext context)
 {
     return(handler.UpdateAsync <AppDomainObject>(context, a => a.AttachClient(command)));
 }
Exemplo n.º 21
0
 public static ClientDto FromCommand(AttachClient command)
 {
     return(SimpleMapper.Map(command, new ClientDto {
         Name = command.Id, Permission = AppClientPermission.Editor
     }));
 }
Exemplo n.º 22
0
        public void CanAttach_should_throw_execption_if_client_id_is_null()
        {
            var command = new AttachClient();

            Assert.Throws <ValidationException>(() => GuardAppClients.CanAttach(clients, command));
        }