Ejemplo n.º 1
0
        public virtual void SetUp()
        {
            _autoMocker = new RhinoAutoMocker <PlayerAchievementRetriever>();
            _autoMocker.PartialMockTheClassUnderTest();

            _expectedAchievement = new FakeAchievement();
            _autoMocker.Get <IAchievementRetriever>().Expect(mock => mock.GetAchievement(_achievementId)).Return(_expectedAchievement);

            _expectedPlayer = new Player
            {
                Name = "some player name",
                Id   = 51
            };
            _playerAchievement = new PlayerAchievement
            {
                AchievementId   = _achievementId,
                DateCreated     = DateTime.UtcNow.AddDays(-15),
                LastUpdatedDate = DateTime.UtcNow,
                PlayerId        = _expectedPlayer.Id
            };
            var playerAchievementsQueryable = new List <PlayerAchievement>
            {
                //--achievement with non-matching id
                new PlayerAchievement(),
                new PlayerAchievement
                {
                    AchievementId = _achievementId
                },
                _playerAchievement
            }.AsQueryable();

            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerAchievement>()).Return(playerAchievementsQueryable);
        }
Ejemplo n.º 2
0
        public virtual void TestSetUp()
        {
            AutoMocker = new RhinoAutoMocker <PlayedGameController>();
            AutoMocker.PartialMockTheClassUnderTest();

            CurrentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = 1
            };
            GameDefinitionSummaries = new List <GameDefinitionSummary>();
            AutoMocker.Get <IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(CurrentUser.CurrentGamingGroupId))
            .Repeat.Once()
            .Return(GameDefinitionSummaries);

            AutoMocker.ClassUnderTest.Url = MockRepository.GenerateMock <UrlHelper>();

            var expectedMapper = MockRepository.GenerateMock <ICustomMapper <SavePlayedGameRequest, NewlyCompletedGame> >();

            AutoMocker.Get <IMapperFactory>()
            .Expect(mock => mock.GetMapper <SavePlayedGameRequest, NewlyCompletedGame>())
            .Return(expectedMapper);
            expectedMapper.Expect(mock => mock.Map(Arg <SavePlayedGameRequest> .Is.Anything)).Return(new NewlyCompletedGame());

            var expectedUpdateGameMapper = MockRepository.GenerateMock <ICustomMapper <SavePlayedGameRequest, UpdatedGame> >();

            AutoMocker.Get <IMapperFactory>()
            .Expect(mock => mock.GetMapper <SavePlayedGameRequest, UpdatedGame>())
            .Return(expectedUpdateGameMapper);
            expectedUpdateGameMapper.Expect(mock => mock.Map(Arg <SavePlayedGameRequest> .Is.Anything)).Return(new UpdatedGame());
        }
        public void TestSetUp()
        {
            AutoMocker = new RhinoAutoMocker <PlayedGameSaver>();
            AutoMocker.PartialMockTheClassUnderTest();
            DataContextMock = MockRepository.GenerateMock <IDataContext>();

            CurrentUser = new ApplicationUser
            {
                Id = "user id",
                CurrentGamingGroupId = GAMING_GROUP_ID,
                AnonymousClientId    = "anonymous client id"
            };
            GameDefinition = new GameDefinition
            {
                Name          = "game definition name",
                GamingGroupId = GAMING_GROUP_ID,
                Id            = 9598,
                BoardGameGeekGameDefinitionId = 13
            };

            AutoMocker.Get <ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess <GameDefinition>(Arg <int> .Is.Anything, Arg <ApplicationUser> .Is.Anything)).Return(GameDefinition);

            ExistingPlayerWithMatchingGamingGroup = new Player
            {
                Id            = 1,
                GamingGroupId = GAMING_GROUP_ID
            };
            AutoMocker.Get <IDataContext>().Expect(mock => mock.FindById <Player>(Arg <int> .Is.Anything)).Return(ExistingPlayerWithMatchingGamingGroup);
        }
Ejemplo n.º 4
0
        public void TestSetUp()
        {
            autoMocker = new RhinoAutoMocker <PlayedGameCreator>();
            autoMocker.PartialMockTheClassUnderTest();

            currentUser = new ApplicationUser()
            {
                Id = "user id",
                CurrentGamingGroupId = GAMING_GROUP_ID,
                AnonymousClientId    = "anonymous client id"
            };
            gameDefinition = new GameDefinition()
            {
                Name = "game definition name", GamingGroupId = GAMING_GROUP_ID, Id = 9598
            };
            autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <GameDefinition>(gameDefinition.Id))
            .Return(gameDefinition);

            existingPlayerWithMatchingGamingGroup = new Player
            {
                Id            = 1,
                GamingGroupId = GAMING_GROUP_ID
            };
            autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <Player>(Arg <int> .Is.Anything)).Return(existingPlayerWithMatchingGamingGroup);
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker <AuthTokenGenerator>();
            _autoMocker.PartialMockTheClassUnderTest();

            IAppSettings appSettingsMock = MockRepository.GenerateMock <IAppSettings>();

            appSettingsMock.Expect(mock => mock[AuthTokenGenerator.APP_KEY_AUTH_TOKEN_SALT]).Return(_expectedSalt);

            _autoMocker.Get <IConfigurationManager>().Expect(mock => mock.AppSettings).Return(appSettingsMock);
            _autoMocker.ClassUnderTest.Expect(mock => mock.GenerateNewAuthToken()).Return(_expectedAuthToken);
            _autoMocker.ClassUnderTest.Expect(mock => mock.HashAuthToken(_expectedAuthToken))
            .Return(_expectedSaltedHashedAuthToken);

            _applicationUser = new ApplicationUser
            {
                Id = ApplicationUserId
            };

            _autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <ApplicationUser>(Arg <string> .Is.Anything)).Return(_applicationUser);

            _userDeviceAuthTokenWithNoDeviceId = new UserDeviceAuthToken
            {
                Id = 0,
                ApplicationUserId = ApplicationUserId,
                DeviceId          = null
            };
            _userDeviceAuthTokenThatDoesntExpire = new UserDeviceAuthToken
            {
                Id = 1,
                ApplicationUserId = ApplicationUserId
            };
            _userDeviceAuthTokenThatExpiresInTheFuture = new UserDeviceAuthToken
            {
                Id = 2,
                ApplicationUserId = ApplicationUserId,
                DeviceId          = "device id for future expiration",
                AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(1)
            };
            _userDeviceAuthTokenThatExpiresInThePast = new UserDeviceAuthToken
            {
                Id = 3,
                ApplicationUserId = ApplicationUserId,
                DeviceId          = "device id for already expired",
                AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(-1)
            };
            var authTokens = new List <UserDeviceAuthToken>
            {
                _userDeviceAuthTokenWithNoDeviceId,
                _userDeviceAuthTokenThatDoesntExpire,
                _userDeviceAuthTokenThatExpiresInTheFuture,
                _userDeviceAuthTokenThatExpiresInThePast,
                new UserDeviceAuthToken
                {
                    ApplicationUserId = "some other applicationUserId"
                }
            }.AsQueryable();

            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <UserDeviceAuthToken>()).Return(authTokens);
        }
