示例#1
0
        public async Task Should_add_app_to_indexes_on_create()
        {
            var token = RandomHash.Simple();

            A.CallTo(() => indexByName.ReserveAsync(appId.Id, appId.Name))
            .Returns(token);

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

            await sut.HandleAsync(context);

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

            A.CallTo(() => indexByName.RemoveReservationAsync(A <string> .Ignored))
            .MustNotHaveHappened();

            A.CallTo(() => indexByUser.AddAsync(appId.Id))
            .MustHaveHappened();
        }
示例#2
0
        private static async Task <string?> CheckAppAsync(IAppsByNameIndexGrain index, CreateApp command)
        {
            var name = command.Name;

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

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

                return(token);
            }

            return(null);
        }
示例#3
0
        private static async Task <string?> CheckAppAsync(IAppsByNameIndexGrain index, CreateApp command)
        {
            var name = command.Name;

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

                if (token == null)
                {
                    var error = new ValidationError("An app with this already exists.");

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

                return(token);
            }

            return(null);
        }