public void It_Processes_Analytics_Events_Then_Badges_Then_Champions_Then_Nemeses_Then_Achievements() { //--arrange var playersInGame = new List <int> { 10, 11 }; var playedGameEvent = new PlayedGameCreatedEvent(1, 2, playersInGame, TransactionSource.RestApi, new AnonymousApplicationUser()); var anonymousApplicationUser = new AnonymousApplicationUser(); //--act _autoMocker.ClassUnderTest.Handle(playedGameEvent); //--assert //--make sure event tracking was called but not yet the champion recalculator _autoMocker.Get <INemeStatsEventTracker>().AssertWasCalled(mock => mock.TrackPlayedGame( Arg <ApplicationUser> .Is.Equal(anonymousApplicationUser), Arg <TransactionSource> .Is.Equal(playedGameEvent.TransactionSource)), options => options.WhenCalled(y => _autoMocker.Get <IChampionRecalculator>().AssertWasNotCalled( mock => mock.RecalculateChampion(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything, Arg <IDataContext> .Is.Anything)))); //--make sure the champion recalculator was called but not yet the nemesis recalculator _autoMocker.Get <IChampionRecalculator>().AssertWasCalled( mock => mock.RecalculateChampion( Arg <int> .Is.Equal(playedGameEvent.GameDefinitionId), Arg <ApplicationUser> .Is.Equal(anonymousApplicationUser), Arg <IDataContext> .Is.Anything, Arg <bool> .Is.Anything), options => options.WhenCalled(y => _autoMocker.Get <INemesisRecalculator>().AssertWasNotCalled( mock => mock.RecalculateNemesis(Arg <int> .Is.Equal(playersInGame[0]), Arg <ApplicationUser> .Is.Equal(anonymousApplicationUser), Arg <IDataContext> .Is.Anything)))); //--make sure the nemesis recalculator was called for the first player in the game, but not yet the achievement processor _autoMocker.Get <INemesisRecalculator>().AssertWasCalled( mock => mock.RecalculateNemesis( Arg <int> .Is.Equal(playersInGame[0]), Arg <ApplicationUser> .Is.Equal(anonymousApplicationUser), Arg <IDataContext> .Is.Anything), options => options.WhenCalled(y => _autoMocker.Get <IAchievementProcessor>().AssertWasNotCalled( mock => mock.ProcessAchievements(playedGameEvent.TriggerEntityId)))); //--make sure the nemesis recalculator was called for the second player in the game _autoMocker.Get <INemesisRecalculator>().AssertWasCalled( mock => mock.RecalculateNemesis( Arg <int> .Is.Equal(playersInGame[1]), Arg <ApplicationUser> .Is.Equal(anonymousApplicationUser), Arg <IDataContext> .Is.Anything)); _autoMocker.Get <IGamingGroupChampionRecalculator>().AssertWasCalled(mock => mock.RecalculateGamingGroupChampion( Arg <int> .Is.Equal(playedGameEvent.TriggerEntityId)), options => options.WhenCalled(y => _autoMocker.Get <IAchievementProcessor>().AssertWasNotCalled( mock => mock.ProcessAchievements(playedGameEvent.TriggerEntityId)))); //--make sure the achievement processor gets called _autoMocker.Get <IAchievementProcessor>().AssertWasCalled( mock => mock.ProcessAchievements(playedGameEvent.TriggerEntityId)); }
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 } } } }
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 } } } }