Ejemplo n.º 6
0
        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 virtual void SetUp()
		{
            AutomapperConfiguration.Configure();
            autoMocker = new RhinoAutoMocker<PlayerController>();
            autoMocker.PartialMockTheClassUnderTest();
            autoMocker.ClassUnderTest.Url = MockRepository.GenerateMock<UrlHelper>();

            currentUser = new ApplicationUser()
			{
				CurrentGamingGroupId = 123,
				Id = "app user id"
			};

			autoMocker.Get<HttpRequestBase>().Expect(x => x.Headers)
				.Repeat.Any()
				.Return(new System.Net.WebHeaderCollection
                {
                    { "X-Requested-With", "XMLHttpRequest" }
                });

			var context = MockRepository.GenerateMock<HttpContextBase>();
			context.Expect(x => x.Request)
				.Repeat.Any()
				.Return(autoMocker.Get<HttpRequestBase>());

			autoMocker.Get<HttpRequestBase>().Expect(mock => mock.Url)
							.Return(new Uri("https://nemestats.com/Details/1"));

			autoMocker.ClassUnderTest.ControllerContext = new ControllerContext(context, new RouteData(), autoMocker.ClassUnderTest);
			autoMocker.Get<IPlayerSummaryBuilder>().Expect(mock => mock.GetTopPlayers(Arg<int>.Is.Anything)).Return(new List<TopPlayer>());
			autoMocker.Get<INemesisHistoryRetriever>().Expect(mock => mock.GetRecentNemesisChanges(Arg<int>.Is.Anything)).Return(new List<NemesisChange>());
			autoMocker.Get<INemesisChangeViewModelBuilder>().Expect(mock => mock.Build(Arg<List<NemesisChange>>.Is.Anything)).Return(new List<NemesisChangeViewModel>());
			autoMocker.ClassUnderTest.Expect(mock => mock.ShowTopPlayers()).Return(new ViewResult { ViewName = MVC.Player.Views.TopPlayers, ViewData = new ViewDataDictionary(expectedTopPlayersViewModel) });
			autoMocker.ClassUnderTest.Expect(mock => mock.ShowRecentNemesisChanges()).Return(new ViewResult { ViewName = MVC.Player.Views.RecentNemesisChanges, ViewData = new ViewDataDictionary(expectedNemesisChangeViewModel) });
		}
Ejemplo n.º 8
0
        public void TestSetUp()
        {
            autoMocker = new RhinoAutoMocker<PlayedGameSaver>();
            autoMocker.PartialMockTheClassUnderTest();

            currentUser = new ApplicationUser
            {
                Id = "user id",
                CurrentGamingGroupId = GAMING_GROUP_ID,
                AnonymousClientId = "anonymous client id"
            };
            gameDefinition = new GameDefinition
            {
                Name = "game definition name",
                GamingGroupId = GAMING_GROUP_ID,
                Id = 9598
            };

            autoMocker.Get<ISecuredEntityValidator>().Expect(mock => mock.RetrieveAndValidateAccess<GameDefinition>(Arg<int>.Is.Anything, Arg<ApplicationUser>.Is.Anything)).Return(gameDefinition);

            existingPlayerWithMatchingGamingGroup = new Player
            {
                Id = 1,
                GamingGroupId = GAMING_GROUP_ID
            };
            autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<Player>(Arg<int>.Is.Anything)).Return(existingPlayerWithMatchingGamingGroup);
        }
Ejemplo n.º 9
0
        public void ItUpdatesTheAspNetUsersAuthenticationTokenWithAHashedAndSaltedToken()
        {
            autoMocker.PartialMockTheClassUnderTest();
            const string expectedAuthToken = "some auth token";

            autoMocker.ClassUnderTest.Expect(mock => mock.GenerateNewAuthToken()).Return(expectedAuthToken);
            const string expectedSaltedHashedAuthToken = "some salted hashed auth token";

            autoMocker.ClassUnderTest.Expect(mock => mock.HashAuthToken(expectedAuthToken))
            .Return(expectedSaltedHashedAuthToken);

            autoMocker.ClassUnderTest.GenerateAuthToken(applicationUserId);

            autoMocker.Get <IDataContext>().AssertWasCalled(mock => mock.Save(Arg <ApplicationUser> .Matches(user => user.Id == applicationUserId &&
                                                                                                             user.AuthenticationToken == expectedSaltedHashedAuthToken),
                                                                              Arg <ApplicationUser> .Is.Anything));
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker<AuthTokenGenerator>();
            _autoMocker.PartialMockTheClassUnderTest();

            IAppSettings appSettingsMock = MockRepository.GenerateMock<IAppSettings>();
            appSettingsMock.Expect(mock => mock[AuthTokenGenerator.APP_KEY_AUTH_TOKEN_SALT]).Return(_expectedSalt);

            _autoMocker.Get<IConfigurationManager>().Expect(mock => mock.AppSettings).Return(appSettingsMock);
            _autoMocker.ClassUnderTest.Expect(mock => mock.GenerateNewAuthToken()).Return(_expectedAuthToken);
            _autoMocker.ClassUnderTest.Expect(mock => mock.HashAuthToken(_expectedAuthToken))
                      .Return(_expectedSaltedHashedAuthToken);

            _applicationUser = new ApplicationUser
            {
                Id = ApplicationUserId
            };

            _autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<ApplicationUser>(Arg<string>.Is.Anything)).Return(_applicationUser);

            _userDeviceAuthTokenWithNoDeviceId = new UserDeviceAuthToken
            {
                Id = 0,
                ApplicationUserId = ApplicationUserId,
                DeviceId = null
            };
            _userDeviceAuthTokenThatDoesntExpire = new UserDeviceAuthToken
            {
                Id = 1,
                ApplicationUserId = ApplicationUserId
            };
            _userDeviceAuthTokenThatExpiresInTheFuture = new UserDeviceAuthToken
            {
                Id = 2,
                ApplicationUserId = ApplicationUserId,
                DeviceId = "device id for future expiration",
                AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(1)
            };
            _userDeviceAuthTokenThatExpiresInThePast = new UserDeviceAuthToken
            {
                Id = 3,
                ApplicationUserId = ApplicationUserId,
                DeviceId = "device id for already expired",
                AuthenticationTokenExpirationDate = DateTime.UtcNow.AddDays(-1)
            };
            var authTokens = new List<UserDeviceAuthToken>
            {
                _userDeviceAuthTokenWithNoDeviceId,
                _userDeviceAuthTokenThatDoesntExpire,
                _userDeviceAuthTokenThatExpiresInTheFuture,
                _userDeviceAuthTokenThatExpiresInThePast,
                new UserDeviceAuthToken
                {
                    ApplicationUserId = "some other applicationUserId"
                }
            }.AsQueryable();
            _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<UserDeviceAuthToken>()).Return(authTokens);
        }
