Beispiel #1
0
        public async Task <string> GenerateKeyAsync(string gameName, string separator)
        {
            if (string.IsNullOrWhiteSpace(gameName))
            {
                throw new InvalidServiceOperationException("Is empty game name");
            }

            var key    = gameName.ToLower().Replace(" ", separator);
            var exists = await _gameDecorator.AnyAsync(g => g.Key == key);

            if (!exists)
            {
                return(key);
            }

            var uniqueKey = await GenerateUniqueKeyAsync(key);

            return(uniqueKey);
        }
Beispiel #2
0
        public void GenerateKeyAsync_AddsNumberToKey_WhenExistsSameKey()
        {
            const string expectedKey       = "grand4";
            const string input             = "Grand";
            var          testGamesSequence = CreateGameRoots();

            A.CallTo(() => _gameDecorator.AnyAsync(A <Expression <Func <GameRoot, bool> > > ._))
            .Returns(true);
            A.CallTo(() => _gameDecorator.FindAllAsync(A <Expression <Func <GameRoot, bool> > > ._))
            .Returns(testGamesSequence);

            var key = _gameServices.GenerateKeyAsync(input, Separator).Result;

            key.Should().BeEquivalentTo(expectedKey);
        }