예제 #1
0
파일: GameTests.cs 프로젝트: nfink/Haven
        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));
        }
예제 #2
0
        public void DeleteChallenge()
        {
            var repository = new TestRepository();

            // add test challenges
            var challenge1 = new Challenge() { Question = "Test Question 1" };
            var challenge2 = new Challenge() { Question = "Test Question 2" };
            repository.Add(challenge1);
            repository.Add(challenge2);

            // add answers
            var answer1a = new ChallengeAnswer() { Answer = "Test Answer 1a", Correct = true, ChallengeId = challenge1.Id };
            var answer1b = new ChallengeAnswer() { Answer = "Test Answer 1b", Correct = false, ChallengeId = challenge1.Id };
            var answer2a = new ChallengeAnswer() { Answer = "Test Answer 2a", Correct = true, ChallengeId = challenge2.Id };
            var answer2b = new ChallengeAnswer() { Answer = "Test Answer 2b", Correct = false, ChallengeId = challenge2.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1a, answer1b, answer2a, answer2b });

            // delete one challenge
            challenge1.Delete();

            // verify challenge and answers are deleted
            Assert.IsEmpty(repository.Find<Challenge>(x => x.Id == challenge1.Id));
            Assert.IsEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer1a.Id));
            Assert.IsEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer1b.Id));

            // verify other challenge is not deleted
            Assert.IsNotEmpty(repository.Find<Challenge>(x => x.Id == challenge2.Id));
            Assert.IsNotEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer2a.Id));
            Assert.IsNotEmpty(repository.Find<ChallengeAnswer>(x => x.Id == answer2b.Id));
        }
예제 #3
0
        public void MultipleChoiceAnswer()
        {
            var repository = new TestRepository();

            // create a multiple choice challenge
            var challenge = new Challenge() { Question = "Test Question 1", ChallengeCategoryId = 2, OwnerId = 3 };
            repository.Add(challenge);
            var answer1 = new ChallengeAnswer() { Answer = "Test Answer 1", Correct = true, ChallengeId = challenge.Id };
            var answer2 = new ChallengeAnswer() { Answer = "Test Answer 2", Correct = false, ChallengeId = challenge.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1, answer2 });

            // verify that correct answer is acknowledged as correct
            Assert.True(challenge.CorrectAnswer(answer1.Id));
            Assert.False(challenge.CorrectAnswer(answer2.Id));
        }
예제 #4
0
        public void CloneChallenge()
        {
            var repository = new TestRepository();

            // create a challenge
            var challenge = new Challenge() { Question = "Test Question 1", ChallengeCategoryId = 2, OwnerId = 3, OpenEnded = true };
            repository.Add(challenge);
            var answer1 = new ChallengeAnswer() { Answer = "Test Answer 1", Correct = true, ChallengeId = challenge.Id };
            var answer2 = new ChallengeAnswer() { Answer = "Test Answer 2", Correct = false, ChallengeId = challenge.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1, answer2 });

            // clone the challenge
            var clonedChallenge = challenge.Clone();

            // verify that challenge and answers were cloned
            Assert.AreNotEqual(challenge.Id, clonedChallenge.Id);
            Assert.AreEqual(challenge.Question, clonedChallenge.Question);
            Assert.AreEqual(challenge.ChallengeCategoryId, clonedChallenge.ChallengeCategoryId);
            Assert.AreEqual(challenge.OwnerId, clonedChallenge.OwnerId);
            Assert.AreEqual(challenge.OpenEnded, clonedChallenge.OpenEnded);
            Assert.AreNotEqual(challenge.Answers.Select(x => x.Id), clonedChallenge.Answers.Select(x => x.Id));
            Assert.AreEqual(challenge.Answers.Select(x => x.Answer), clonedChallenge.Answers.Select(x => x.Answer));
            Assert.AreEqual(challenge.Answers.Select(x => x.Correct), clonedChallenge.Answers.Select(x => x.Correct));
        }
예제 #5
0
파일: SpaceTests.cs 프로젝트: nfink/Haven
        public void DeleteSpace()
        {
            var repository = new TestRepository();

            // create spaces
            var space1 = new Space();
            var space2 = new Space();
            repository.AddAll(new Space[] { space1, space2 });

            // delete a space
            space1.Delete();

            // verify that space is deleted
            Assert.IsEmpty(repository.Find<Space>(x => x.Id == space1.Id));

            // verify that other space is not deleted
            Assert.IsNotEmpty(repository.Find<Space>(x => x.Id == space2.Id));
        }