Ejemplo n.º 11
0
        public void ItFiltersPlayedGamesThatHappenedAfterTheToDate()
        {
            var autoMocker = new RhinoAutoMocker <PlayerRetriever>();

            autoMocker.PartialMockTheClassUnderTest();

            var gamingGroupId = 1;
            var toDate        = new DateTime(2015, 1, 1);
            var expectedNemePointsAwardedForEachGame = 50;
            var queryable = new List <Player>
            {
                new Player
                {
                    GamingGroupId     = gamingGroupId,
                    PlayerGameResults = new List <PlayerGameResult>
                    {
                        new PlayerGameResult
                        {
                            GameRank   = 2,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = toDate.AddDays(-1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        },
                        new PlayerGameResult
                        {
                            GameRank   = 1,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = toDate.AddDays(1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        }
                    },
                    ChampionedGames = new List <Champion>()
                }
            }.AsQueryable();

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(queryable);

            autoMocker.ClassUnderTest.Expect(mock => mock.PopulateNemePointsSummary(Arg <int> .Is.Anything, Arg <List <PlayerWithNemesis> > .Is.Anything, Arg <IDateRangeFilter> .Is.Anything));


            var dateRangeFilter = new BasicDateRangeFilter
            {
                ToDate = toDate
            };

            var players = autoMocker.ClassUnderTest.GetAllPlayersWithNemesisInfo(gamingGroupId, dateRangeFilter);

            Assert.That(players.Count, Is.EqualTo(1));
            var player = players.First();

            Assert.That(player.GamesLost, Is.EqualTo(1));
            Assert.That(player.GamesWon, Is.EqualTo(0));
        }
Ejemplo n.º 12
0
        public void ItReturnsTheUnsaltedUnhashedAuthToken()
        {
            _autoMocker.PartialMockTheClassUnderTest();
            var expectedAuthToken = "some token";

            _autoMocker.ClassUnderTest.Expect(mock => mock.GenerateNewAuthToken()).Return(expectedAuthToken);

            var actualAuthToken = _autoMocker.ClassUnderTest.GenerateAuthToken("some id");

            Assert.That(actualAuthToken.AuthenticationTokenString, Is.EqualTo(expectedAuthToken));
        }
 public virtual void SetUp()
 {
     autoMocker = new RhinoAutoMocker<GamingGroupController>();
     autoMocker.PartialMockTheClassUnderTest();
    
     currentUser = new ApplicationUser()
     {
         Id = "user  id",
         CurrentGamingGroupId = 1315
     };
 }
        public void BaseSetUp()
        {
            autoMocker = new RhinoAutoMocker<GameDefinitionSaver>();
            autoMocker.PartialMockTheClassUnderTest();

            currentUser = new ApplicationUser
            {
                Id = "some application user id",
                CurrentGamingGroupId = 100
            };
        }
Ejemplo n.º 15
0
        public void BaseSetUp()
        {
            autoMocker = new RhinoAutoMocker <BoardGameGeekUserSaver>();
            autoMocker.PartialMockTheClassUnderTest();

            currentUser = new ApplicationUser
            {
                Id = "some application user id",
                CurrentGamingGroupId = 100
            };
        }
        public virtual void SetUp()
        {
            autoMocker = new RhinoAutoMocker <GamingGroupController>();
            autoMocker.PartialMockTheClassUnderTest();

            currentUser = new ApplicationUser()
            {
                Id = "user  id",
                CurrentGamingGroupId = 1315
            };
        }
Ejemplo n.º 17
0
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker <UniversalAnalyticsNemeStatsEventTracker>();
            _autoMocker.PartialMockTheClassUnderTest();

            analyticsEvent = MockRepository.GenerateMock <IUniversalAnalyticsEvent>();

            currentUser = new ApplicationUser
            {
                AnonymousClientId = "anonymous id"
            };
        }
Ejemplo n.º 18
0
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker <AchievementRetriever>();
            _autoMocker.PartialMockTheClassUnderTest();

            _currentUser = new ApplicationUser();

            _achievement1        = new AchievementOne();
            _achievement2        = new AchievementTwo();
            _achievementNoOneHas = new AchievementNoOneHas();

            _allAchievements = new List <IAchievement>
            {
                _achievementNoOneHas,
                _achievement1,
                _achievement2
            };
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetAllAchievements()).Return(_allAchievements);

            _playerAchievements = new List <PlayerAchievement>
            {
                new PlayerAchievement
                {
                    AchievementId = _achievement2.Id,
                    Player        = new Player()
                },
                new PlayerAchievement
                {
                    AchievementId = _achievement1.Id,
                    Player        = new Player
                    {
                        ApplicationUserId = _currentUser.Id
                    }
                },
                new PlayerAchievement
                {
                    AchievementId = _achievement1.Id,
                    Player        = new Player()
                }
            };
            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerAchievement>()).Return(_playerAchievements.AsQueryable());
        }
