/// <summary> /// Create a room. For internal use by the Games SDK only. Calling this method directly is unsupported. /// Documentation https://developers.google.com/games/v1/reference/rooms/create /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>RoomResponse</returns> public static Room Create(GamesService service, RoomCreateRequest body, RoomsCreateOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Rooms.Create(body); // Applying optional parameters to the request. request = (RoomsResource.CreateRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Rooms.Create failed.", ex); } }
/// <summary> /// Retrieves the metadata of the leaderboard with the given ID. /// Documentation https://developers.google.com/games/v1/reference/leaderboards/get /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="leaderboardId">The ID of the leaderboard.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>LeaderboardResponse</returns> public static Leaderboard Get(GamesService service, string leaderboardId, LeaderboardsGetOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (leaderboardId == null) { throw new ArgumentNullException(leaderboardId); } // Building the initial request. var request = service.Leaderboards.Get(leaderboardId); // Applying optional parameters to the request. request = (LeaderboardsResource.GetRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Leaderboards.Get failed.", ex); } }
public async Task TakeNewShouldGetTwo() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); var repository = new EfRepository <Game>(context); var service = new GamesService(repository); var models = new List <SuggestionToGameViewModel> { new SuggestionToGameViewModel() { Title = "test", Description = "test", ImageUrl = "test", }, new SuggestionToGameViewModel() { Title = "test1", Description = "test", ImageUrl = "test", }, }; foreach (var model in models) { await service.AddAsync(model); } var actual = await service.TakeNewAsync <NewGamesViewModel>(); Assert.Equal(2, actual.Count()); }
public async Task GetGames() { try { if (IsBusy) { return; } IsBusy = true; var gamesService = new GamesService(); var games = await gamesService.GetGamesAsync(Constants.GetGamesUri(_selectedDay)); GamesList.Clear(); foreach (var game in games) { GamesList.Add(new GameViewModel() { GameModel = game }); } int sI = GamesList.Count / 2; SelectedGame = GamesList[sI]; } catch (Exception ex) { Debug.WriteLine("Error : " + ex.Message); } finally { IsBusy = false; } }
public CartServiceTest() { AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly); this.userCartItemsRepo = new Mock <IDeletableEntityRepository <UserCartItem> >(); this.gamesRepo = new Mock <IDeletableEntityRepository <Game> >(); this.cartItemsList = new List <UserCartItem>(); this.cartService = new CartService(this.userCartItemsRepo.Object, this.gamesRepo.Object); this.userCartItemsRepo.Setup(x => x.All()).Returns(this.cartItemsList.AsQueryable()); this.userCartItemsRepo.Setup(x => x.AddAsync(It.IsAny <UserCartItem>())).Callback( (UserCartItem item) => this.cartItemsList.Add(item)); this.userCartItemsRepo.Setup(x => x.Delete(It.IsAny <UserCartItem>())).Callback( (UserCartItem item) => this.cartItemsList.Remove(item)); this.userCartItemsRepo.Setup(x => x.HardDelete(It.IsAny <UserCartItem>())).Callback( (UserCartItem item) => this.cartItemsList.Remove(item)); this.gamesRepo = new Mock <IDeletableEntityRepository <Game> >(); this.languagesRepo = new Mock <IDeletableEntityRepository <Language> >(); this.tagsRepo = new Mock <IDeletableEntityRepository <Tag> >(); this.orderItemsRepo = new Mock <IRepository <OrderItem> >(); this.gamesList = new List <Game>(); this.gamesService = new GamesService( this.gamesRepo.Object, this.languagesRepo.Object, this.tagsRepo.Object, this.orderItemsRepo.Object); this.gamesRepo.Setup(x => x.All()).Returns(this.gamesList.AsQueryable()); this.gamesRepo.Setup(x => x.AllAsNoTracking()).Returns(this.gamesList.AsQueryable()); this.gamesRepo.Setup(x => x.AddAsync(It.IsAny <Game>())).Callback( (Game game) => this.gamesList.Add(game)); }
public PlayerResult Get(int id) { var dataCache = new DataCache(); var player = PlayersService.GetInstance().GetPlayer(id, dataCache); var sports = SportsService.GetInstance().GetSports(); var leagues = LeaguesService.GetInstance().GetLeagues(); var stats = StatsService.GetInstance().GetAllStats(playerID: id, dataCache: dataCache); var statTypes = GamesService.GetInstance().GetStatTypes().OrderBy(s => s.GridDisplayOrder); var playerResult = new PlayerResult() { ID = player.ID, Name = player.Name, Games = player.Games?.Select(g => new PlayerGameResult() { ID = g.ID, GameDate = g.GameDate, Team1Score = g.Team1Score, Team2Score = g.Team2Score }).ToList(), Teams = player.Teams?.Select(t => { var league = leagues.First(l => l.ID == t.LeagueID); var sport = sports.First(s => s.ID == league.SportID); return(new PlayerTeamResult() { ID = t.ID, Name = t.Name, LeagueID = t.LeagueID, Number = t.PlayerNumber, SportID = league.SportID, LeagueName = string.Format("{0} - {1} {2} - {3}", sport.Name, league.StartDate.Year, league.Season.ToString(), league.Name) }); }).OrderBy(t => t.LeagueName).ToList(), HockeyStats = stats .Select(s => ConvertObjects.ConvertType(s)) .Where(s => s.Sport == SportsList.Hockey && leagues.Exists(l => l.ID == s.LeagueID)) .OrderBy(s => leagues.First(l => l.ID == s.LeagueID).StartDate) .ToList(), BaseballStats = stats .Select(s => ConvertObjects.ConvertType(s)) .Where(s => s.Sport == SportsList.Baseball && leagues.Exists(l => l.ID == s.LeagueID)) .OrderBy(s => leagues.First(l => l.ID == s.LeagueID).StartDate) .ToList(), BasketballStats = stats .Select(s => ConvertObjects.ConvertType(s)) .Where(s => s.Sport == SportsList.Basketball && leagues.Exists(l => l.ID == s.LeagueID)) .OrderBy(s => leagues.First(l => l.ID == s.LeagueID).StartDate) .ToList(), HockeyStatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).Where(st => st.Sport == SportsList.Hockey).ToList(), BaseballStatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).Where(st => st.Sport == SportsList.Baseball).ToList(), BasketballStatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).Where(st => st.Sport == SportsList.Basketball).ToList(), }; UpdateStatRow(playerResult.HockeyStats, player, leagues); UpdateStatRow(playerResult.BaseballStats, player, leagues); UpdateStatRow(playerResult.BasketballStats, player, leagues); return(playerResult); }
public IHttpActionResult Get(int id, int?unionId = null) { int?seasonId = unionId != null?_seasonsRepo.GetLastSeasonByCurrentUnionId(unionId.Value) : (int?)null; var game = GamesService.GetGameById(id, seasonId); if (game == null) { return(NotFound()); } var section = _sectionRepo.GetByLeagueId(game.LeagueId)?.Alias; GamesService.UpdateGameSet(game, section); var vm = new GamePageViewModel { GameInfo = game }; if (User.Identity.IsAuthenticated) { vm.GoingFriends = GetTeamsFansList(id); } vm.Sets = GamesService.GetGameSets(id).ToList(); vm.History = GamesService.GetGameHistory(game.GuestTeamId, game.HomeTeamId); GamesService.UpdateGameSets(vm.History); GamesService.UpdateGameSet(vm.GameInfo, section); return(Ok(vm)); }
public async void CanCreateUpdateAndSaveToDatabase() { DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>() .UseInMemoryDatabase("CanCreateUpdateAndSaveToDatabase") .Options; using GuildAPIDbContext context = new GuildAPIDbContext(options); GamesService service = new GamesService(context); GamesDTO dto = new GamesDTO() { Name = "Bryants Deluxe Game Edition" }; Assert.Equal(0, context.Games.CountAsync().Result); var result = await service.Create(dto); GamesDTO gamesDTO = new GamesDTO() { Id = 1, Name = "Legends of Lesley" }; var update = service.Update(gamesDTO); var actual = context.Games.FindAsync(update.Result.Id).Result; Assert.Equal(1, context.Games.CountAsync().Result); // Assert.IsType<Games>(actual); Assert.Equal(1, update.Id); Assert.Equal("Legends of Lesley", actual.Name); }
public async void CanGetGameFromDatabase() { DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>() .UseInMemoryDatabase("CanGetGameFromDatabase") .Options; using GuildAPIDbContext context = new GuildAPIDbContext(options); GamesService service = new GamesService(context); GamesDTO dto = new GamesDTO() { Name = "Bryants Deluxe Game Edition" }; Assert.Equal(0, context.Games.CountAsync().Result); var result = await service.Create(dto); Assert.Equal(1, context.Games.CountAsync().Result); var get = service.GetGame(result.Id); Assert.Equal(1, get.Result.Id); Assert.IsType <GamesDTO>(get.Result); Assert.Equal("Bryants Deluxe Game Edition", get.Result.Name); // Assert.IsType<Games>(actual); }
public void CanDeleteGuildAndSaveToDatabase() { DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>() .UseInMemoryDatabase("CanDeleteGuildAndSaveToDatabase") .Options; using GuildAPIDbContext context = new GuildAPIDbContext(options); GamesService gameService = new GamesService(context); GamesDTO gamesDTO = new GamesDTO() { Name = "Odins Game" }; var createdGame = gameService.Create(gamesDTO); GuildService guildService = new GuildService(context, gameService); Assert.Equal(1, context.Games.CountAsync().Result); GuildsDTO guild = new GuildsDTO() { Name = "Odin Slayers" }; var creation = guildService.Create(guild); var association = gameService.AddGameGuild(createdGame.Result.Id, creation.Result.Id); Assert.Equal(1, context.Guilds.CountAsync().Result); var delete = guildService.Delete(creation.Result.Id); Assert.Equal(0, context.Guilds.CountAsync().Result); }
public void CanGetGuildFromDatabase() { DbContextOptions <GuildAPIDbContext> options = new DbContextOptionsBuilder <GuildAPIDbContext>() .UseInMemoryDatabase("CanGetGuildFromDatabase") .Options; using GuildAPIDbContext context = new GuildAPIDbContext(options); GamesService gameService = new GamesService(context); GamesDTO gamesDTO = new GamesDTO() { Name = "Odins Game" }; var createdGame = gameService.Create(gamesDTO); GuildService guildService = new GuildService(context, gameService); Assert.Equal(1, context.Games.CountAsync().Result); GuildsDTO guild = new GuildsDTO() { Name = "Odin Slayers" }; var creation = guildService.Create(guild); var association = gameService.AddGameGuild(createdGame.Result.Id, creation.Result.Id); var actual = guildService.GetGuild(creation.Result.Id).Result; Assert.Equal(1, context.Guilds.CountAsync().Result); Assert.IsType <GuildsDTO>(actual); Assert.Equal(1, actual.Id); Assert.Equal("Odin Slayers", actual.Name); }
/// <summary> /// Records a batch of changes to the number of times events have occurred for the currently authenticated user of this application. /// Documentation https://developers.google.com/games/v1/reference/events/record /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>EventUpdateResponseResponse</returns> public static EventUpdateResponse Record(GamesService service, EventRecordRequest body, EventsRecordOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Events.Record(body); // Applying optional parameters to the request. request = (EventsResource.RecordRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Events.Record failed.", ex); } }
/// <summary> /// Commit the results of a player turn. /// Documentation https://developers.google.com/games/v1/reference/turnBasedMatches/takeTurn /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="matchId">The ID of the match.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>TurnBasedMatchResponse</returns> public static TurnBasedMatch TakeTurn(GamesService service, string matchId, TurnBasedMatchTurn body, TurnBasedMatchesTakeTurnOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (matchId == null) { throw new ArgumentNullException(matchId); } // Building the initial request. var request = service.TurnBasedMatches.TakeTurn(body, matchId); // Applying optional parameters to the request. request = (TurnBasedMatchesResource.TakeTurnRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request TurnBasedMatches.TakeTurn failed.", ex); } }
/// <summary> /// List play data aggregated per category for the player corresponding to playerId. /// Documentation https://developers.google.com/games/v1/reference/metagame/listCategoriesByPlayer /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="playerId">A player ID. A value of me may be used in place of the authenticated player's ID.</param> /// <param name="collection">The collection of categories for which data will be returned.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>CategoryListResponseResponse</returns> public static CategoryListResponse ListCategoriesByPlayer(GamesService service, string playerId, string collection, MetagameListCategoriesByPlayerOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (playerId == null) { throw new ArgumentNullException(playerId); } if (collection == null) { throw new ArgumentNullException(collection); } // Building the initial request. var request = service.Metagame.ListCategoriesByPlayer(playerId, collection); // Applying optional parameters to the request. request = (MetagameResource.ListCategoriesByPlayerRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Metagame.ListCategoriesByPlayer failed.", ex); } }
private GamesResult GetGamesResult(int leagueID) { var dataCache = new DataCache(); var teams = TeamsService.GetInstance().GetTeams(leagueID: leagueID, showAll: true, dataCache: dataCache); var games = GamesService.GetInstance().GetGames(leagueID: leagueID, dataCache: dataCache); var gamesResult = new GamesResult() { Teams = teams.Select(t => new TeamsResult() { ID = t.ID, Name = t.Name }).ToList(), Games = games.Select(g => new GameResultBase() { ID = g.ID, GameDate = g.GameDate, Team1ID = g.Team1ID, Team1Name = teams.FirstOrDefault(tm1 => tm1.ID == g.Team1ID)?.Name, Team1Score = g.Team1Score, Team2ID = g.Team2ID, Team2Name = teams.FirstOrDefault(tm2 => tm2.ID == g.Team2ID)?.Name, Team2Score = g.Team2Score }).ToList() }; return(gamesResult); }
public ActionResult FinishGameSession(int gameSessionId) { AccessGuardian(Roles.AccessUser); GamesService.FinishGameSession(gameSessionId); return(JsonHelper.Success("zakończono sesje")); }
/// <summary> /// Increments the steps of the achievement with the given ID for the currently authenticated player. /// Documentation https://developers.google.com/games/v1/reference/achievements/increment /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="achievementId">The ID of the achievement used by this method.</param> /// <param name="stepsToIncrement">The number of steps to increment.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>AchievementIncrementResponseResponse</returns> public static AchievementIncrementResponse Increment(GamesService service, string achievementId, int?stepsToIncrement, AchievementsIncrementOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (achievementId == null) { throw new ArgumentNullException(achievementId); } if (stepsToIncrement == null) { throw new ArgumentNullException(stepsToIncrement); } // Building the initial request. var request = service.Achievements.Increment(achievementId, stepsToIncrement); // Applying optional parameters to the request. request = (AchievementsResource.IncrementRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Achievements.Increment failed.", ex); } }
/// <summary> /// Removes a push token for the current user and application. Removing a non-existent push token will report success. /// Documentation https://developers.google.com/games/v1/reference/pushtokens/remove /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> public static void Remove(GamesService service, PushTokenId body, PushtokensRemoveOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Pushtokens.Remove(body); // Applying optional parameters to the request. request = (PushtokensResource.RemoveRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. request.Execute(); } catch (Exception ex) { throw new Exception("Request Pushtokens.Remove failed.", ex); } }
/// <summary> /// Lists the progress for all your application's achievements for the currently authenticated player. /// Documentation https://developers.google.com/games/v1/reference/achievements/list /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="playerId">A player ID. A value of me may be used in place of the authenticated player's ID.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>PlayerAchievementListResponseResponse</returns> public static PlayerAchievementListResponse List(GamesService service, string playerId, AchievementsListOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (playerId == null) { throw new ArgumentNullException(playerId); } // Building the initial request. var request = service.Achievements.List(playerId); // Applying optional parameters to the request. request = (AchievementsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Achievements.List failed.", ex); } }
/// <summary> /// Updates multiple achievements for the currently authenticated player. /// Documentation https://developers.google.com/games/v1/reference/achievements/updateMultiple /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>AchievementUpdateMultipleResponseResponse</returns> public static AchievementUpdateMultipleResponse UpdateMultiple(GamesService service, AchievementUpdateMultipleRequest body, AchievementsUpdateMultipleOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Achievements.UpdateMultiple(body); // Applying optional parameters to the request. request = (AchievementsResource.UpdateMultipleRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Achievements.UpdateMultiple failed.", ex); } }
/// <summary> /// Indicates that the currently authorized user will participate in the quest. /// Documentation https://developers.google.com/games/v1/reference/quests/accept /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="questId">The ID of the quest.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>QuestResponse</returns> public static Quest Accept(GamesService service, string questId, QuestsAcceptOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (questId == null) { throw new ArgumentNullException(questId); } // Building the initial request. var request = service.Quests.Accept(questId); // Applying optional parameters to the request. request = (QuestsResource.AcceptRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Quests.Accept failed.", ex); } }
/// <summary> /// Logs into the YouTube API's Servers. /// </summary> internal void Login() { this.OClient = new GamesService(new BaseClientService.Initializer { HttpClientInitializer = this.OCredentials, ApplicationName = "GL.Servers.HD", ApiKey = "AIzaSyAr6oXL0O52iM2y3qx_1edjLls4LAAows8" }); }
/// <summary> /// Verifies the auth token provided with this request is for the application with the specified ID, and returns the ID of the player it was granted for. /// Documentation https://developers.google.com/games/v1/reference/applications/verify /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="applicationId">The application ID from the Google Play developer console.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>ApplicationVerifyResponseResponse</returns> public static ApplicationVerifyResponse Verify(GamesService service, string applicationId, ApplicationsVerifyOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (applicationId == null) { throw new ArgumentNullException(applicationId); } // Building the initial request. var request = service.Applications.Verify(applicationId); // Applying optional parameters to the request. request = (ApplicationsResource.VerifyRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Applications.Verify failed.", ex); } }
public void SaveOrder([FromBody] StatRequest statRequest) { var gameStat = ConvertObjects.ConvertType(statRequest); gameStat.Override = true; GamesService.GetInstance().AddStat(gameStat); }
/// <summary> /// Submits a score to the specified leaderboard. /// Documentation https://developers.google.com/games/v1/reference/scores/submit /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="leaderboardId">The ID of the leaderboard.</param> /// <param name="score">The score you're submitting. The submitted score is ignored if it is worse than a previously submitted score, where worse depends on the leaderboard sort order. The meaning of the score value depends on the leaderboard format type. For fixed-point, the score represents the raw value. For time, the score represents elapsed time in milliseconds. For currency, the score represents a value in micro units.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>PlayerScoreResponseResponse</returns> public static PlayerScoreResponse Submit(GamesService service, string leaderboardId, string score, ScoresSubmitOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (leaderboardId == null) { throw new ArgumentNullException(leaderboardId); } if (score == null) { throw new ArgumentNullException(score); } // Building the initial request. var request = service.Scores.Submit(leaderboardId, score); // Applying optional parameters to the request. request = (ScoresResource.SubmitRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Scores.Submit failed.", ex); } }
/// <summary> /// Submits multiple scores to leaderboards. /// Documentation https://developers.google.com/games/v1/reference/scores/submitMultiple /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Games service.</param> /// <param name="body">A valid Games v1 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>PlayerScoreListResponseResponse</returns> public static PlayerScoreListResponse SubmitMultiple(GamesService service, PlayerScoreSubmissionList body, ScoresSubmitMultipleOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Scores.SubmitMultiple(body); // Applying optional parameters to the request. request = (ScoresResource.SubmitMultipleRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Scores.SubmitMultiple failed.", ex); } }
static void Main(string[] args) { var gamesService = new GamesService(new EFRepository <Game>(new MonolithicStore.DataAccess.AppContext())); System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(gamesService, new Uri("http://localhost:8733/Design_Time_Addresses/GamesStore")); host.AddServiceEndpoint(typeof(IGamesService), new BasicHttpBinding(), ""); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri("http://localhost:8733/Design_Time_Addresses/GamesStore/mex"); host.Description.Behaviors.Add(smb); Console.WriteLine("Opening..."); host.Open(); Console.WriteLine("Opened"); Console.WriteLine("Press exit to exit"); while (Console.ReadLine() != "exit") { } }
public void GetAllGames_ShouldReturn_All_GameViewModels() { var gameRepoBuilder = new GameRepositoryBuilder(); var gameRepo = gameRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var sut = new GamesService(gameRepo, levelRepo, null, null, Mapper); var actual = sut.GetAllGames(); var expected = new List <GameViewModel> { new GameViewModel { Id = "7", Name = "Nameri mqstoto", Image = levelRepo.All().FirstOrDefault(l => l.GameId == "7" && l.NumberInGame == 3).Image }, new GameViewModel { Id = "9", Name = "Na more", Image = levelRepo.All().FirstOrDefault(l => l.GameId == "9" && l.NumberInGame == 3).Image } }.AsQueryable(); Assert.Equal(expected, actual, new GameViewModelComparer()); gameRepoBuilder.GamesRepoMock.Verify(); }
public async Task UserStartGame_ShouldDoNotAddUserToGame_IfUserAureadyExistInThisGame() { var gameRepoBuilder = new GameRepositoryBuilder(); var gameRepo = gameRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(gameRepo, levelRepo, levelsParticipantsRepo, null, Mapper); var user = new GoUser { Id = "10" }; await sut.UserStartGame("7", user); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.AddRangeAsync(It.IsAny <List <GameLevelParticipant> >()), Times.Never); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); gameRepoBuilder.GamesRepoMock.Verify(); levelsRepoBuilder.LevelsRepoMock.Verify(); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(); }
public async Task UserStartGame_ShouldThrowIfGameNotExist() { var gameRepoBuilder = new GameRepositoryBuilder(); var gameRepo = gameRepoBuilder .WithAll() .Build(); var levelsRepoBuilder = new LevelRepositoryBuilder(); var levelRepo = levelsRepoBuilder .WithAll() .Build(); var levelsParticipantsRepoBuilder = new GameLevelParticipantRepositoryBuilder(); var levelsParticipantsRepo = levelsParticipantsRepoBuilder .WithAll() .Build(); var sut = new GamesService(gameRepo, levelRepo, levelsParticipantsRepo, null, Mapper); var user = new GoUser { Id = "1" }; var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await sut.UserStartGame("11", user)); Assert.Equal("Game do not exist!", ex.Message); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.AddRangeAsync(It.IsAny <List <GameLevelParticipant> >()), Times.Never); levelsParticipantsRepoBuilder.LevelParticipantRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never); gameRepoBuilder.GamesRepoMock.Verify(); levelsRepoBuilder.LevelsRepoMock.Verify(); }
public ActionResult Play(Guid id) { using (var gamesService = new GamesService()) { var session = gamesService.GetSession(id, User.Identity.GetUserId()); return View(session); } }
public ActionResult Index() { if (Request.IsAuthenticated) { using (var gamesService = new GamesService()) { var sessions = gamesService.GetActiveSessionsForUser(User.Identity.GetUserId()); return View("Dashboard", sessions); } } else { return View(); } }
public ActionResult Create(CreateGameViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Hay un error con los correos. Veríficalos y vuelve a intentarlo"); return View(model); } var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); using (var gamesService = new GamesService()) { string first; string second; string third; string fourth; try { first = User.Identity.GetUserId(); second = userManager.FindByEmail(model.Email2).Id; third = userManager.FindByEmail(model.Email3).Id; fourth = userManager.FindByEmail(model.Email4).Id; } catch (Exception) { ModelState.AddModelError("", "Hay un error con los correos. Veríficalos y vuelve a intentarlo"); return View(model); } var set = new HashSet<string>(new[] { first, second, third, fourth }); if (set.Count != 4) { ModelState.AddModelError("", "No puedes invitar a un amigo más de una vez"); return View(model); } var sessionId = gamesService.Create(first, second, third, fourth); return RedirectToAction("Play", new { id = sessionId }); } }