예제 #6
0
파일: SpaceTests.cs 프로젝트: nfink/Haven
        public void DeletedSafeHavenSpace()
        {
            var repository = new TestRepository();

            // create safe haven spaces
            var safeHavenCard1 = new SafeHavenCard();
            var safeHavenCard2 = new SafeHavenCard();
            repository.AddAll(new SafeHavenCard[] { safeHavenCard1, safeHavenCard2 });
            var space1 = new Space() { SafeHavenCardId = safeHavenCard1.Id };
            var space2 = new Space() { SafeHavenCardId = safeHavenCard2.Id };
            repository.AddAll(new Space[] { space1, space2 });

            // delete a space
            space1.Delete();

            // verify that space is deleted
            Assert.IsEmpty(repository.Find<Space>(x => x.Id == space1.Id));

            // verify that safe haven card is deleted
            Assert.IsEmpty(repository.Find<SafeHavenCard>(x => x.Id == space1.SafeHavenCardId));

            // verify that other space data is not deleted
            Assert.IsNotEmpty(repository.Find<Space>(x => x.Id == space2.Id));
            Assert.IsNotEmpty(repository.Find<SafeHavenCard>(x => x.Id == space2.SafeHavenCardId));
        }
예제 #7
0
파일: SpaceTests.cs 프로젝트: nfink/Haven
        public void DeletedChallengeSpace()
        {
            var repository = new TestRepository();

            // create challenge spaces
            var nameCard1 = new NameCard();
            var nameCard2 = new NameCard();
            repository.AddAll(new NameCard[] { nameCard1, nameCard2 });
            var space1 = new Space() { NameCardId = nameCard1.Id };
            var space2 = new Space() { NameCardId = nameCard2.Id };
            repository.AddAll(new Space[] { space1, space2 });

            // delete a space
            space1.Delete();

            // verify that space is deleted
            Assert.IsEmpty(repository.Find<Space>(x => x.Id == space1.Id));

            // verify that name card is deleted
            Assert.IsEmpty(repository.Find<NameCard>(x => x.Id == space1.NameCardId));

            // verify that other space data is not deleted
            Assert.IsNotEmpty(repository.Find<Space>(x => x.Id == space2.Id));
            Assert.IsNotEmpty(repository.Find<NameCard>(x => x.Id == space2.NameCardId));
        }
예제 #8
0
파일: GameTests.cs 프로젝트: nfink/Haven
        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);
            }
        }
예제 #9
0
파일: GameTests.cs 프로젝트: nfink/Haven
        private Game CreateGameData(TestRepository repository)
        {
            // create game
            var board = new Board();
            repository.Add(board);
            repository.Add(new Space() { BoardId = board.Id });
            var game = new Game() { BoardId = board.Id };
            repository.Add(game);

            // add challenges
            var challenge1 = new Challenge();
            var challenge2 = new Challenge();
            var challenge3 = new Challenge();
            var challenge4 = new Challenge();
            repository.AddAll(new Challenge[] { challenge1, challenge2, challenge3, challenge4 });

            // mark some challenges as used
            repository.Add(new UsedChallenge() { GameId = game.Id, ChallengeId = challenge1.Id });
            repository.Add(new UsedChallenge() { GameId = game.Id, ChallengeId = challenge2.Id });

            // add players
            game.AddPlayer();
            game.AddPlayer();
            game.AddPlayer();

            return game;
        }