Ejemplo n.º 19
0
        public virtual void SetUp()
        {
            AutomapperConfiguration.Configure();
            autoMocker = new RhinoAutoMocker <PlayerController>();
            autoMocker.PartialMockTheClassUnderTest();
            autoMocker.ClassUnderTest.Url = MockRepository.GenerateMock <UrlHelper>();

            currentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = 123,
                Id = "app user id"
            };

            autoMocker.Get <HttpRequestBase>().Expect(x => x.Headers)
            .Repeat.Any()
            .Return(new System.Net.WebHeaderCollection
            {
                { "X-Requested-With", "XMLHttpRequest" }
            });

            var context = MockRepository.GenerateMock <HttpContextBase>();

            context.Expect(x => x.Request)
            .Repeat.Any()
            .Return(autoMocker.Get <HttpRequestBase>());

            autoMocker.Get <HttpRequestBase>().Expect(mock => mock.Url)
            .Return(new Uri("https://nemestats.com/Details/1"));

            autoMocker.ClassUnderTest.ControllerContext = new ControllerContext(context, new RouteData(), autoMocker.ClassUnderTest);
            autoMocker.Get <IPlayerSummaryBuilder>().Expect(mock => mock.GetTopPlayers(Arg <int> .Is.Anything)).Return(new List <TopPlayer>());
            autoMocker.Get <INemesisHistoryRetriever>().Expect(mock => mock.GetRecentNemesisChanges(Arg <int> .Is.Anything)).Return(new List <NemesisChange>());
            autoMocker.Get <INemesisChangeViewModelBuilder>().Expect(mock => mock.Build(Arg <List <NemesisChange> > .Is.Anything)).Return(new List <NemesisChangeViewModel>());
            autoMocker.ClassUnderTest.Expect(mock => mock.ShowTopPlayers()).Return(new ViewResult {
                ViewName = MVC.Player.Views.TopPlayers, ViewData = new ViewDataDictionary(expectedTopPlayersViewModel)
            });
            autoMocker.ClassUnderTest.Expect(mock => mock.ShowRecentNemesisChanges()).Return(new ViewResult {
                ViewName = MVC.Player.Views.RecentNemesisChanges, ViewData = new ViewDataDictionary(expectedNemesisChangeViewModel)
            });
        }
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker <PlayerRetriever>();
            _autoMocker.PartialMockTheClassUnderTest();

            _expectedChampion = new Champion()
            {
                Id       = 100,
                PlayerId = 101,
                Player   = new Player()
            };
            _expectedNemesis = new Nemesis()
            {
                Id = 155,
                NemesisPlayerId = 8888,
                NemesisPlayer   = new Player()
            };
            _expectedPriorNemesis = new Nemesis()
            {
                Id = 22222,
                NemesisPlayerId = 4444,
                NemesisPlayer   = new Player()
            };
            var nemesisForPlayerWithOnlyACurrentNemesis = new Nemesis
            {
                Id            = 33333,
                NemesisPlayer = new Player()
            };

            _player = new Player()
            {
                Id   = 1351,
                Name = "the player",
                PlayerGameResults = new List <PlayerGameResult>(),
                GamingGroup       = new GamingGroup {
                    Id = _gamingGroupId, Name = "some gaming group name"
                },
                GamingGroupId     = _gamingGroupId,
                Active            = true,
                NemesisId         = _expectedNemesis.Id,
                Nemesis           = _expectedNemesis,
                PreviousNemesisId = _expectedPriorNemesis.Id,
                PreviousNemesis   = _expectedPriorNemesis,
                ApplicationUserId = "some user id"
            };
            _expectedFormerChampionGame = new GameDefinition
            {
                Id = 111,
                PreviousChampionId = _player.Id,
                GamingGroupId      = _gamingGroupId
            };
            _playerWithNoNemesisEver = new Player()
            {
                Id          = 161266939,
                GamingGroup = new GamingGroup {
                    Id = _gamingGroupId
                },
                GamingGroupId = _gamingGroupId
            };
            _playerWithOnlyACurrentNemesis = new Player()
            {
                Id          = 888484,
                NemesisId   = 7,
                Nemesis     = nemesisForPlayerWithOnlyACurrentNemesis,
                GamingGroup = new GamingGroup {
                    Id = _gamingGroupId
                },
                GamingGroupId = _gamingGroupId
            };
            _playerWithAChampionship = new Player()
            {
                Id          = 101,
                GamingGroup = new GamingGroup {
                    Id = _gamingGroupId
                }
            };

            var players = new List <Player>()
            {
                _player,
                _playerWithNoNemesisEver,
                _playerWithOnlyACurrentNemesis,
                _playerWithAChampionship
            };

            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(players.AsQueryable());

            _expectedPlayerStatistics = new PlayerStatistics
            {
                NemePointsSummary = new NemePointsSummary(1, 2, 4)
            };

            _autoMocker.ClassUnderTest.Expect(repo => repo.GetPlayerStatistics(Arg <int> .Is.Anything))
            .Repeat.Once()
            .Return(_expectedPlayerStatistics);

            var queryableApplicationUser = new List <ApplicationUser>
            {
                new ApplicationUser
                {
                    Id    = _player.ApplicationUserId,
                    Email = _expectedEmail
                }
            }.AsQueryable();

            _autoMocker.Get <IDataContext>()
            .Expect(mock => mock.GetQueryable <ApplicationUser>())
            .Return(queryableApplicationUser);

            _autoMocker.ClassUnderTest.Expect(mock => mock.GetPlayerGameResultsWithPlayedGameAndGameDefinition(
                                                  Arg <int> .Is.Anything,
                                                  Arg <int> .Is.Anything))
            .Repeat.Once()
            .Return(_player.PlayerGameResults.ToList());

            _expectedMinions = new List <Player>();
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetMinions(Arg <int> .Is.Anything))
            .Return(_expectedMinions);

            _expectedPlayerGameSummaries = new List <PlayerGameSummary>
            {
                new PlayerGameSummary()
            };
            _autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetPlayerGameSummaries(Arg <int> .Is.Anything, Arg <IDataContext> .Is.Anything))
            .Return(_expectedPlayerGameSummaries);

            _expectedChampionedGames = new List <Champion> {
                _expectedChampion
            };
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetChampionedGames(Arg <int> .Is.Anything))
            .Return(_expectedChampionedGames);

            _expectedFormerChampionedGames = new List <GameDefinition> {
                _expectedFormerChampionGame
            };
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetFormerChampionedGames(Arg <int> .Is.Anything))
            .Return(_expectedFormerChampionedGames);

            _expectedPlayerVersusPlayerStatistics = new List <PlayerVersusPlayerStatistics>();
            _autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetPlayerVersusPlayersStatistics(Arg <int> .Is.Anything, Arg <IDataContext> .Is.Anything))
            .Return(_expectedPlayerVersusPlayerStatistics);

            _autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetLongestWinningStreak(Arg <int> .Is.Equal(_player.Id), Arg <IDataContext> .Is.Anything)).Return(_expectedLongestWinningStreak);

            _expectedPlayerAchievementWinnersPageableList = new List <PlayerAchievementWinner>
            {
                new PlayerAchievementWinner(),
                new PlayerAchievementWinner()
            }.ToPagedList(1, 2);

            _autoMocker.Get <IRecentPlayerAchievementsUnlockedRetriever>()
            .Expect(mock => mock.GetResults(Arg <GetRecentPlayerAchievementsUnlockedQuery> .Is.Anything))
            .Return(_expectedPlayerAchievementWinnersPageableList);
        }
Ejemplo n.º 21
0
 public virtual void SetUp()
 {
     _autoMocker = new RhinoAutoMocker<PointsCalculator>();
     _autoMocker.PartialMockTheClassUnderTest();
 }
        public void FixtureSetUp()
        {
            _autoMocker = new RhinoAutoMocker <GameDefinitionDetailsViewModelBuilder>();
            _autoMocker.PartialMockTheClassUnderTest();

            _expectedPlayerSummary1 = new GameDefinitionPlayerSummaryViewModel();
            _expectedPlayerSummary2 = new GameDefinitionPlayerSummaryViewModel();

            List <PlayedGame> playedGames = new List <PlayedGame>();

            playedGames.Add(new PlayedGame
            {
                Id = 10
            });
            _playedGameDetailsViewModel1 = new PlayedGameDetailsViewModel();
            playedGames.Add(new PlayedGame
            {
                Id = 11
            });
            _playedGameDetailsViewModel2 = new PlayedGameDetailsViewModel();
            _championPlayer = new Player
            {
                Name   = _championName,
                Id     = _championPlayerId,
                Active = true
            };
            _previousChampionPlayer = new Player
            {
                Name   = _previousChampionName,
                Id     = _previousChampionPlayerId,
                Active = false
            };
            _champion = new Champion
            {
                Player        = _championPlayer,
                WinPercentage = _championWinPercentage,
                NumberOfGames = _championNumberOfGames,
                NumberOfWins  = _championNumberOfWins
            };
            _previousChampion = new Champion
            {
                Player = _previousChampionPlayer
            };
            _playerWinRecord1 = new PlayerWinRecord
            {
                GamesWon      = 1,
                GamesLost     = 2,
                PlayerName    = "player name",
                WinPercentage = 33,
                PlayerId      = 3
            };
            _playerWinRecord2 = new PlayerWinRecord();

            _autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <GameDefinitionPlayerSummaryViewModel>(_playerWinRecord1))
            .Return(_expectedPlayerSummary1);
            _autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <GameDefinitionPlayerSummaryViewModel>(_playerWinRecord2))
            .Return(_expectedPlayerSummary2);

            _gameDefinitionSummary = new GameDefinitionSummary
            {
                Id                            = 1,
                Name                          = "game definition name",
                Description                   = "game definition description",
                GamingGroupId                 = _gamingGroupid,
                GamingGroupName               = "gaming group name",
                PlayedGames                   = playedGames,
                TotalNumberOfGamesPlayed      = 3,
                AveragePlayersPerGame         = 2.2M,
                BoardGameGeekGameDefinitionId = 123,
                BoardGameGeekGameDefinition   = new BoardGameGeekGameDefinition()
                {
                    Id = 123
                },
                Champion         = _champion,
                PreviousChampion = _previousChampion,
                PlayerWinRecords = new List <PlayerWinRecord>
                {
                    _playerWinRecord1,
                    _playerWinRecord2
                },
                BoardGameGeekInfo = new BoardGameGeekInfo()
            };
            _currentUser = new ApplicationUser
            {
                CurrentGamingGroupId = _gamingGroupid
            };
            _autoMocker.Get <IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_gameDefinitionSummary.PlayedGames[0], _currentUser, true))
            .Return(_playedGameDetailsViewModel1);
            _autoMocker.Get <IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_gameDefinitionSummary.PlayedGames[1], _currentUser, true))
            .Return(_playedGameDetailsViewModel2);

            _expectedBoardGameGeekInfo = new BoardGameGeekInfoViewModel();
            _autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <BoardGameGeekInfoViewModel>(_gameDefinitionSummary.BoardGameGeekInfo))
            .Return(_expectedBoardGameGeekInfo);

            _expectedRegisteredUserDictionary = new Dictionary <int, string>
            {
                { _playerWinRecord1.PlayerId, _expectedPlayer1Email }
            };

            _viewModel = _autoMocker.ClassUnderTest.Build(_gameDefinitionSummary, _expectedRegisteredUserDictionary, _currentUser);
        }
