public void CleanUpExistingRecords() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { using (NemeStatsDataContext dataContext = new NemeStatsDataContext(dbContext, new SecuredEntityValidatorFactory())) { var games = dataContext.GetQueryable <GameDefinition>() .Where(game => game.BoardGameGeekGameDefinitionId == null) .ToList(); var bggSearcher = new BoardGameGeekClient(new ApiDownloaderService()); int updateCount = 0; foreach (GameDefinition game in games) { var bggResults = bggSearcher.SearchBoardGames(game.Name.Trim(), true); if (bggResults.Count() == 1) { game.BoardGameGeekGameDefinitionId = bggResults.First().BoardGameId; ApplicationUser user = new ApplicationUser { CurrentGamingGroupId = game.GamingGroupId }; dataContext.Save(game, user); dataContext.CommitAllChanges(); Console.WriteLine(game.Name + " had exactly one match and was updated."); updateCount++; } } Console.WriteLine("Updated " + updateCount + " records."); } } }
public void CleanUpExistingRecords() { using (NemeStatsDbContext dbContext = new NemeStatsDbContext()) { using (NemeStatsDataContext dataContext = new NemeStatsDataContext(dbContext, new SecuredEntityValidatorFactory())) { var games = dataContext.GetQueryable<GameDefinition>() .Where(game => game.BoardGameGeekGameDefinitionId == null) .ToList(); var bggSearcher = new BoardGameGeekClient(new ApiDownloaderService(), new RollbarClient()); int updateCount = 0; foreach (GameDefinition game in games) { var bggResults = bggSearcher.SearchBoardGames(game.Name.Trim(), true); if (bggResults.Count() == 1) { game.BoardGameGeekGameDefinitionId = bggResults.First().BoardGameId; ApplicationUser user = new ApplicationUser { CurrentGamingGroupId = game.GamingGroupId }; dataContext.Save(game, user); dataContext.CommitAllChanges(); Console.WriteLine(game.Name + " had exactly one match and was updated."); updateCount++; } } Console.WriteLine("Updated " + updateCount + " records."); } } }
private static void Cleanup( NemeStatsDataContext dbContext, GamingGroup gamingGroup, ApplicationUser currentUser) { GamingGroup gamingGroupToDelete = dbContext.GetQueryable<GamingGroup>() .Where(game => game.Name == gamingGroup.Name).FirstOrDefault(); if (gamingGroupToDelete != null) { dbContext.Delete(gamingGroupToDelete, currentUser); dbContext.CommitAllChanges(); } }
public virtual ActionResult Delete(int?id, ApplicationUser currentUser) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var playedgame = _dataContext.GetQueryable <PlayedGame>().FirstOrDefault(playedGame => playedGame.Id == id.Value); if (playedgame == null) { return(HttpNotFound()); } return(View(playedgame)); }
private static void Cleanup( NemeStatsDataContext dbContext, GamingGroup gamingGroup, ApplicationUser currentUser) { GamingGroup gamingGroupToDelete = dbContext.GetQueryable <GamingGroup>() .Where(game => game.Name == gamingGroup.Name).FirstOrDefault(); if (gamingGroupToDelete != null) { dbContext.Delete(gamingGroupToDelete, currentUser); dbContext.CommitAllChanges(); } }
public void EagerLoadTest() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { var result = (from gameDefinition in dataContext.GetQueryable<GameDefinition>() .Include(game => game.Champion.Player) where gameDefinition.Id == 2004 select gameDefinition /*select new { Champion = gameDefinition.Champion }*/).First(); Assert.That(result.Champion, Is.Not.Null); Assert.That(result.Champion.Player, Is.Not.Null); } }
public void EagerLoadTest() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { var result = (from gameDefinition in dataContext.GetQueryable <GameDefinition>() .Include(game => game.Champion.Player) where gameDefinition.Id == 2004 select gameDefinition /*select new { * Champion = gameDefinition.Champion * }*/).First(); Assert.That(result.Champion, Is.Not.Null); Assert.That(result.Champion.Player, Is.Not.Null); } }
public void ItReturnsGamesInDescendingOrderByDatePlayed() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); int five = 5; List <PlayedGame> playedGames = retriever.GetRecentGames(five, testUserWithDefaultGamingGroup.CurrentGamingGroupId); List <PlayedGame> allPlayedGames = dataContext.GetQueryable <PlayedGame>() .Where(game => game.GamingGroupId == testUserWithDefaultGamingGroup.CurrentGamingGroupId) .ToList() .OrderByDescending(playedGame => playedGame.DatePlayed) .ToList(); for (int i = 0; i < five; i++) { Assert.AreEqual(allPlayedGames[i].Id, playedGames[i].Id); } } }
public void TestIncludeMethod() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext( new NemeStatsDbContext(), new SecuredEntityValidatorFactory())) { List <Player> players = dataContext.GetQueryable <Player>() .Where(player => player.Active && player.GamingGroupId == 1) .Include(player => player.Nemesis) .Include(player => player.Nemesis.NemesisPlayer) .OrderBy(player => player.Name) .ToList(); List <Player> playersWithNemesisid = players.Where(player => player.NemesisId != null).ToList(); Assert.Greater(playersWithNemesisid.Count, 0); } }
public void TestIncludeMethod() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext( new NemeStatsDbContext(), new SecuredEntityValidatorFactory())) { List<Player> players = dataContext.GetQueryable<Player>() .Where(player => player.Active && player.GamingGroupId == 1) .Include(player => player.Nemesis) .Include(player => player.Nemesis.NemesisPlayer) .OrderBy(player => player.Name) .ToList(); List<Player> playersWithNemesisid = players.Where(player => player.NemesisId != null).ToList(); Assert.Greater(playersWithNemesisid.Count, 0); } }
public void ItReturnsGamesInDescendingOrderByDatePlayed() { using (var dataContext = new NemeStatsDataContext()) { var dateRangeFilter = new BasicDateRangeFilter(); var five = 5; List <PlayedGame> playedGames = _retriever.GetRecentGames(five, testUserWithDefaultGamingGroup.CurrentGamingGroupId.Value, dateRangeFilter); var allPlayedGames = dataContext.GetQueryable <PlayedGame>() .Where(game => game.GamingGroupId == testUserWithDefaultGamingGroup.CurrentGamingGroupId && game.DatePlayed <= dateRangeFilter.ToDate) .ToList() .OrderByDescending(playedGame => playedGame.DatePlayed) .ToList(); for (var i = 0; i < five; i++) { Assert.AreEqual(allPlayedGames[i].Id, playedGames[i].Id); } } }
public void It_Wraps_Updates_In_A_Transaction_Implicitly() { var dataContext = new NemeStatsDataContext(new NemeStatsDbContext(), new SecuredEntityValidatorFactory()); var firstPlayedGame = dataContext.GetQueryable <PlayedGame>().First(); var applicationUserWhoCanSave = new ApplicationUser { CurrentGamingGroupId = firstPlayedGame.GamingGroupId }; firstPlayedGame.Notes = "Integration test note: " + DateTime.UtcNow; dataContext.Save(firstPlayedGame, applicationUserWhoCanSave); var firstGameDefinition = dataContext.GetQueryable <GameDefinition>().First(x => x.GamingGroupId == applicationUserWhoCanSave.CurrentGamingGroupId); int numberOfCharactersToSubstring = firstGameDefinition.Name.Length > 100 ? 100 : firstGameDefinition.Name.Length; firstGameDefinition.Name = (Guid.NewGuid() + firstGameDefinition.Name).Substring(0, numberOfCharactersToSubstring); dataContext.Save(firstGameDefinition, applicationUserWhoCanSave); dataContext.Dispose(); #region See The Sql /* * * Opened connection at 3/24/2017 12:46:07 PM -04:00 * * SELECT TOP (1) * [c].[Id] AS [Id], * [c].[GamingGroupId] AS [GamingGroupId], * [c].[GameDefinitionId] AS [GameDefinitionId], * [c].[WinnerType] AS [WinnerType], * [c].[NumberOfPlayers] AS [NumberOfPlayers], * [c].[DatePlayed] AS [DatePlayed], * [c].[DateCreated] AS [DateCreated], * [c].[DateUpdated] AS [DateUpdated], * [c].[CreatedByApplicationUserId] AS [CreatedByApplicationUserId], * [c].[Notes] AS [Notes] * FROM [dbo].[PlayedGame] AS [c] * * * -- Executing at 3/24/2017 12:46:07 PM -04:00 * * -- Completed in 0 ms with result: SqlDataReader * * * * Closed connection at 3/24/2017 12:46:07 PM -04:00 * * Opened connection at 3/24/2017 12:46:10 PM -04:00 * * SELECT TOP (2) * [Extent1].[Id] AS [Id], * [Extent1].[GamingGroupId] AS [GamingGroupId], * [Extent1].[GameDefinitionId] AS [GameDefinitionId], * [Extent1].[WinnerType] AS [WinnerType], * [Extent1].[NumberOfPlayers] AS [NumberOfPlayers], * [Extent1].[DatePlayed] AS [DatePlayed], * [Extent1].[DateCreated] AS [DateCreated], * [Extent1].[DateUpdated] AS [DateUpdated], * [Extent1].[CreatedByApplicationUserId] AS [CreatedByApplicationUserId], * [Extent1].[Notes] AS [Notes] * FROM [dbo].[PlayedGame] AS [Extent1] * WHERE 4 = [Extent1].[Id] * * * -- Executing at 3/24/2017 12:46:10 PM -04:00 * * -- Completed in 0 ms with result: SqlDataReader * * * * Closed connection at 3/24/2017 12:46:10 PM -04:00 * * Opened connection at 3/24/2017 12:46:10 PM -04:00 * * Started transaction at 3/24/2017 12:46:10 PM -04:00 * * UPDATE [dbo].[PlayedGame] * SET [Notes] = @0 * WHERE ([Id] = @1) * * -- @0: 'Integration test note: 3/24/2017 4:46:09 PM' (Type = String, Size = -1) * * -- @1: '4' (Type = Int32) * * -- Executing at 3/24/2017 12:46:10 PM -04:00 * * -- Completed in 5 ms with result: 1 * * * * Committed transaction at 3/24/2017 12:46:10 PM -04:00 * * Closed connection at 3/24/2017 12:46:10 PM -04:00 * * Opened connection at 3/24/2017 12:46:11 PM -04:00 * * SELECT TOP (1) * [Extent1].[Id] AS [Id], * [Extent1].[GamingGroupId] AS [GamingGroupId], * [Extent1].[Name] AS [Name], * [Extent1].[Description] AS [Description], * [Extent1].[Active] AS [Active], * [Extent1].[DateCreated] AS [DateCreated], * [Extent1].[ChampionId] AS [ChampionId], * [Extent1].[PreviousChampionId] AS [PreviousChampionId], * [Extent1].[BoardGameGeekGameDefinitionId] AS [BoardGameGeekGameDefinitionId] * FROM [dbo].[GameDefinition] AS [Extent1] * WHERE [Extent1].[GamingGroupId] = @p__linq__0 * * * -- p__linq__0: '1' (Type = Int32, IsNullable = false) * * -- Executing at 3/24/2017 12:46:11 PM -04:00 * * -- Completed in 0 ms with result: SqlDataReader * * * * Closed connection at 3/24/2017 12:46:11 PM -04:00 * * Opened connection at 3/24/2017 12:46:13 PM -04:00 * * SELECT TOP (2) * [Extent1].[Id] AS [Id], * [Extent1].[GamingGroupId] AS [GamingGroupId], * [Extent1].[Name] AS [Name], * [Extent1].[Description] AS [Description], * [Extent1].[Active] AS [Active], * [Extent1].[DateCreated] AS [DateCreated], * [Extent1].[ChampionId] AS [ChampionId], * [Extent1].[PreviousChampionId] AS [PreviousChampionId], * [Extent1].[BoardGameGeekGameDefinitionId] AS [BoardGameGeekGameDefinitionId] * FROM [dbo].[GameDefinition] AS [Extent1] * WHERE 27458 = [Extent1].[Id] * * * -- Executing at 3/24/2017 12:46:13 PM -04:00 * * -- Completed in 1 ms with result: SqlDataReader * * * * Closed connection at 3/24/2017 12:46:13 PM -04:00 * * Opened connection at 3/24/2017 12:46:13 PM -04:00 * * Started transaction at 3/24/2017 12:46:13 PM -04:00 * * UPDATE [dbo].[GameDefinition] * SET [Name] = @0 * WHERE ([Id] = @1) * * -- @0: '01b16aaa-faf1-4c9a-9798-161bddf9dde' (Type = String, Size = 255) * * -- @1: '27458' (Type = Int32) * * -- Executing at 3/24/2017 12:46:13 PM -04:00 * * -- Completed in 1 ms with result: 1 * * * * Committed transaction at 3/24/2017 12:46:13 PM -04:00 * * Closed connection at 3/24/2017 12:46:13 PM -04:00 * * */ #endregion }
public void ItReturnsGamesInDescendingOrderByDatePlayed() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { PlayedGameRetriever retriever = new PlayedGameRetriever(dataContext); int five = 5; List<PlayedGame> playedGames = retriever.GetRecentGames(five, testUserWithDefaultGamingGroup.CurrentGamingGroupId); List<PlayedGame> allPlayedGames = dataContext.GetQueryable<PlayedGame>() .Where(game => game.GamingGroupId == testUserWithDefaultGamingGroup.CurrentGamingGroupId) .ToList() .OrderByDescending(playedGame => playedGame.DatePlayed) .ToList(); for(int i = 0; i<five; i++) { Assert.AreEqual(allPlayedGames[i].Id, playedGames[i].Id); } } }