public void GetNextChallengeBoardCategory() { var repository = new TestRepository(); // create a game with some challenges var board = new Board(); repository.Add(board); var game = new Game() { BoardId = board.Id }; repository.Add(game); var category = new ChallengeCategory(); repository.Add(category); var challenge1 = new Challenge() { ChallengeCategoryId = category.Id }; var challenge2 = new Challenge() { ChallengeCategoryId = category.Id }; var challenge3 = new Challenge() { ChallengeCategoryId = category.Id }; var challenges = new Challenge[] { challenge1, challenge2, challenge3 }; repository.AddAll(challenges); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category.Id }); // keep getting the next challenge until all challenges should have been used var usedChallenges = new List<Challenge>(); foreach (Challenge challenge in challenges) { usedChallenges.Add(game.GetNextChallenge(0)); } // verify that all challenges were used CollectionAssert.AreEqual(challenges.Select(x => x.Id).OrderBy(x => x), usedChallenges.Select(x => x.Id).OrderBy(x => x)); // verify that more challenges can be retrieved Assert.IsNotNull(game.GetNextChallenge(0)); }
public void GetNextChallengeMultipleBoardCategories() { var repository = new TestRepository(); // create a game with some challenges var board = new Board(); repository.Add(board); var game = new Game() { BoardId = board.Id }; repository.Add(game); var category1 = new ChallengeCategory(); var category2 = new ChallengeCategory(); repository.Add(category1); repository.Add(category2); var challenge1 = new Challenge() { ChallengeCategoryId = category1.Id }; var challenge2 = new Challenge() { ChallengeCategoryId = category1.Id }; var challenge3 = new Challenge() { ChallengeCategoryId = category2.Id }; var challenge4 = new Challenge() { ChallengeCategoryId = category2.Id }; var challenge5 = new Challenge() { ChallengeCategoryId = category2.Id }; var challenges = new Challenge[] { challenge1, challenge2, challenge3, challenge4, challenge5 }; repository.AddAll(challenges); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category1.Id }); repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category2.Id }); // get some challenges (which ones will be used is indeterminate) for (int i = 0; i < 10; i++) { game.GetNextChallenge(0); } }