Ejemplo n.º 23
0
        public virtual void BaseSetUp()
        {
            autoMocker = new RhinoAutoMocker<PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();
            const int CHAMPION_ID = 55;

            gameDefinition = new GameDefinition
            {
                Name = "game name",
                ChampionId = CHAMPION_ID
            };

            var playerId = 1;
            var champion = new Champion
            {
                Id = CHAMPION_ID,
                GameDefinition = gameDefinition,
                PlayerId = playerId
            };

            playerGameResultsForFirstPlayer = new List<PlayerGameResult>()
            {
                new PlayerGameResult
                {
                    GameRank = 2,
                    NemeStatsPointsAwarded = 10,
                    PlayedGame = new PlayedGame
                    {
                        DatePlayed = new BasicDateRangeFilter().FromDate
                    }
                },
                new PlayerGameResult
                {
                    GameRank = 1,
                    NemeStatsPointsAwarded = 20,
                    PlayedGame = new PlayedGame
                    {
                        DatePlayed = new BasicDateRangeFilter().ToDate
                    }
                }};

            playerChampionshipsForFirstPlayer = new List<Champion>
            {
                champion
            };
            List<Player> players = new List<Player>()
            {
                new Player(){ GamingGroupId = gamingGroupId, Name = "2", PlayerGameResults = new List<PlayerGameResult>(), ChampionedGames = new List<Champion>()},
                new Player(){ GamingGroupId = gamingGroupId, Name = "3", PlayerGameResults = new List<PlayerGameResult>(), ChampionedGames = new List<Champion>() },
                new Player(){ GamingGroupId = -1, Name = "not in gaming group", PlayerGameResults = new List<PlayerGameResult>(), ChampionedGames = new List<Champion>() },
                new Player()
                {
                    Id = playerId,
                    GamingGroupId = gamingGroupId, 
                    Name = "1", 
                    PlayerGameResults = playerGameResultsForFirstPlayer,
                    ChampionedGames = new List<Champion>
                    {
                        champion
                    }
                },
                new Player()
                {
                    //player that will be last because she's inactive
                    GamingGroupId = gamingGroupId, Name = "0", PlayerGameResults = new List<PlayerGameResult>(), ChampionedGames = new List<Champion>(), Active = false 
                }
            };
            players[3].NemesisId = 1;
            players[3].Nemesis = new Nemesis()
            {
                NemesisPlayerId = 2,
                NemesisPlayer = new Player() { Id = 93995 }
            };
            playerQueryable = players.AsQueryable<Player>();

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Player>())
                .Return(playerQueryable);

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<GameDefinition>())
                .Return(
                new List<GameDefinition>
                { gameDefinition }.AsQueryable());

            var playerAchievement =
                new PlayerAchievement
                {
                    DateCreated = DateTime.UtcNow,
                    LastUpdatedDate = DateTime.UtcNow,
                    PlayerId = playerId,
                    AchievementLevel = AchievementLevel.Bronze,
                    AchievementId = AchievementId.BusyBee
                };
            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<PlayerAchievement>())
                .Return(new List<PlayerAchievement> { playerAchievement }.AsQueryable());
        }
Ejemplo n.º 24
0
 public void InitMock()
 {
     Achievement = new RhinoAutoMocker <T>();
     Achievement.PartialMockTheClassUnderTest();
 }
Ejemplo n.º 25
0
        public void SetUp()
        {
            autoMocker = new RhinoAutoMocker <PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();

            expectedChampion = new Champion()
            {
                Id       = 100,
                PlayerId = 101,
                Player   = new Player()
            };
            expectedNemesis = new Nemesis()
            {
                Id = 155,
                NemesisPlayerId = 8888,
                NemesisPlayer   = new Player()
            };
            expectedPriorNemesis = new Nemesis()
            {
                Id = 22222,
                NemesisPlayerId = 4444,
                NemesisPlayer   = new Player()
            };
            var nemesisForPlayerWithOnlyACurrentNemesis = new Nemesis
            {
                Id            = 33333,
                NemesisPlayer = new Player()
            };

            player = new Player()
            {
                Id   = 1351,
                Name = "the player",
                PlayerGameResults = new List <PlayerGameResult>(),
                GamingGroup       = new GamingGroup {
                    Id = gamingGroupId
                },
                GamingGroupId     = gamingGroupId,
                Active            = true,
                NemesisId         = expectedNemesis.Id,
                Nemesis           = expectedNemesis,
                PreviousNemesisId = expectedPriorNemesis.Id,
                PreviousNemesis   = expectedPriorNemesis
            };
            expectedFormerChampionGame = new GameDefinition
            {
                Id = 111,
                PreviousChampionId = player.Id,
                GamingGroupId      = gamingGroupId
            };
            playerWithNoNemesisEver = new Player()
            {
                Id          = 161266939,
                GamingGroup = new GamingGroup {
                    Id = gamingGroupId
                },
                GamingGroupId = gamingGroupId
            };
            playerWithOnlyACurrentNemesis = new Player()
            {
                Id          = 888484,
                NemesisId   = 7,
                Nemesis     = nemesisForPlayerWithOnlyACurrentNemesis,
                GamingGroup = new GamingGroup {
                    Id = gamingGroupId
                },
                GamingGroupId = gamingGroupId
            };
            playerWithAChampionship = new Player()
            {
                Id          = 101,
                GamingGroup = new GamingGroup {
                    Id = gamingGroupId
                }
            };

            var players = new List <Player>()
            {
                player,
                playerWithNoNemesisEver,
                playerWithOnlyACurrentNemesis,
                playerWithAChampionship
            };

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(players.AsQueryable());

            expectedPlayerStatistics = new PlayerStatistics
            {
                NemePointsSummary = new NemePointsSummary(1, 2, 4)
            };

            autoMocker.ClassUnderTest.Expect(repo => repo.GetPlayerStatistics(Arg <int> .Is.Anything))
            .Repeat.Once()
            .Return(expectedPlayerStatistics);

            autoMocker.ClassUnderTest.Expect(mock => mock.GetPlayerGameResultsWithPlayedGameAndGameDefinition(
                                                 Arg <int> .Is.Anything,
                                                 Arg <int> .Is.Anything))
            .Repeat.Once()
            .Return(player.PlayerGameResults.ToList());

            this.expectedMinions = new List <Player>();
            autoMocker.ClassUnderTest.Expect(mock => mock.GetMinions(Arg <int> .Is.Anything))
            .Return(this.expectedMinions);

            expectedPlayerGameSummaries = new List <PlayerGameSummary>
            {
                new PlayerGameSummary()
            };
            autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetPlayerGameSummaries(Arg <int> .Is.Anything))
            .Return(expectedPlayerGameSummaries);

            expectedChampionedGames = new List <Champion> {
                expectedChampion
            };
            autoMocker.ClassUnderTest.Expect(mock => mock.GetChampionedGames(Arg <int> .Is.Anything))
            .Return(expectedChampionedGames);

            expectedFormerChampionedGames = new List <GameDefinition> {
                expectedFormerChampionGame
            };
            autoMocker.ClassUnderTest.Expect(mock => mock.GetFormerChampionedGames(Arg <int> .Is.Anything))
            .Return(expectedFormerChampionedGames);

            expectedPlayerVersusPlayerStatistics = new List <PlayerVersusPlayerStatistics>();
            autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetPlayerVersusPlayersStatistics(Arg <int> .Is.Anything))
            .Return(expectedPlayerVersusPlayerStatistics);

            autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetLongestWinningStreak(player.Id)).Return(expectedLongestWinningStreak);

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerAchievement>()).Return(new List <PlayerAchievement>().AsQueryable());
        }
