Beispiel #1
0
        public async Task InitiateGame(Guid[] players)
        {
            try
            {
                Game game = new Game
                {
                    State     = GameState.PLAYERS_CONNECTING,
                    Link      = ShortUrlGenerator.Generate(),
                    UserGames = players.Select(p =>
                    {
                        var x = new UserGame
                        {
                            UserId = p
                        };

                        return(x);
                    }).ToList()
                };

                _dbContext.Games.Add(game);
                _dbContext.SaveChanges();

                foreach (var player in players)
                {
                    await _lobbyBroadcaster.SendGameFound(player, game.Link);
                }
            }
            catch (Exception ex)
            {
            }
            return;
        }
        /**
         * metoda vraca registrirani URL
         *
         * Ako za korisnika 'Account' vec postoji URL kao u 'Request'u, onda vraćamo taj postojeći objekt iz baze
         * Ako URL ne postoji, kreiramo novi RegisteredUrl, spremamo u bazu i vraćamo ga
         */
        public RegisteredUrl CreateRegisteredUrl(RegisterUrlRequestBody Request, string Account)
        {
            //pokusavamo naci url u bazi podataka. ako postoji, provjeravamo da li pripada ovom accountu.
            //ako je sve zo zadovoljeno, nema potrebe kreirati novi zapis, nego vracamo stari
            RegisteredUrl findUrl = _context.RegisteredUrls.FirstOrDefault(databaseUrl => databaseUrl.LongUrl == Request.url && databaseUrl.AccountID == Account);

            if (findUrl != null)
            {
                return(findUrl);
            }
            else
            {
                //URL ne postoji, kreiramo novi zapis u bazi i vracamo novi RegisteredUrl objekt
                RegisteredUrl registeredUrl = new RegisteredUrl()
                {
                    LongUrl = Request.url, ShortUrl = ShortUrlGenerator.Generate(10), AccountID = Account
                };
                if (Request.redirectType > 0)
                {
                    registeredUrl.RedirectType = Request.redirectType;
                }
                else
                {
                    registeredUrl.RedirectType = 302;
                }
                _context.RegisteredUrls.Add(registeredUrl);
                _context.SaveChanges();
                return(registeredUrl);
            }
        }
Beispiel #3
0
        public void ShortUrlGenerator_NotNull()
        {
            var code = ShortUrlGenerator.Generate();

            Assert.NotNull(code);
        }
Beispiel #4
0
        public void ShortUrlGenerator_Code_Length_Greater_Then_One()
        {
            var code = ShortUrlGenerator.Generate();

            Assert.True(code.Length > 1, "code length to be greater than 1");
        }