コード例 #1
0
        public void It_Doesnt_Get_Exceptions_While_Processing_Lots_Of_Events_For_The_Same_Player()
        {
            //--arrange

            //--act
            var playedGameEvent = new PlayedGameCreatedEvent
            {
                //--any playedGame from the integration test base should be sufficient to generate at least one achievement
                TriggerEntityId = testPlayedGames[0].Id
            };
            var taskList        = new List <Task <bool> >();
            var dataContexts    = new List <NemeStatsDataContext>();
            int NUMBER_OF_CALLS = 3;

            for (int i = 0; i < NUMBER_OF_CALLS; i++)
            {
                var dataContext = new NemeStatsDataContext();
                dataContexts.Add(dataContext);
            }
            for (int i = 0; i < NUMBER_OF_CALLS; i++)
            {
                var achievementsEventHandler = new AchievementsEventHandler(dataContexts[i], MockRepository.GenerateMock <IRollbarClient>());

                var lastTask = new Task <bool>(() => achievementsEventHandler.Handle(playedGameEvent));
                lastTask.Start();
                taskList.Add(lastTask);
            }

            try
            {
                if (taskList.Any(task => !task.Result))
                {
                    throw new AssertionException("There was an exception from one of the tasks.");
                }
            }
            finally
            {
                foreach (var dataContext in dataContexts)
                {
                    try
                    {
                        dataContext.Dispose();
                    }
                    catch (Exception)
                    {
                        //squish
                    }
                }
            }
        }
コード例 #2
0
        public void It_Doesnt_Get_Exceptions_While_Processing_Lots_Of_Events_For_The_Same_Player()
        {
            //--arrange

            //--act
            var playedGameEvent = new PlayedGameCreatedEvent
            {
                //--any playedGame from the integration test base should be sufficient to generate at least one achievement
                TriggerEntityId = testPlayedGames[0].Id
            };
            var taskList = new List<Task<bool>>();
            var dataContexts = new List<NemeStatsDataContext>();
            int NUMBER_OF_CALLS = 3;
            for (int i = 0; i < NUMBER_OF_CALLS; i++)
            {
                var dataContext = new NemeStatsDataContext();
                dataContexts.Add(dataContext);
            }
            for (int i = 0; i < NUMBER_OF_CALLS; i++)
            {
                var achievementsEventHandler = new AchievementsEventHandler(dataContexts[i], MockRepository.GenerateMock<IRollbarClient>());

                var lastTask = new Task<bool>(() => achievementsEventHandler.Handle(playedGameEvent));
                lastTask.Start();
                taskList.Add(lastTask);
            }

            try
            {
                if (taskList.Any(task => !task.Result))
                {
                    throw new AssertionException("There was an exception from one of the tasks.");
                }
            }
            finally
            {
                foreach (var dataContext in dataContexts)
                {
                    try
                    {
                        dataContext.Dispose();
                    }
                    catch (Exception)
                    {
                        //squish
                    }
                }
            }
        }
コード例 #3
0
        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
        }
コード例 #4
0
        public void It_Doesnt_Get_Exceptions_While_Processing_Lots_Of_Events_For_The_Same_Player()
        {
            //--arrange

            //--act
            //--any playedGame from the integration test base should be sufficient to generate at least one achievement
            var playedGameEvent = new PlayedGameCreatedEvent(
                testPlayedGames[0].Id,
                testPlayedGames[0].GameDefinitionId,
                testPlayedGames[0].PlayerGameResults.Select(x => x.PlayerId).ToList(),
                TransactionSource.RestApi,
                testUserWithDefaultGamingGroup);

            var taskList        = new List <Task <bool> >();
            var dataContexts    = new List <NemeStatsDataContext>();
            int NUMBER_OF_CALLS = 3;

            for (int i = 0; i < NUMBER_OF_CALLS; i++)
            {
                var dataContext = new NemeStatsDataContext();
                dataContexts.Add(dataContext);
            }

            for (int i = 0; i < NUMBER_OF_CALLS; i++)
            {
                var achievementsEventHandler = new PlayedGameEventHandler(
                    dataContexts[i],
                    MockRepository.GenerateMock <INemeStatsEventTracker>(),
                    MockRepository.GenerateMock <IAchievementProcessor>(),
                    MockRepository.GenerateMock <IChampionRecalculator>(),
                    MockRepository.GenerateMock <INemesisRecalculator>(),
                    MockRepository.GenerateMock <IGamingGroupChampionRecalculator>(),
                    MockRepository.GenerateMock <IRollbarClient>());

                var lastTask = new Task <bool>(() => achievementsEventHandler.Handle(playedGameEvent));
                lastTask.Start();
                taskList.Add(lastTask);
            }

            try
            {
                if (taskList.Any(task => !task.Result))
                {
                    throw new AssertionException("There was an exception from one of the tasks.");
                }
            }
            finally
            {
                foreach (var dataContext in dataContexts)
                {
                    try
                    {
                        dataContext.Dispose();
                    }
                    catch (Exception)
                    {
                        //squish
                    }
                }
            }
        }
コード例 #5
0
 public void TearDown()
 {
     dataContext.Dispose();
 }