Ejemplo n.º 26
0
        public void SetUp()
        {
            autoMocker = new RhinoAutoMocker<PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();
          
            expectedChampion = new Champion()
            {
                Id = 100,
                PlayerId = 101,
                Player = new Player()
            };
            expectedNemesis = new Nemesis()
            {
                Id = 155,
                NemesisPlayerId = 8888,
                NemesisPlayer = new Player()
            };
            expectedPriorNemesis = new Nemesis()
            {
                Id = 22222,
                NemesisPlayerId = 4444,
                NemesisPlayer = new Player()
            };
            var nemesisForPlayerWithOnlyACurrentNemesis = new Nemesis
            {
                Id = 33333,
                NemesisPlayer = new Player()
            };
            player = new Player()
            {
                Id = 1351,
                Name = "the player",
                PlayerGameResults = new List<PlayerGameResult>(),
                GamingGroup = new GamingGroup{ Id = gamingGroupId },
                GamingGroupId = gamingGroupId,
                Active = true,
                NemesisId = expectedNemesis.Id,
                Nemesis = expectedNemesis,
                PreviousNemesisId = expectedPriorNemesis.Id,
                PreviousNemesis = expectedPriorNemesis
            };
            expectedFormerChampionGame = new GameDefinition
            {
                Id = 111,
                PreviousChampionId = player.Id,
                GamingGroupId = gamingGroupId
            };
            playerWithNoNemesisEver = new Player()
            {
                Id = 161266939,
                GamingGroup = new GamingGroup { Id = gamingGroupId },
                GamingGroupId = gamingGroupId
            };
            playerWithOnlyACurrentNemesis = new Player()
            {
                Id = 888484,
                NemesisId = 7,
                Nemesis = nemesisForPlayerWithOnlyACurrentNemesis,
                GamingGroup = new GamingGroup { Id = gamingGroupId },
                GamingGroupId = gamingGroupId
            };
            playerWithAChampionship = new Player()
            {
                Id = 101,
                GamingGroup = new GamingGroup { Id = gamingGroupId }
            };

            var players = new List<Player>()
            {
                player,
                playerWithNoNemesisEver,
                playerWithOnlyACurrentNemesis,
                playerWithAChampionship
            };

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Player>())
                                               .Return(players.AsQueryable());

            expectedPlayerStatistics = new PlayerStatistics
            {
                NemePointsSummary = new NemePointsSummary(1, 2, 4)
            };

            autoMocker.ClassUnderTest.Expect(repo => repo.GetPlayerStatistics(Arg<int>.Is.Anything))
                .Repeat.Once()
                .Return(expectedPlayerStatistics);

            autoMocker.ClassUnderTest.Expect(mock => mock.GetPlayerGameResultsWithPlayedGameAndGameDefinition(
                Arg<int>.Is.Anything, 
                Arg<int>.Is.Anything))
                            .Repeat.Once()
                            .Return(player.PlayerGameResults.ToList());

            this.expectedMinions = new List<Player>();
            autoMocker.ClassUnderTest.Expect(mock => mock.GetMinions(Arg<int>.Is.Anything))
                .Return(this.expectedMinions);

            expectedPlayerGameSummaries = new List<PlayerGameSummary>
            {
                new PlayerGameSummary()
            };
            autoMocker.Get<IPlayerRepository>().Expect(mock => mock.GetPlayerGameSummaries(Arg<int>.Is.Anything))
                                .Return(expectedPlayerGameSummaries);

            expectedChampionedGames = new List<Champion> { expectedChampion };
            autoMocker.ClassUnderTest.Expect(mock => mock.GetChampionedGames(Arg<int>.Is.Anything))
                .Return(expectedChampionedGames);

            expectedFormerChampionedGames = new List<GameDefinition> { expectedFormerChampionGame };
            autoMocker.ClassUnderTest.Expect(mock => mock.GetFormerChampionedGames(Arg<int>.Is.Anything))
                .Return(expectedFormerChampionedGames);

            expectedPlayerVersusPlayerStatistics = new List<PlayerVersusPlayerStatistics>();
            autoMocker.Get<IPlayerRepository>().Expect(mock => mock.GetPlayerVersusPlayersStatistics(Arg<int>.Is.Anything))
                      .Return(expectedPlayerVersusPlayerStatistics);

            autoMocker.Get<IPlayerRepository>().Expect(mock => mock.GetLongestWinningStreak(player.Id)).Return(expectedLongestWinningStreak);

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<PlayerAchievement>()).Return(new List<PlayerAchievement>().AsQueryable());

        }
        public void FixtureSetUp()
        {
            _autoMocker = new RhinoAutoMocker<GameDefinitionDetailsViewModelBuilder>();
            _autoMocker.PartialMockTheClassUnderTest();

            _expectedPlayerSummary1 = new GameDefinitionPlayerSummaryViewModel();
            _expectedPlayerSummary2 = new GameDefinitionPlayerSummaryViewModel();

            List<PlayedGame> playedGames = new List<PlayedGame>();
            playedGames.Add(new PlayedGame
            {
                    Id = 10
                });
            _playedGameDetailsViewModel1 = new PlayedGameDetailsViewModel();
            playedGames.Add(new PlayedGame
            {
                Id = 11
            });
            _playedGameDetailsViewModel2 = new PlayedGameDetailsViewModel();
            _championPlayer = new Player
            {
                Name = _championName,
                Id = _championPlayerId,
                Active = true
            };
            _previousChampionPlayer = new Player
            {
                Name = _previousChampionName,
                Id = _previousChampionPlayerId,
                Active = false
            };
            _champion = new Champion
            {
                Player = _championPlayer,
                WinPercentage = _championWinPercentage,
                NumberOfGames = _championNumberOfGames,
                NumberOfWins = _championNumberOfWins
            };
            _previousChampion = new Champion
            {
                Player = _previousChampionPlayer
            };
            _playerWinRecord1 = new PlayerWinRecord
            {
                GamesWon = 1,
                GamesLost = 2,
                PlayerName = "player name",
                WinPercentage = 33,
                PlayerId = 3
            };
            _playerWinRecord2 = new PlayerWinRecord();

            _autoMocker.Get<ITransformer>().Expect(mock => mock.Transform<GameDefinitionPlayerSummaryViewModel>(_playerWinRecord1))
                       .Return(_expectedPlayerSummary1);
            _autoMocker.Get<ITransformer>().Expect(mock => mock.Transform<GameDefinitionPlayerSummaryViewModel>(_playerWinRecord2))
                 .Return(_expectedPlayerSummary2); 

            _gameDefinitionSummary = new GameDefinitionSummary
            {
                Id = 1,
                Name = "game definition name",
                Description = "game definition description",
                GamingGroupId = _gamingGroupid,
                GamingGroupName = "gaming group name",
                PlayedGames = playedGames,
                TotalNumberOfGamesPlayed = 3,
                AveragePlayersPerGame = 2.2M,
                BoardGameGeekGameDefinitionId = 123,
                BoardGameGeekGameDefinition = new BoardGameGeekGameDefinition() { Id = 123},
                Champion = _champion,
                PreviousChampion = _previousChampion,
                PlayerWinRecords = new List<PlayerWinRecord>
                {
                    _playerWinRecord1,
                    _playerWinRecord2
                },
                BoardGameGeekInfo = new BoardGameGeekInfo()
            };
            _currentUser = new ApplicationUser
            {
                CurrentGamingGroupId = _gamingGroupid
            };
            _autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_gameDefinitionSummary.PlayedGames[0], _currentUser, true))
                .Return(_playedGameDetailsViewModel1);
            _autoMocker.Get<IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(_gameDefinitionSummary.PlayedGames[1], _currentUser, true))
                .Return(_playedGameDetailsViewModel2);

            _expectedBoardGameGeekInfo = new BoardGameGeekInfoViewModel();
            _autoMocker.Get<ITransformer>().Expect(mock => mock.Transform<BoardGameGeekInfoViewModel>(_gameDefinitionSummary.BoardGameGeekInfo))
                .Return(_expectedBoardGameGeekInfo);

            _viewModel = _autoMocker.ClassUnderTest.Build(_gameDefinitionSummary, _currentUser);
        }
        public void ItFiltersPlayedGamesThatHappenedBeforeTheFromDate()
        {
            var autoMocker = new RhinoAutoMocker<PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();
            var gamingGroupId = 1;
            var fromDate = new DateTime(2015, 6, 1);
            var expectedNemePointsAwardedForEachGame = 50;
            var queryable = new List<Player>
            {
                new Player
                {
                    GamingGroupId = gamingGroupId,
                    PlayerGameResults = new List<PlayerGameResult>
                    {
                        new PlayerGameResult
                        {
                            GameRank = 2,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = fromDate.AddDays(-1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        },
                        new PlayerGameResult
                        {
                            GameRank = 1,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = fromDate.AddDays(1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        },
                        new PlayerGameResult
                        {
                            GameRank = 1,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = fromDate.AddDays(-1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        }
                    },
                    ChampionedGames = new List<Champion>()
                }
            }.AsQueryable();
            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Player>())
                .Return(queryable);
            autoMocker.ClassUnderTest.Expect(mock => mock.PopulateNemePointsSummary(Arg<int>.Is.Anything, Arg<List<PlayerWithNemesis>>.Is.Anything, Arg<IDateRangeFilter>.Is.Anything));

            var dateRangeFilter = new BasicDateRangeFilter
            {
                FromDate = fromDate
            };

            var players = autoMocker.ClassUnderTest.GetAllPlayersWithNemesisInfo(gamingGroupId, dateRangeFilter);

            Assert.That(players.Count, Is.EqualTo(1));
            var player = players.First();
            Assert.That(player.GamesLost, Is.EqualTo(0));
            Assert.That(player.GamesWon, Is.EqualTo(1));
        }
Ejemplo n.º 29
0
 public virtual void SetUp()
 {
     _autoMocker = new RhinoAutoMocker <PointsCalculator>();
     _autoMocker.PartialMockTheClassUnderTest();
 }
Ejemplo n.º 30
0
        public void ItFiltersPlayedGamesThatHappenedBeforeTheFromDate()
        {
            var autoMocker = new RhinoAutoMocker <PlayerRetriever>();

            autoMocker.PartialMockTheClassUnderTest();
            var gamingGroupId = 1;
            var fromDate      = new DateTime(2015, 6, 1);
            var expectedNemePointsAwardedForEachGame = 50;
            var queryable = new List <Player>
            {
                new Player
                {
                    GamingGroupId     = gamingGroupId,
                    PlayerGameResults = new List <PlayerGameResult>
                    {
                        new PlayerGameResult
                        {
                            GameRank   = 2,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = fromDate.AddDays(-1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        },
                        new PlayerGameResult
                        {
                            GameRank   = 1,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = fromDate.AddDays(1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        },
                        new PlayerGameResult
                        {
                            GameRank   = 1,
                            PlayedGame = new PlayedGame
                            {
                                DatePlayed = fromDate.AddDays(-1)
                            },
                            NemeStatsPointsAwarded = expectedNemePointsAwardedForEachGame
                        }
                    },
                    //--have to do this because entity framework can handle the null relationship, but pure LINQ cannot :(
                    Nemesis = new Nemesis
                    {
                        NemesisPlayer = new Player()
                    },
                    PreviousNemesis = new Nemesis
                    {
                        NemesisPlayer = new Player()
                    },
                    ChampionedGames = new List <Champion>()
                }
            }.AsQueryable();

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(queryable);
            autoMocker.ClassUnderTest.Expect(mock => mock.PopulateNemePointsSummary(Arg <int> .Is.Anything, Arg <List <PlayerWithNemesis> > .Is.Anything, Arg <IDateRangeFilter> .Is.Anything));

            var dateRangeFilter = new BasicDateRangeFilter
            {
                FromDate = fromDate
            };

            var players = autoMocker.ClassUnderTest.GetAllPlayersWithNemesisInfo(gamingGroupId, dateRangeFilter);

            Assert.That(players.Count, Is.EqualTo(1));
            var player = players.First();

            Assert.That(player.GamesLost, Is.EqualTo(0));
            Assert.That(player.GamesWon, Is.EqualTo(1));
        }
Ejemplo n.º 31
0
        public virtual void BaseSetUp()
        {
            autoMocker = new RhinoAutoMocker <PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();
            const int CHAMPION_ID = 55;

            gameDefinition = new GameDefinition
            {
                Name       = "game name",
                ChampionId = CHAMPION_ID
            };

            var playerId = 1;
            var champion = new Champion
            {
                Id             = CHAMPION_ID,
                GameDefinition = gameDefinition,
                PlayerId       = playerId
            };

            playerGameResultsForFirstPlayer = new List <PlayerGameResult>()
            {
                new PlayerGameResult
                {
                    GameRank = 2,
                    NemeStatsPointsAwarded = 10,
                    PlayedGame             = new PlayedGame
                    {
                        DatePlayed = new BasicDateRangeFilter().FromDate
                    }
                },
                new PlayerGameResult
                {
                    GameRank = 1,
                    NemeStatsPointsAwarded = 20,
                    PlayedGame             = new PlayedGame
                    {
                        DatePlayed = new BasicDateRangeFilter().ToDate
                    }
                }
            };

            playerChampionshipsForFirstPlayer = new List <Champion>
            {
                champion
            };
            List <Player> players = new List <Player>()
            {
                new Player()
                {
                    GamingGroupId = gamingGroupId, Name = "2", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>()
                },
                new Player()
                {
                    GamingGroupId = gamingGroupId, Name = "3", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>()
                },
                new Player()
                {
                    GamingGroupId = -1, Name = "not in gaming group", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>()
                },
                new Player()
                {
                    Id                = playerId,
                    GamingGroupId     = gamingGroupId,
                    Name              = "1",
                    PlayerGameResults = playerGameResultsForFirstPlayer,
                    ChampionedGames   = new List <Champion>
                    {
                        champion
                    }
                },
                new Player()
                {
                    //player that will be last because she's inactive
                    GamingGroupId = gamingGroupId, Name = "0", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>(), Active = false
                }
            };

            players[3].NemesisId = 1;
            players[3].Nemesis   = new Nemesis()
            {
                NemesisPlayerId = 2,
                NemesisPlayer   = new Player()
                {
                    Id = 93995
                }
            };
            playerQueryable = players.AsQueryable <Player>();

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(playerQueryable);

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <GameDefinition>())
            .Return(
                new List <GameDefinition>
            {
                gameDefinition
            }.AsQueryable());

            var playerAchievement =
                new PlayerAchievement
            {
                DateCreated      = DateTime.UtcNow,
                LastUpdatedDate  = DateTime.UtcNow,
                PlayerId         = playerId,
                AchievementLevel = AchievementLevel.Bronze,
                AchievementId    = AchievementId.BusyBee
            };

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <PlayerAchievement>())
            .Return(new List <PlayerAchievement> {
                playerAchievement
            }.AsQueryable());
        }
Ejemplo n.º 32
0
        public void FixtureSetUp()
        {
            autoMocker = new RhinoAutoMocker <GameDefinitionDetailsViewModelBuilder>();
            autoMocker.PartialMockTheClassUnderTest();

            expectedPlayerSummary1 = new PlayerSummaryViewModel();
            expectedPlayerSummary2 = new PlayerSummaryViewModel();

            List <PlayedGame> playedGames = new List <PlayedGame>();

            playedGames.Add(new PlayedGame
            {
                Id = 10
            });
            playedGameDetailsViewModel1 = new PlayedGameDetailsViewModel();
            playedGames.Add(new PlayedGame
            {
                Id = 11
            });
            playedGameDetailsViewModel2 = new PlayedGameDetailsViewModel();
            championPlayer = new Player
            {
                Name = championName,
                Id   = championPlayerId
            };
            previousChampionPlayer = new Player
            {
                Name = previousChampionName,
                Id   = previousChampionPlayerId
            };
            champion = new Champion
            {
                Player        = championPlayer,
                WinPercentage = championWinPercentage,
                NumberOfGames = championNumberOfGames,
                NumberOfWins  = championNumberOfWins
            };
            previousChampion = new Champion
            {
                Player = previousChampionPlayer
            };
            playerWinRecord1 = new PlayerWinRecord
            {
                GamesWon      = 1,
                GamesLost     = 2,
                PlayerName    = "player name",
                WinPercentage = 33,
                PlayerId      = 3
            };
            playerWinRecord2 = new PlayerWinRecord();

            autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <PlayerWinRecord, PlayerSummaryViewModel>(playerWinRecord1))
            .Return(expectedPlayerSummary1);
            autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <PlayerWinRecord, PlayerSummaryViewModel>(playerWinRecord2))
            .Return(expectedPlayerSummary2);

            gameDefinitionSummary = new GameDefinitionSummary
            {
                Id                            = 1,
                Name                          = "game definition name",
                Description                   = "game definition description",
                GamingGroupId                 = gamingGroupid,
                GamingGroupName               = "gaming group name",
                PlayedGames                   = playedGames,
                TotalNumberOfGamesPlayed      = 3,
                AveragePlayersPerGame         = 2.2M,
                BoardGameGeekGameDefinitionId = 123,
                Champion                      = champion,
                PreviousChampion              = previousChampion,
                PlayerWinRecords              = new List <PlayerWinRecord>
                {
                    playerWinRecord1,
                    playerWinRecord2
                }
            };
            currentUser = new ApplicationUser
            {
                CurrentGamingGroupId = gamingGroupid
            };
            autoMocker.Get <IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(gameDefinitionSummary.PlayedGames[0], currentUser))
            .Return(playedGameDetailsViewModel1);
            autoMocker.Get <IPlayedGameDetailsViewModelBuilder>().Expect(mock => mock.Build(gameDefinitionSummary.PlayedGames[1], currentUser))
            .Return(playedGameDetailsViewModel2);

            viewModel = autoMocker.ClassUnderTest.Build(gameDefinitionSummary, currentUser);
        }