예제 #10
0
파일: BoardTests.cs 프로젝트: nfink/Haven
 private Board CreateBoardData(TestRepository repository)
 {
     var image = new Image() { Filename = "test.jpg" };
     repository.Add(image);
     var board = new Board() { ImageId = image.Id, Active = true, Description = "test1", Name = "test3", OwnerId = 4, TurnsToEnd = 50, NameCardsToEnd = 10, SafeHavenCardsToEnd = 5 };
     repository.Add(board);
     var space1 = new Space() { BoardId = board.Id, Order = 10 };
     var space2 = new Space() { BoardId = board.Id, Order = 20 };
     var space3 = new Space() { BoardId = board.Id, Order = 30 };
     repository.AddAll(new Space[] { space1, space2, space3 });
     var category1 = new ChallengeCategory() { Name = "test1", OwnerId = 2 };
     var category2 = new ChallengeCategory() { Name = "test3", OwnerId = 4 };
     var category3 = new ChallengeCategory() { Name = "test4", OwnerId = 4 };
     var categories = new ChallengeCategory[] { category1, category2, category3 };
     repository.AddAll(categories);
     repository.Add(new SpaceChallengeCategory() { SpaceId = space1.Id, ChallengeCategoryId = category1.Id });
     repository.Add(new SpaceChallengeCategory() { SpaceId = space2.Id, ChallengeCategoryId = category3.Id });
     var challenge1 = new Challenge() { Question = "test1", ChallengeCategoryId = category1.Id, OwnerId = 3 };
     var challenge2 = new Challenge() { Question = "test2", ChallengeCategoryId = category2.Id, OwnerId = 4 };
     repository.AddAll(new Challenge[] { challenge1, challenge2 });
     repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category1.Id });
     repository.Add(new BoardChallengeCategory() { BoardId = board.Id, ChallengeCategoryId = category2.Id });
     return board;
 }
예제 #11
0
파일: BoardTests.cs 프로젝트: nfink/Haven
        public void GetNewSpace()
        {
            var repository = new TestRepository();

            // create a board with some spaces
            var board = new Board();
            repository.Add(board);
            var space1 = new Space() { BoardId = board.Id, Order = 10 };
            var space2 = new Space() { BoardId = board.Id, Order = 20 };
            var space3 = new Space() { BoardId = board.Id, Order = 30 };
            var space4 = new Space() { BoardId = board.Id, Order = 40 };
            var space5 = new Space() { BoardId = board.Id, Order = 50 };
            repository.AddAll(new Space[] { space1, space2, space3, space4, space5 });

            // verify that the correct space is returned moving forward
            Assert.AreEqual(space2.Id, board.GetNewSpace(space1.Id, 1, true).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space1.Id, 2, true).Id);
            Assert.AreEqual(space5.Id, board.GetNewSpace(space1.Id, 4, true).Id);

            // verify that the correct space is returned moving forward and wrapping around
            Assert.AreEqual(space1.Id, board.GetNewSpace(space5.Id, 1, true).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space4.Id, 4, true).Id);

            // verify that the correct space is returned moving forward and moving more than the number of spaces
            Assert.AreEqual(space1.Id, board.GetNewSpace(space1.Id, 5, true).Id);
            Assert.AreEqual(space2.Id, board.GetNewSpace(space1.Id, 11, true).Id);

            // verify that the correct space is returned moving backward
            Assert.AreEqual(space4.Id, board.GetNewSpace(space5.Id, 1, false).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space5.Id, 2, false).Id);
            Assert.AreEqual(space1.Id, board.GetNewSpace(space5.Id, 4, false).Id);

            // verify that the correct space is returned moving backward and wrapping around
            Assert.AreEqual(space5.Id, board.GetNewSpace(space1.Id, 1, false).Id);
            Assert.AreEqual(space3.Id, board.GetNewSpace(space2.Id, 4, false).Id);

            // verify that the correct space is returned moving backward and moving more than the number of spaces
            Assert.AreEqual(space1.Id, board.GetNewSpace(space1.Id, 5, false).Id);
            Assert.AreEqual(space5.Id, board.GetNewSpace(space1.Id, 11, false).Id);
        }
예제 #12
0
        public void OpenEndedAnswer()
        {
            var repository = new TestRepository();

            // create an open ended challenge
            var challenge = new Challenge() { Question = "Test Question 1", ChallengeCategoryId = 2, OwnerId = 3, OpenEnded = true };
            repository.Add(challenge);
            var answer1 = new ChallengeAnswer() { Answer = "Test Answer 1", Correct = true, ChallengeId = challenge.Id };
            var answer2 = new ChallengeAnswer() { Answer = "Test Answer 2", Correct = false, ChallengeId = challenge.Id };
            repository.AddAll(new ChallengeAnswer[] { answer1, answer2 });

            // verify that correct answer is acknowledged as correct
            Assert.True(challenge.CorrectAnswer(answer1.Answer));
            Assert.False(challenge.CorrectAnswer(answer2.Answer));
            Assert.False(challenge.CorrectAnswer(answer1.Answer + "a"));
        }