示例#1
0
        private async Task <string?> CheckAppAsync(IAppsCacheGrain cache, CreateApp command)
        {
            var token = await cache.ReserveAsync(command.AppId, command.Name);

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

            try
            {
                var existingId = await GetAppIdAsync(command.Name);

                if (existingId != default)
                {
                    throw new ValidationException(T.Get("apps.nameAlreadyExists"));
                }
            }
            catch
            {
                // Catch our own exception, just in case something went wrong before.
                await cache.RemoveReservationAsync(token);

                throw;
            }

            return(token);
        }
示例#2
0
        public async Task Should_add_app_to_indexes_if_creating()
        {
            var token = RandomHash.Simple();

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

            var command = Create(appId.Name);

            var context =
                new CommandContext(command, commandBus)
                .Complete();

            await sut.HandleAsync(context);

            A.CallTo(() => cache.AddAsync(appId.Id, appId.Name))
            .MustHaveHappened();

            A.CallTo(() => cache.RemoveReservationAsync(token))
            .MustHaveHappened();
        }