Ejemplo n.º 33
0
        public void BaseSetUp()
        {
            autoMocker = new RhinoAutoMocker <PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();
            const int CHAMPION_ID = 55;

            gameDefinition = new GameDefinition
            {
                Name       = "game name",
                ChampionId = CHAMPION_ID
            };

            var playerId = 1;
            var champion = new Champion
            {
                Id             = CHAMPION_ID,
                GameDefinition = gameDefinition,
                PlayerId       = playerId
            };

            playerGameResultsForFirstPlayer = new List <PlayerGameResult>()
            {
                new PlayerGameResult
                {
                    GameRank = 2,
                    NemeStatsPointsAwarded = 10
                },
                new PlayerGameResult
                {
                    GameRank = 1,
                    NemeStatsPointsAwarded = 20
                }
            };

            playerChampionshipsForFirstPlayer = new List <Champion>
            {
                champion
            };
            List <Player> players = new List <Player>()
            {
                new Player()
                {
                    GamingGroupId = gamingGroupId, Name = "2", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>()
                },
                new Player()
                {
                    GamingGroupId = gamingGroupId, Name = "3", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>()
                },
                new Player()
                {
                    GamingGroupId = -1, Name = "not in gaming group", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>()
                },
                new Player()
                {
                    Id                = playerId,
                    GamingGroupId     = gamingGroupId,
                    Name              = "1",
                    PlayerGameResults = playerGameResultsForFirstPlayer,
                    ChampionedGames   = new List <Champion>
                    {
                        champion
                    }
                },
                new Player()
                {
                    //player that will be last because she's inactive
                    GamingGroupId = gamingGroupId, Name = "0", PlayerGameResults = new List <PlayerGameResult>(), ChampionedGames = new List <Champion>(), Active = false
                }
            };

            players[3].NemesisId = 1;
            players[3].Nemesis   = new Nemesis()
            {
                NemesisPlayerId = 2,
                NemesisPlayer   = new Player()
                {
                    Id = 93995
                }
            };
            playerQueryable = players.AsQueryable <Player>();

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(playerQueryable);

            autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <GameDefinition>())
            .Return(
                new List <GameDefinition>
            {
                gameDefinition
            }.AsQueryable());
        }