Exemple #1
0
        public async Task Should_add_schema_to_index_on_create()
        {
            var token = RandomHash.Simple();

            A.CallTo(() => index.ReserveAsync(schemaId.Id, schemaId.Name))
            .Returns(token);

            var context =
                new CommandContext(Create(schemaId.Name), commandBus)
                .Complete();

            await sut.HandleAsync(context);

            A.CallTo(() => index.AddAsync(token))
            .MustHaveHappened();

            A.CallTo(() => index.RemoveReservationAsync(A <string> .Ignored))
            .MustNotHaveHappened();
        }
        private static async Task <string?> CheckSchemaAsync(ISchemasByAppIndexGrain index, CreateSchema command)
        {
            var name = command.Name;

            if (name.IsSlug())
            {
                var token = await index.ReserveAsync(command.SchemaId, name);

                if (token == null)
                {
                    throw new ValidationException(T.Get("schemas.nameAlreadyExists"));
                }

                return(token);
            }

            return(null);
        }
Exemple #3
0
        private async Task <string?> CheckSchemaAsync(ISchemasByAppIndexGrain index, CreateSchema command)
        {
            var name = command.Name;

            if (name.IsSlug())
            {
                var token = await index.ReserveAsync(command.SchemaId, name);

                if (token == null)
                {
                    var error = new ValidationError("A schema with this name already exists.");

                    throw new ValidationException("Cannot create schema.", error);
                }

                return(token);
            }

            return(null);
        }