public void SetUp() { _autoMocker = new RhinoAutoMocker <DeleteGamingGroupComponent>(); _autoMocker.PartialMockTheClassUnderTest(); _dataContextMock = MockRepository.GenerateMock <IDataContext>(); _currentUser = new ApplicationUser(); _expectedGamingGroup = new GamingGroup { GamingGroupId = _gamingGroupId }; _autoMocker.Get <ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess <GamingGroup>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(_expectedGamingGroup); _autoMocker.ClassUnderTest.Expect(mock => mock.DeletePlayerGameResults(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeletePlayedGames(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeletePlayerAchievements(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeleteChampionsAndGameDefinitions(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeleteNemeses(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeletePlayers(Arg <GamingGroup> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.UnassociateUsers(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeleteGamingGroupInvitations(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); _autoMocker.ClassUnderTest.Expect(mock => mock.DeleteGamingGroup(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)); }
public override void SetUp() { base.SetUp(); expectedGamingGroup = new GamingGroup() { Id = currentUser.CurrentGamingGroupId }; autoMocker.Get<IDataContext>().Expect(mock => mock.Save(Arg<GamingGroup>.Is.Anything, Arg<ApplicationUser>.Is.Anything)) .Return(expectedGamingGroup); expectedPlayer = new Player(); autoMocker.Get<IPlayerSaver>().Expect(mock => mock.CreatePlayer( Arg<CreatePlayerRequest>.Is.Anything, Arg<ApplicationUser>.Is.Anything, Arg<bool>.Is.Anything)).Return(expectedPlayer); expectedUserGamingGroup = new UserGamingGroup { ApplicationUserId = currentUser.Id, GamingGroupId = expectedGamingGroup.Id }; autoMocker.Get<IDataContext>().Expect(mock => mock.Save<UserGamingGroup>(Arg<UserGamingGroup>.Is.Anything, Arg<ApplicationUser>.Is.Anything)) .Return(expectedUserGamingGroup); appUserRetrievedFromFindMethod = new ApplicationUser() { Id = currentUser.Id }; autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<ApplicationUser>(Arg<ApplicationUser>.Is.Anything)) .Return(appUserRetrievedFromFindMethod); autoMocker.Get<IDataContext>().Expect(mock => mock.Save(Arg<ApplicationUser>.Is.Anything, Arg<ApplicationUser>.Is.Anything)) .Return(new ApplicationUser()); }
public void LocalSetUp() { _gamingGroupWithNoPlays = new GamingGroup { Id = 2, DateCreated = DateTime.UtcNow, PlayedGames = new List <PlayedGame>() }; _gamingGroupWithPlays = new GamingGroup { Id = 1, DateCreated = DateTime.UtcNow.AddDays(-1), PlayedGames = new List <PlayedGame> { new PlayedGame { DatePlayed = _expectedMostRecentDate }, new PlayedGame { DatePlayed = DateTime.UtcNow.AddDays(-20) } } }; var gamingGroupQueryable = new List <GamingGroup> { _gamingGroupWithNoPlays, _gamingGroupWithPlays }.AsQueryable(); AutoMocker.Get <IDataContext>().Expect(x => x.GetQueryable <GamingGroup>()).Return(gamingGroupQueryable); }
public virtual NewlyCreatedGamingGroupResult CreateNewGamingGroup( string gamingGroupName, TransactionSource registrationSource, ApplicationUser currentUser) { ValidateGamingGroupName(gamingGroupName); GamingGroup gamingGroup = new GamingGroup() { OwningUserId = currentUser.Id, Name = gamingGroupName }; NewlyCreatedGamingGroupResult newlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult(); GamingGroup newGamingGroup = dataContext.Save <GamingGroup>(gamingGroup, currentUser); newlyCreatedGamingGroupResult.NewlyCreatedGamingGroup = newGamingGroup; //commit changes since we'll need the GamingGroup.Id dataContext.CommitAllChanges(); Player newlyCreatedPlayer = this.AssociateUserWithGamingGroup(currentUser, newGamingGroup); newlyCreatedGamingGroupResult.NewlyCreatedPlayer = newlyCreatedPlayer; new Task(() => eventTracker.TrackGamingGroupCreation(registrationSource)).Start(); return(newlyCreatedGamingGroupResult); }
public override void SetUp() { base.SetUp(); expectedGamingGroup = new GamingGroup { Id = gamingGroupId, OwningUserId = CurrentUser.Id }; filter = new GamingGroupFilter { GamingGroupId = gamingGroupId }; AutoMocker.Get<IDataContext>().Expect(mock => mock.FindById<GamingGroup>(gamingGroupId)) .Return(expectedGamingGroup); gameDefinitionSummaries = new List<GameDefinitionSummary> { new GameDefinitionSummary() }; AutoMocker.Get<IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(gamingGroupId, filter.DateRangeFilter)) .Return(gameDefinitionSummaries); List<ApplicationUser> applicationUsers = new List<ApplicationUser>(); applicationUsers.Add(CurrentUser); AutoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<ApplicationUser>()) .Return(applicationUsers.AsQueryable()); AutoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<ApplicationUser>()) .Return(applicationUsers.AsQueryable()); }
public virtual NewlyCreatedGamingGroupResult CreateNewGamingGroup( string gamingGroupName, TransactionSource registrationSource, ApplicationUser currentUser) { ValidateGamingGroupName(gamingGroupName); var gamingGroup = new GamingGroup() { OwningUserId = currentUser.Id, Name = gamingGroupName }; var newlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult(); var newGamingGroup = dataContext.Save<GamingGroup>(gamingGroup, currentUser); newlyCreatedGamingGroupResult.NewlyCreatedGamingGroup = newGamingGroup; //commit changes since we'll need the GamingGroup.Id dataContext.CommitAllChanges(); var newlyCreatedPlayer = this.AssociateUserWithGamingGroup(currentUser, newGamingGroup); newlyCreatedGamingGroupResult.NewlyCreatedPlayer = newlyCreatedPlayer; new Task(() => eventTracker.TrackGamingGroupCreation(registrationSource)).Start(); return newlyCreatedGamingGroupResult; }
public override void SetUp() { base.SetUp(); expectedGamingGroup = new GamingGroup() { Id = currentUser.CurrentGamingGroupId }; autoMocker.Get <IDataContext>().Expect(mock => mock.Save(Arg <GamingGroup> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(expectedGamingGroup); expectedPlayer = new Player(); autoMocker.Get <IPlayerSaver>().Expect(mock => mock.Save(Arg <Player> .Is.Anything, Arg <ApplicationUser> .Is.Anything)).Return(expectedPlayer); expectedUserGamingGroup = new UserGamingGroup { ApplicationUserId = currentUser.Id, GamingGroupId = expectedGamingGroup.Id }; autoMocker.Get <IDataContext>().Expect(mock => mock.Save <UserGamingGroup>(Arg <UserGamingGroup> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(expectedUserGamingGroup); appUserRetrievedFromFindMethod = new ApplicationUser() { Id = currentUser.Id }; autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <ApplicationUser>(Arg <ApplicationUser> .Is.Anything)) .Return(appUserRetrievedFromFindMethod); autoMocker.Get <IDataContext>().Expect(mock => mock.Save(Arg <ApplicationUser> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(new ApplicationUser()); }
public override void SetUp() { base.SetUp(); _expectedGamingGroup = new GamingGroup { Id = _gamingGroupId, OwningUserId = CurrentUser.Id }; _filter = new GamingGroupFilter(_gamingGroupId); AutoMocker.Get <IDataContext>().Expect(mock => mock.FindById <GamingGroup>(_gamingGroupId)) .Return(_expectedGamingGroup); _gameDefinitionSummaries = new List <GameDefinitionSummary> { new GameDefinitionSummary() }; AutoMocker.Get <IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(_gamingGroupId, _filter.DateRangeFilter)) .Return(_gameDefinitionSummaries); List <ApplicationUser> applicationUsers = new List <ApplicationUser>(); applicationUsers.Add(CurrentUser); AutoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <ApplicationUser>()) .Return(applicationUsers.AsQueryable()); AutoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <ApplicationUser>()) .Return(applicationUsers.AsQueryable()); }
public override void SetUp() { base.SetUp(); expectedGamingGroup = new GamingGroup { Id = gamingGroupId, OwningUserId = currentUser.Id }; dataContextMock.Expect(mock => mock.FindById <GamingGroup>(gamingGroupId)) .Return(expectedGamingGroup); gameDefinitionSummaries = new List <GameDefinitionSummary> { new GameDefinitionSummary() }; gameDefinitionRetrieverMock.Expect(mock => mock.GetAllGameDefinitions(gamingGroupId)) .Return(gameDefinitionSummaries); List <ApplicationUser> applicationUsers = new List <ApplicationUser>(); applicationUsers.Add(currentUser); dataContextMock.Expect(mock => mock.GetQueryable <ApplicationUser>()) .Return(applicationUsers.AsQueryable()); dataContextMock.Expect(mock => mock.GetQueryable <ApplicationUser>()) .Return(applicationUsers.AsQueryable()); }
private Player AssociateUserWithGamingGroup(ApplicationUser currentUser, GamingGroup newGamingGroup) { this.AddUserGamingGroupRecord(currentUser, newGamingGroup); this.SetGamingGroupOnCurrentUser(currentUser, newGamingGroup); return this.AddUserToGamingGroupAsPlayer(currentUser); }
private Player AssociateUserWithGamingGroup(ApplicationUser currentUser, GamingGroup newGamingGroup) { this.AddUserGamingGroupRecord(currentUser, newGamingGroup); this.SetGamingGroupOnCurrentUser(currentUser, newGamingGroup); return(this.AddUserToGamingGroupAsPlayer(currentUser)); }
public void SetUp() { dataContextMock = MockRepository.GenerateMock <IDataContext>(); emailServiceMock = MockRepository.GenerateMock <IIdentityMessageService>(); configurationManagerMock = MockRepository.GenerateMock <IConfigurationManager>(); playerInvitation = new PlayerInvitation { CustomEmailMessage = "custom message", EmailSubject = "email subject", InvitedPlayerEmail = "player email", InvitedPlayerId = 1 }; currentUser = new ApplicationUser { CurrentGamingGroupId = 15, UserName = "******" }; player = new Player { Id = playerInvitation.InvitedPlayerId, GamingGroupId = 135 }; gamingGroup = new GamingGroup { Id = currentUser.CurrentGamingGroupId, Name = "jake's Gaming Group" }; gamingGroupInvitation = new GamingGroupInvitation { Id = Guid.NewGuid() }; dataContextMock.Expect(mock => mock.FindById <GamingGroup>(currentUser.CurrentGamingGroupId)) .Return(gamingGroup); List <ApplicationUser> applicationUsers = new List <ApplicationUser> { new ApplicationUser { Email = playerInvitation.InvitedPlayerEmail, Id = existingUserId } }; dataContextMock.Expect(mock => mock.GetQueryable <ApplicationUser>()) .Return(applicationUsers.AsQueryable()); dataContextMock.Expect(mock => mock.Save <GamingGroupInvitation>(Arg <GamingGroupInvitation> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(gamingGroupInvitation); configurationManagerMock.Expect(mock => mock.AppSettings[PlayerInviter.APP_SETTING_URL_ROOT]) .Return(rootUrl); emailServiceMock.Expect(mock => mock.SendAsync(Arg <IdentityMessage> .Is.Anything)) .Return(Task.FromResult <object>(null)); playerInviter = new PlayerInviter(dataContextMock, emailServiceMock, configurationManagerMock); }
public virtual void FixtureSetUp() { //create a stub for this only since we don't want the slowdown of all of the universal analytics event tracking eventTrackerStub = MockRepository.GenerateStub <IEventTracker>(); eventTrackerStub.Expect(stub => stub.TrackEvent(Arg <IUniversalAnalyticsEvent> .Is.Anything)) .Repeat.Any(); playedGameTracker = new UniversalAnalyticsNemeStatsEventTracker(eventTrackerStub, eventFactory); using (NemeStatsDbContext nemeStatsDbContext = new NemeStatsDbContext()) { CleanUpTestData(); testUserWithDefaultGamingGroup = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithDefaultGamingGroup, "*****@*****.**"); testUserWithDefaultGamingGroupAndNoInvites = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithDefaultGamingGroupAndNoInvites, "*****@*****.**"); testUserWithOtherGamingGroup = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithOtherGamingGroup, "*****@*****.**"); testUserWithThirdGamingGroup = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithThirdGamingGroup, "*****@*****.**"); using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { testGamingGroup = SaveGamingGroup(dataContext, testGamingGroup1Name, testUserWithDefaultGamingGroup); testUserWithDefaultGamingGroup = UpdateDatefaultGamingGroupOnUser(testUserWithDefaultGamingGroup, testGamingGroup, dataContext); testOtherGamingGroup = SaveGamingGroup(dataContext, testGamingGroup2Name, testUserWithOtherGamingGroup); testUserWithOtherGamingGroup = UpdateDatefaultGamingGroupOnUser(testUserWithOtherGamingGroup, testOtherGamingGroup, dataContext); testThirdGamingGroup = SaveGamingGroup(dataContext, testGamingGroup3Name, testUserWithThirdGamingGroup); testUserWithThirdGamingGroup = UpdateDatefaultGamingGroupOnUser(testUserWithThirdGamingGroup, testThirdGamingGroup, dataContext); testGameDefinition = SaveGameDefinition(nemeStatsDbContext, testGamingGroup.Id, testGameName); testGameDefinition2 = SaveGameDefinition(nemeStatsDbContext, testGamingGroup.Id, testGameName2); testGameDefinitionWithOtherGamingGroupId = SaveGameDefinition(nemeStatsDbContext, testOtherGamingGroup.Id, testGameNameForGameWithOtherGamingGroupId); gameDefinitionWithNoChampion = SaveGameDefinition(nemeStatsDbContext, testThirdGamingGroup.Id, gameDefinitionWithNoChampionName); anotherTestGameDefinitionWithOtherGamingGroupId = SaveGameDefinition(nemeStatsDbContext, testOtherGamingGroup.Id, testGameNameForAnotherGameWithOtherGamingGroupId); SavePlayers(nemeStatsDbContext, testGamingGroup.Id, testOtherGamingGroup.Id); SaveGamingGroupInvitations(nemeStatsDbContext, dataContext); } using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { CreatePlayedGames(dataContext); } } }
private void SetGamingGroupOnCurrentUser(ApplicationUser currentUser, GamingGroup newGamingGroup) { ApplicationUser user = dataContext.FindById <ApplicationUser>(currentUser.Id); user.CurrentGamingGroupId = newGamingGroup.Id; dataContext.Save(user, currentUser); currentUser.CurrentGamingGroupId = user.CurrentGamingGroupId; }
public void SetUp() { dataContextMock = MockRepository.GenerateMock<IDataContext>(); emailServiceMock = MockRepository.GenerateMock<IIdentityMessageService>(); configurationManagerMock = MockRepository.GenerateMock<IConfigurationManager>(); playerInvitation = new PlayerInvitation { CustomEmailMessage = "custom message", EmailSubject = "email subject", InvitedPlayerEmail = "player email", InvitedPlayerId = 1 }; currentUser = new ApplicationUser { CurrentGamingGroupId = 15, UserName = "******" }; player = new Player { Id = playerInvitation.InvitedPlayerId, GamingGroupId = 135 }; gamingGroup = new GamingGroup { Id = currentUser.CurrentGamingGroupId, Name = "jake's Gaming Group" }; gamingGroupInvitation = new GamingGroupInvitation { Id = Guid.NewGuid() }; dataContextMock.Expect(mock => mock.FindById<GamingGroup>(currentUser.CurrentGamingGroupId)) .Return(gamingGroup); List<ApplicationUser> applicationUsers = new List<ApplicationUser> { new ApplicationUser { Email = playerInvitation.InvitedPlayerEmail, Id = existingUserId } }; dataContextMock.Expect(mock => mock.GetQueryable<ApplicationUser>()) .Return(applicationUsers.AsQueryable()); dataContextMock.Expect(mock => mock.Save<GamingGroupInvitation>(Arg<GamingGroupInvitation>.Is.Anything, Arg<ApplicationUser>.Is.Anything)) .Return(gamingGroupInvitation); configurationManagerMock.Expect(mock => mock.AppSettings[PlayerInviter.APP_SETTING_URL_ROOT]) .Return(rootUrl); emailServiceMock.Expect(mock => mock.SendAsync(Arg<IdentityMessage>.Is.Anything)) .Return(Task.FromResult<object>(null)); playerInviter = new PlayerInviter(dataContextMock, emailServiceMock, configurationManagerMock); }
private void AddUserGamingGroupRecord(ApplicationUser currentUser, GamingGroup newGamingGroup) { UserGamingGroup userGamingGroup = new UserGamingGroup { ApplicationUserId = currentUser.Id, GamingGroupId = newGamingGroup.Id }; this.dataContext.Save(userGamingGroup, currentUser); }
private GamingGroup SaveGamingGroup(string gamingGroupName, ApplicationUser owningUser) { GamingGroup gamingGroup = new GamingGroup { Name = gamingGroupName, OwningUserId = owningUser.Id }; _dataContext.Save(gamingGroup, owningUser); _dataContext.CommitAllChanges(); return(gamingGroup); }
internal virtual void DeletePlayers(GamingGroup gamingGroup, ApplicationUser currentUser) { gamingGroup.GamingGroupChampionPlayerId = null; _dataContext.Save(gamingGroup, currentUser); var playerIds = _dataContext.GetQueryable <Player>() .Where(x => x.GamingGroupId == gamingGroup.Id) .Select(x => x.Id) .ToList(); playerIds.ForEach(x => _dataContext.DeleteById <Player>(x, currentUser)); }
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(); } }
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(); } }
private void CleanUpGamingGroup(string testGamingGroupName) { GamingGroup gamingGroupToDelete = (from gamingGroup in _nemeStatsDbContext.GamingGroups where gamingGroup.Name == testGamingGroupName select gamingGroup).FirstOrDefault(); if (gamingGroupToDelete != null) { try { _nemeStatsDbContext.GamingGroups.Remove(gamingGroupToDelete); } catch (Exception) { } } }
public void LocalSetUp() { expectedInvitation = new GamingGroupInvitation { GamingGroupId = 1, PlayerId = 2 }; expectedGamingGroup = new GamingGroup { Id = expectedInvitation.GamingGroupId, Name = "some awesome gaming group name" }; dataContextMock.Expect(mock => mock.FindById<GamingGroup>(expectedInvitation.GamingGroupId)).Return(expectedGamingGroup); expectedPlayer = new Player(); }
public void LocalSetUp() { expectedInvitation = new GamingGroupInvitation { GamingGroupId = 1, PlayerId = 2 }; expectedGamingGroup = new GamingGroup { Id = expectedInvitation.GamingGroupId, Name = "some awesome gaming group name" }; dataContextMock.Expect(mock => mock.FindById <GamingGroup>(expectedInvitation.GamingGroupId)).Return(expectedGamingGroup); expectedPlayer = new Player(); }
private void SetupPlayedGames(int winnerId, int loserId, int winnerPoints) { var results = new List <PlayerGameResult>() { new PlayerGameResult { PlayedGame = new PlayedGame() { GamingGroupId = _gamingGroupId }, PlayerId = winnerId, NemeStatsPointsAwarded = winnerPoints }, new PlayerGameResult { PlayedGame = new PlayedGame() { GamingGroupId = _gamingGroupId }, PlayerId = loserId, NemeStatsPointsAwarded = 5 }, }; _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerGameResult>()).Return(results.AsQueryable()); var players = new List <Player> { new Player { Id = _playerId, GamingGroupId = _gamingGroupId } }; _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>()).Return(players.AsQueryable()); var testingGamingGroup = new GamingGroup { Id = _gamingGroupId }; var gamingGroups = new List <GamingGroup> { testingGamingGroup }; _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <GamingGroup>()).Return(gamingGroups.AsQueryable()); }
private void SetUpGamingGroup(string owningUserId = "some id") { _expectedGamingGroup = new GamingGroup { Id = _gamingGroupId, Active = false, Name = "some gaming group name", PublicDescription = "some public description", PublicGamingGroupWebsite = "some website", OwningUserId = owningUserId }; AutoMocker.Get <ISecuredEntityValidator>() .Expect(mock => mock.RetrieveAndValidateAccess <GamingGroup>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(_expectedGamingGroup); }
public void ItTracksTheGamingGroupCreation() { GamingGroup expectedGamingGroup = new GamingGroup() { Id = 123 }; autoMocker.Get <IDataContext>().Expect(mock => mock.Save(Arg <GamingGroup> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Repeat.Once() .Return(expectedGamingGroup); TransactionSource expectedRegistrationSource = TransactionSource.RestApi; autoMocker.ClassUnderTest.CreateNewGamingGroup(gamingGroupName, expectedRegistrationSource, currentUser); autoMocker.Get <INemeStatsEventTracker>().AssertWasCalled(mock => mock.TrackGamingGroupCreation(expectedRegistrationSource)); }
public void TheAddOrInsertExtensionMethodSetsTheIdOnNewEntities() { var dataContext = GetInstance <IDataContext>(); var gamingGroup = new GamingGroup { Name = "new gaming group without an ID yet", OwningUserId = _userWithGamingGroup.Id }; dataContext.Save(gamingGroup, _userWithGamingGroup); dataContext.CommitAllChanges(); Cleanup(dataContext, gamingGroup, _userWithGamingGroup); gamingGroup.Id.ShouldNotBe(default(int)); }
public void SetUp() { _autoMocker = new RhinoAutoMocker <GamingGroupChampionRecalculator>(); _gamingGroup = new GamingGroup { Id = _gamingGroupId }; var gamingGroupsQueryable = new List <GamingGroup> { _gamingGroup }.AsQueryable(); _autoMocker.Get <IDataContext>() .Expect(mock => mock.GetQueryable <GamingGroup>()) .Return(gamingGroupsQueryable); }
public void InvitePlayer(PlayerInvitation playerInvitation, ApplicationUser currentUser) { if (!currentUser.CurrentGamingGroupId.HasValue) { throw new UserHasNoGamingGroupException(currentUser.Id); } GamingGroup gamingGroup = dataContext.FindById <GamingGroup>(currentUser.CurrentGamingGroupId); string existingUserId = (from ApplicationUser user in dataContext.GetQueryable <ApplicationUser>() where user.Email == playerInvitation.InvitedPlayerEmail select user.Id).FirstOrDefault(); GamingGroupInvitation gamingGroupInvitation = new GamingGroupInvitation { DateSent = DateTime.UtcNow, GamingGroupId = currentUser.CurrentGamingGroupId.Value, InviteeEmail = playerInvitation.InvitedPlayerEmail, InvitingUserId = currentUser.Id, PlayerId = playerInvitation.InvitedPlayerId, RegisteredUserId = existingUserId }; GamingGroupInvitation savedGamingGroupInvitation = dataContext.Save <GamingGroupInvitation>(gamingGroupInvitation, currentUser); //commit so we can get the Id back dataContext.CommitAllChanges(); string urlRoot = configurationManager.AppSettings[APP_SETTING_URL_ROOT]; string messageBody = string.Format(PlayerInviter.EMAIL_MESSAGE_INVITE_PLAYER, currentUser.UserName, gamingGroup.Name, urlRoot, playerInvitation.CustomEmailMessage, savedGamingGroupInvitation.Id, "<br/><br/>"); var message = new IdentityMessage { Body = messageBody, Destination = playerInvitation.InvitedPlayerEmail, Subject = playerInvitation.EmailSubject }; emailService.SendAsync(message); }
public override void SetUp() { base.SetUp(); _gamingGroupId = CurrentUser.CurrentGamingGroupId.Value; _expectedGamingGroup = new GamingGroup { Id = _gamingGroupId, Active = false, Name = "some gaming group name", PublicDescription = "some public description", PublicGamingGroupWebsite = "some website" }; AutoMocker.Get <ISecuredEntityValidator>() .Expect(mock => mock.RetrieveAndValidateAccess <GamingGroup>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)) .Return(_expectedGamingGroup); }
public void TheAddOrInsertExtensionMethodSetsTheIdOnNewEntities() { using (NemeStatsDataContext dataContext = new NemeStatsDataContext( new NemeStatsDbContext(), new SecuredEntityValidatorFactory())) { GamingGroup gamingGroup = new GamingGroup() { Name = "new gaming group without an ID yet", OwningUserId = testUserWithDefaultGamingGroup.Id }; dataContext.Save(gamingGroup, testUserWithDefaultGamingGroup); dataContext.CommitAllChanges(); Cleanup(dataContext, gamingGroup, testUserWithDefaultGamingGroup); Assert.AreNotEqual(default(int), gamingGroup.Id); } }
public void TheAddOrInsertExtensionMethodSetsTheIdOnNewEntities() { using(NemeStatsDataContext dataContext = new NemeStatsDataContext( new NemeStatsDbContext(), new SecuredEntityValidatorFactory())) { GamingGroup gamingGroup = new GamingGroup() { Name = "new gaming group without an ID yet", OwningUserId = testUserWithDefaultGamingGroup.Id }; dataContext.Save(gamingGroup, testUserWithDefaultGamingGroup); dataContext.CommitAllChanges(); Cleanup(dataContext, gamingGroup, testUserWithDefaultGamingGroup); Assert.AreNotEqual(default(int), gamingGroup.Id); } }
public void ItDoesntSetTheGamingGroupIdIfTheEntityIsAGamingGroupItself() { var gamingGroup = new GamingGroup(); var securedEntityValidator = MockRepository.GenerateMock <ISecuredEntityValidator>(); securedEntityValidatorFactory.Expect(mock => mock.MakeSecuredEntityValidator <GamingGroup>(dataContext)) .IgnoreArguments() .Return(securedEntityValidator); securedEntityValidator.Expect(mock => mock.ValidateAccess <GameDefinition>(null, null)).IgnoreArguments(); dataContext.Expect(mock => mock.AddOrInsertOverride(gamingGroup)) .Repeat.Once() .Return(gamingGroup); dataContext.Save(gamingGroup, currentUser); //--GamingGroup.GamingGroupId is just an alias for GamingGroup.Id, so this should remain the same dataContext.AssertWasNotCalled(mock => mock.AddOrInsertOverride( Arg <GamingGroup> .Matches(entity => entity.GamingGroupId == currentUser.CurrentGamingGroupId))); }
public GamingGroupSummary GetGamingGroupDetails(int gamingGroupId, int maxNumberOfGamesToRetrieve) { GamingGroup gamingGroup = dataContext.FindById <GamingGroup>(gamingGroupId); GamingGroupSummary summary = new GamingGroupSummary { Id = gamingGroup.Id, DateCreated = gamingGroup.DateCreated, Name = gamingGroup.Name, OwningUserId = gamingGroup.OwningUserId, PublicDescription = gamingGroup.PublicDescription, PublicGamingGroupWebsite = gamingGroup.PublicGamingGroupWebsite }; summary.PlayedGames = playedGameRetriever.GetRecentGames(maxNumberOfGamesToRetrieve, gamingGroupId); summary.Players = playerRetriever.GetAllPlayersWithNemesisInfo(gamingGroupId); summary.GameDefinitionSummaries = gameDefinitionRetriever.GetAllGameDefinitions(gamingGroupId); summary.OwningUser = dataContext.GetQueryable <ApplicationUser>().First(user => user.Id == gamingGroup.OwningUserId); return(summary); }
public virtual void FixtureSetUp() { //create a stub for this only since we don't want the slowdown of all of the universal analytics event tracking eventTrackerStub = MockRepository.GenerateStub<IEventTracker>(); eventTrackerStub.Expect(stub => stub.TrackEvent(Arg<IUniversalAnalyticsEvent>.Is.Anything)) .Repeat.Any(); playedGameTracker = new UniversalAnalyticsNemeStatsEventTracker(eventTrackerStub, eventFactory); using (NemeStatsDbContext nemeStatsDbContext = new NemeStatsDbContext()) { CleanUpTestData(); testUserWithDefaultGamingGroup = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithDefaultGamingGroup, "*****@*****.**"); testUserWithDefaultGamingGroupAndNoInvites = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithDefaultGamingGroupAndNoInvites, "*****@*****.**"); testUserWithOtherGamingGroup = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithOtherGamingGroup, "*****@*****.**"); testUserWithThirdGamingGroup = SaveApplicationUser( nemeStatsDbContext, testApplicationUserNameForUserWithThirdGamingGroup, "*****@*****.**"); using (NemeStatsDataContext dataContext = new NemeStatsDataContext()) { testGamingGroup = SaveGamingGroup(dataContext, testGamingGroup1Name, testUserWithDefaultGamingGroup); testUserWithDefaultGamingGroup = UpdateDatefaultGamingGroupOnUser(testUserWithDefaultGamingGroup, testGamingGroup, dataContext); testOtherGamingGroup = SaveGamingGroup(dataContext, testGamingGroup2Name, testUserWithOtherGamingGroup); testUserWithOtherGamingGroup = UpdateDatefaultGamingGroupOnUser(testUserWithOtherGamingGroup, testOtherGamingGroup, dataContext); testThirdGamingGroup = SaveGamingGroup(dataContext, testGamingGroup3Name, testUserWithThirdGamingGroup); testUserWithThirdGamingGroup = UpdateDatefaultGamingGroupOnUser(testUserWithThirdGamingGroup, testThirdGamingGroup, dataContext); testBoardGameGeekGameDefinition = SaveBoardGameGeekGameDefinition(dataContext); testGameDefinition = SaveGameDefinition(nemeStatsDbContext, testGamingGroup.Id, testGameName, testBoardGameGeekGameDefinition.Id); testGameDefinition2 = SaveGameDefinition(nemeStatsDbContext, testGamingGroup.Id, testGameName2); testGameDefinitionWithOtherGamingGroupId = SaveGameDefinition(nemeStatsDbContext, testOtherGamingGroup.Id, testGameNameForGameWithOtherGamingGroupId); gameDefinitionWithNoChampion = SaveGameDefinition(nemeStatsDbContext, testThirdGamingGroup.Id, gameDefinitionWithNoChampionName); anotherTestGameDefinitionWithOtherGamingGroupId = SaveGameDefinition(nemeStatsDbContext, testOtherGamingGroup.Id, testGameNameForAnotherGameWithOtherGamingGroupId); SavePlayers(nemeStatsDbContext, testGamingGroup.Id, testOtherGamingGroup.Id); } using(NemeStatsDataContext dataContext = new NemeStatsDataContext()) { CreatePlayedGames(dataContext); } } }
private GamingGroup SaveGamingGroup(NemeStatsDataContext dataContext, string gamingGroupName, ApplicationUser owningUser) { GamingGroup gamingGroup = new GamingGroup { Name = gamingGroupName, OwningUserId = owningUser.Id }; dataContext.Save(gamingGroup, owningUser); dataContext.CommitAllChanges(); return gamingGroup; }
private void SetGamingGroupOnCurrentUser(ApplicationUser currentUser, GamingGroup newGamingGroup) { var user = dataContext.FindById<ApplicationUser>(currentUser.Id); user.CurrentGamingGroupId = newGamingGroup.Id; dataContext.Save(user, currentUser); currentUser.CurrentGamingGroupId = user.CurrentGamingGroupId; }
private ApplicationUser UpdateDatefaultGamingGroupOnUser(ApplicationUser user, GamingGroup gamingGroup) { user.CurrentGamingGroupId = gamingGroup.Id; _dataContext.CommitAllChanges(); return(user); }
private void AddUserGamingGroupRecord(ApplicationUser currentUser, GamingGroup newGamingGroup) { var userGamingGroup = new UserGamingGroup { ApplicationUserId = currentUser.Id, GamingGroupId = newGamingGroup.Id }; this.dataContext.Save(userGamingGroup, currentUser); }
private void SetItAllUp(WinnerTypes winnerType) { Stack<int> gameRankStack = new Stack<int>(); if (winnerType == WinnerTypes.PlayerWin) { gameRankStack.Push(1); gameRankStack.Push(2); gameRankStack.Push(3); }else if (winnerType == WinnerTypes.TeamLoss) { gameRankStack.Push(2); gameRankStack.Push(2); gameRankStack.Push(2); }else if (winnerType == WinnerTypes.TeamWin) { gameRankStack.Push(1); gameRankStack.Push(1); gameRankStack.Push(1); } _gamingGroup = new GamingGroup { Id = _gamingGroupId, Name = "gaming group name" }; _playedGame = new PlayedGame { Id = 11111, GameDefinition = new GameDefinition(), GamingGroup = _gamingGroup, GameDefinitionId = 2222, PlayerGameResults = new List<PlayerGameResult>(), GamingGroupId = _gamingGroupId, Notes = "some notes" + Environment.NewLine + "some notes on a separate line", WinnerType = winnerType }; _playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 3, Id = 1, PlayedGameId = _playedGame.Id, PlayerId = 1 }); _playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 2, Id = 2, PlayedGameId = _playedGame.Id, PlayerId = 2 }); _playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 1, Id = 3, PlayedGameId = _playedGame.Id, PlayerId = 3, PlayedGame = new PlayedGame() { GameDefinition = new GameDefinition() { Id = 135, Name = "Test game name" } } }); _detailsBuilder = MockRepository.GenerateMock<IGameResultViewModelBuilder>(); _builder = new PlayedGameDetailsViewModelBuilder(_detailsBuilder); int totalPlayerGameResults = _playedGame.PlayerGameResults.Count; for (int i = 0; i < totalPlayerGameResults; i++) { _detailsBuilder.Expect( x => x.Build(_playedGame.PlayerGameResults[i])) .Repeat .Once() .Return(new GameResultViewModel() { PlayerId = _playedGame.PlayerGameResults[i].PlayerId }); } _currentUser = new ApplicationUser() { CurrentGamingGroupId = _gamingGroupId }; _actualViewModel = _builder.Build(_playedGame, _currentUser, false); }
public void ItTracksTheGamingGroupCreation() { GamingGroup expectedGamingGroup = new GamingGroup() { Id = 123 }; autoMocker.Get<IDataContext>().Expect(mock => mock.Save(Arg<GamingGroup>.Is.Anything, Arg<ApplicationUser>.Is.Anything)) .Repeat.Once() .Return(expectedGamingGroup); TransactionSource expectedRegistrationSource = TransactionSource.RestApi; autoMocker.ClassUnderTest.CreateNewGamingGroup(gamingGroupName, expectedRegistrationSource, currentUser); autoMocker.Get<INemeStatsEventTracker>().AssertWasCalled(mock => mock.TrackGamingGroupCreation(expectedRegistrationSource)); }
private void SetItAllUp(WinnerTypes winnerType) { Stack <int> gameRankStack = new Stack <int>(); if (winnerType == WinnerTypes.PlayerWin) { gameRankStack.Push(1); gameRankStack.Push(2); gameRankStack.Push(3); } else if (winnerType == WinnerTypes.TeamLoss) { gameRankStack.Push(2); gameRankStack.Push(2); gameRankStack.Push(2); } else if (winnerType == WinnerTypes.TeamWin) { gameRankStack.Push(1); gameRankStack.Push(1); gameRankStack.Push(1); } this.gamingGroup = new GamingGroup { Id = this.gamingGroupId, Name = "gaming group name" }; this.playedGame = new PlayedGame { Id = 11111, GameDefinition = new GameDefinition(), GamingGroup = this.gamingGroup, GameDefinitionId = 2222, PlayerGameResults = new List <PlayerGameResult>(), GamingGroupId = this.gamingGroupId, Notes = "some notes" + Environment.NewLine + "some notes on a separate line" }; this.playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 3, Id = 1, PlayedGameId = this.playedGame.Id, PlayerId = 1 }); this.playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 2, Id = 2, PlayedGameId = this.playedGame.Id, PlayerId = 2 }); this.playedGame.PlayerGameResults.Add(new PlayerGameResult() { GameRank = gameRankStack.Pop(), NemeStatsPointsAwarded = 1, Id = 3, PlayedGameId = this.playedGame.Id, PlayerId = 3, PlayedGame = new PlayedGame() { GameDefinition = new GameDefinition() { Id = 135, Name = "Test game name" } } }); this.detailsBuilder = MockRepository.GenerateMock <IGameResultViewModelBuilder>(); this.builder = new PlayedGameDetailsViewModelBuilder(this.detailsBuilder); int totalPlayerGameResults = this.playedGame.PlayerGameResults.Count; for (int i = 0; i < totalPlayerGameResults; i++) { this.detailsBuilder.Expect( x => x.Build(this.playedGame.PlayerGameResults[i])) .Repeat .Once() .Return(new GameResultViewModel() { PlayerId = this.playedGame.PlayerGameResults[i].PlayerId }); } this.currentUser = new ApplicationUser() { CurrentGamingGroupId = this.gamingGroupId }; this.actualViewModel = this.builder.Build(this.playedGame, this.currentUser); }
public void It_Sets_The_Gaming_Group_Information() { const int EXPECTED_GAMING_GROUP_ID_1 = 1; const string EXPECTED_GAMING_GROUP_NAME_1 = "gaming group name 1"; const string EXPECTED_URL = "gaming group name 1"; const string EXPECTED_DESCRIPTION = "gaming group name 1"; var expectedChampion = new Player(); var expectedGamingGroup1 = new GamingGroup { Id = EXPECTED_GAMING_GROUP_ID_1, Name = EXPECTED_GAMING_GROUP_NAME_1, PublicGamingGroupWebsite = EXPECTED_URL, PublicDescription = EXPECTED_DESCRIPTION, Active = !default(bool), PlayedGames = new List <PlayedGame> { new PlayedGame() }, Players = new List <Player> { new Player(), new Player() }, GamingGroupChampion = expectedChampion }; var expectedApplicationUser = new ApplicationUser { Id = "some application user id", UserGamingGroups = new List <UserGamingGroup> { new UserGamingGroup { GamingGroup = expectedGamingGroup1 }, new UserGamingGroup { GamingGroup = new GamingGroup { PlayedGames = new List <PlayedGame>(), Players = new List <Player>(), Name = "zzz - this game will get sorted 2nd because of the name" } } }, Players = new List <Player>(), BoardGameGeekUser = null }; var userQueryable = new List <ApplicationUser> { expectedApplicationUser }.AsQueryable(); _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <ApplicationUser>()).Return(userQueryable); var actualResult = _autoMocker.ClassUnderTest.RetrieveUserInformation(expectedApplicationUser); actualResult.GamingGroups.Count.ShouldBe(2); var actualGamingGroupInfo = actualResult.GamingGroups[0]; actualGamingGroupInfo.GamingGroupId.ShouldBe(EXPECTED_GAMING_GROUP_ID_1); actualGamingGroupInfo.GamingGroupName.ShouldBe(EXPECTED_GAMING_GROUP_NAME_1); actualGamingGroupInfo.GamingGroupPublicUrl.ShouldBe(EXPECTED_URL); actualGamingGroupInfo.GamingGroupPublicDescription.ShouldBe(EXPECTED_DESCRIPTION); actualGamingGroupInfo.Active.ShouldBe(expectedGamingGroup1.Active); actualGamingGroupInfo.NumberOfGamesPlayed.ShouldBe(expectedGamingGroup1.PlayedGames.Count); actualGamingGroupInfo.NumberOfPlayers.ShouldBe(expectedGamingGroup1.Players.Count); actualGamingGroupInfo.GamingGroupChampion.ShouldBeSameAs(expectedChampion); }
private ApplicationUser UpdateDatefaultGamingGroupOnUser(ApplicationUser user, GamingGroup gamingGroup, NemeStatsDataContext dataContext) { user.CurrentGamingGroupId = gamingGroup.Id; dataContext.CommitAllChanges(); return user; }