Exemple #1
0
        public void CloneSpace()
        {
            var repository = new TestRepository();

            // create a space
            var space = new Space() { BackgroundColorId = 1, BoardId = 2, Height = 3, ImageId = 4, Order = 5, TextColorId = 6, Type = SpaceType.TurnAround, Width = 7, X = 8, Y = 9, IconId = 11 };
            repository.Add(space);

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space was cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.BackgroundColorId, space.BackgroundColorId);
            Assert.AreEqual(clonedSpace.BoardId, space.BoardId);
            Assert.AreEqual(clonedSpace.Height, space.Height);
            Assert.AreEqual(clonedSpace.ImageId, space.ImageId);
            Assert.AreEqual(clonedSpace.Name, space.Name);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreEqual(clonedSpace.TextColorId, space.TextColorId);
            Assert.AreEqual(clonedSpace.Type, space.Type);
            Assert.AreEqual(clonedSpace.Width, space.Width);
            Assert.AreEqual(clonedSpace.X, space.X);
            Assert.AreEqual(clonedSpace.Y, space.Y);
            Assert.AreEqual(clonedSpace.IconId, space.IconId);
        }
Exemple #2
0
        public void Create(Space space, NameCard nameCard = null, SafeHavenCard safeHavenCard = null, Image image = null)
        {
            int imageId = 0;
            if (image != null)
            {
                this.Repository.Add<Image>(image);
                imageId = image.Id;
            }

            // add any dependent items
            if (space.Type == Haven.SpaceType.Challenge)
            {
                if (nameCard != null)
                {
                    // add name card
                    nameCard.ImageId = image.Id;
                    this.Repository.Add<NameCard>(nameCard);
                    space.NameCardId = nameCard.Id;
                }
                else
                {
                    // set space image
                    space.ImageId = image.Id;
                }
            }
            else if (space.Type == Haven.SpaceType.SafeHaven)
            {
                if (safeHavenCard != null)
                {
                    // add safe haven card
                    safeHavenCard.ImageId = image.Id;
                    this.Repository.Add<SafeHavenCard>(safeHavenCard);
                    space.SafeHavenCardId = nameCard.Id;
                }
                else
                {
                    // set space image
                    space.ImageId = image.Id;
                }
            }
            else
            {
                space.ImageId = image.Id;
            }

            this.Repository.Add<Space>(space);

            //// add challenge categories
            //if ((space.Type == Haven.SpaceType.Challenge) || (space.Type == Haven.SpaceType.War))
            //{
            //    foreach (SpaceChallengeCategory category in space.ChallengeCategories)
            //    {
            //        category.SpaceId = space.Id;
            //        category.ChallengeCategoryId = category.ChallengeCategory.Id;
            //        this.Repository.Add<SpaceChallengeCategory>(category);
            //    }
            //}
        }
Exemple #3
0
        public Space Clone(Space space)
        {
            //// use same attributes and Image record
            //var space = new Space()
            //{
            //    Board = this.Board,
            //    Order = this.Order,
            //    Type = this.Type,
            //    Width = this.Width,
            //    Height = this.Height,
            //    X = this.X,
            //    Y = this.Y,
            //    BackgroundColor = this.BackgroundColor,
            //    TextColor = this.TextColor,
            //    Picture = this.Picture
            //};

            //// copy any subrecords
            //if (this.NameCard != null)
            //{
            //    space.NameCard = this.NameCard.Clone();
            //}
            //if (this.SafeHavenCard != null)
            //{
            //    space.SafeHavenCard = this.SafeHavenCard.Clone();
            //}

            ////this.Repository.Add(space);

            //// add categories
            //var categories = new List<SpaceChallengeCategory>();
            //foreach (SpaceChallengeCategory category in this.ChallengeCategories)
            //{
            //    categories.Add(new SpaceChallengeCategory() { Space = space, ChallengeCategory = category.ChallengeCategory });
            //    //this.Repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = category.ChallengeCategoryId });
            //}

            //return space;

            //            public NameCard Clone()
            //{
            //    int imageId = 0;
            //    if (this.ImageId != 0)
            //    {
            //        imageId = this.Image.Clone().Id;
            //    }

            //    var nameCard = new NameCard() { Name = this.Name, Details = this.Details, ImageId = imageId };
            //    TinyIoCContainer.Current.Resolve<IRepository>().Add<NameCard>(nameCard);
            //    //var nameCard = new NameCard() { Name = this.Name, Details = this.Details, Image = (this.Image != null ? this.Image.Clone() : null) };
            //    return nameCard;
            //}

            return null;
        }
Exemple #4
0
        public void CloneSafeHavenSpace()
        {
            var repository = new TestRepository();

            // create a space with a safe haven card
            var safeHavenCard = new SafeHavenCard() { Name = "test1" };
            repository.Add(safeHavenCard);
            var space = new Space() { SafeHavenCardId = safeHavenCard.Id, Order = 10 };
            repository.Add(space);

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space and subobject were cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreNotEqual(clonedSpace.SafeHavenCardId, space.SafeHavenCardId);
            Assert.AreEqual(clonedSpace.SafeHavenCard.Name, space.SafeHavenCard.Name);
        }
Exemple #5
0
        public void CloneChallengeSpace()
        {
            var repository = new TestRepository();

            // create a space with a name card
            var nameCard = new NameCard() { Name = "test1" };
            repository.Add(nameCard);
            var space = new Space() { NameCardId = nameCard.Id, Order = 10 };
            repository.Add(space);

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space and subobject were cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreNotEqual(clonedSpace.NameCardId, space.NameCardId);
            Assert.AreEqual(clonedSpace.NameCard.Name, space.NameCard.Name);
        }
Exemple #6
0
        public void TurnAround()
        {
            // set up data
            var repository = new TestRepository();

            var board = new Board();
            repository.Add(board);
            var space = new Space() { Type = SpaceType.TurnAround, BoardId = board.Id };
            repository.Add(space);
            var game = new Game();
            game.Repository = repository;
            game.Create(board.Id, 2);

            // trigger onland
            var player = game.Players.First();
            space.OnLand(player);

            // verify that player was turned around and received the correct message
            player = repository.Get<Player>(player.Id);
            Assert.AreEqual(false, player.MovementDirection);
            var message = player.Messages.Single();
            Assert.AreEqual("Turned around.", message.Text);
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        public void DeletedSpaceWithCategories()
        {
            var repository = new TestRepository();

            // create a space with category links
            var space = new Space();
            repository.Add(space);
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 1 });
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 2 });

            // delete a space
            space.Delete();

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

            // verify that category links are deleted
            Assert.IsEmpty(repository.Find<SpaceChallengeCategory>(x => x.SpaceId == space.Id));
        }
Exemple #9
0
        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));
        }
Exemple #10
0
        public void GetNewSpaceSingleSpace()
        {
            var repository = new TestRepository();

            // create a board with a single space
            var board = new Board();
            repository.Add(board);
            var space = new Space() { BoardId = board.Id, Order = 10 };
            repository.Add(space);

            // verify that the same space is returned when moving forward
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 1, true).Id);
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 5, true).Id);

            // verify that the same space is returned when moving backward
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 1, false).Id);
            Assert.AreEqual(space.Id, board.GetNewSpace(space.Id, 5, false).Id);
        }
Exemple #11
0
        public void GetNextChallengeSpaceCategory()
        {
            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);
            var space = new Space() { BoardId = board.Id };
            repository.Add(space);
            repository.Add(new SpaceChallengeCategory() { SpaceId=space.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(space.Id));
            }

            // 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(space.Id));
        }
Exemple #12
0
        public void GetNextChallengeMultipleSpaceCategories()
        {
            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);
            var space = new Space() { BoardId = board.Id };
            repository.Add(space);
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = category1.Id });
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = category2.Id });

            // get some challenges (which ones will be used is indeterminate)
            for (int i = 0; i < 10; i++)
            {
                game.GetNextChallenge(space.Id);
            }
        }
Exemple #13
0
        public void Update(Space space)
        {
            var originalSpace = this.Repository.Find<Space>(x => x.Id == space.Id).SingleOrDefault();
            if (originalSpace != null)
            {
                // add/update any dependent records

            }

            //    // add/update any dependent records
            //    if (space.Type == Haven.SpaceType.Challenge)
            //    {
            //        // delete other records
            //        if (originalSpace.SafeHavenCard != null)
            //        {
            //            if (originalSpace.SafeHavenCard.Image != null)
            //            {
            //                originalSpace.SafeHavenCard.Image.Delete();
            //                this.Repository.Remove<Image>(originalSpace.SafeHavenCard.Image);
            //            }

            //            this.Repository.Remove<SafeHavenCard>(originalSpace.SafeHavenCard);
            //        }

            //        // add/update name card record
            //        if (originalSpace.NameCard == null)
            //        {
            //            // add image and name card
            //            this.Repository.Add<Image>(space.NameCard.Image);
            //            space.NameCard.ImageId = space.NameCard.Image.Id;
            //            this.Repository.Add<NameCard>(space.NameCard);
            //        }
            //        else
            //        {
            //            // if new image != old image, remove old image and add new image
            //            if (originalSpace.NameCard.ImageId != space.NameCard.ImageId)
            //            {

            //            }

            //            this.Repository.Update<NameCard>(space.NameCard);
            //        }

            //        var image = nameCard.Image;
            //        image = this.UpdateImage(pathProvider, image, imageFile);
            //        if (space.NameCard.Image != null)
            //        {

            //            nameCard.ImageId = image.Id;
            //        }

            //        this.Repository.Update(nameCard);
            //        space.NameCardId = nameCard.Id;
            //    }
            //    else if (space.Type == Haven.SpaceType.SafeHaven)
            //    {
            //        // delete other records
            //        if (space.NameCardId != 0)
            //        {
            //            this.Repository.Remove<NameCard>(space.NameCardId);
            //            space.NameCardId = 0;
            //        }

            //        // add/update safe haven card record
            //        SafeHavenCard safeHavenCard = space.SafeHavenCard;
            //        if (safeHavenCard == null)
            //        {
            //            safeHavenCard = new SafeHavenCard() { Name = (string)this.Request.Form.CardName, Details = (string)this.Request.Form.CardDetails };
            //            this.Repository.Add(safeHavenCard);
            //        }
            //        else
            //        {
            //            safeHavenCard.Name = (string)this.Request.Form.CardName;
            //            safeHavenCard.Details = (string)this.Request.Form.CardDetails;
            //        }

            //        var image = safeHavenCard.Image;
            //        image = this.UpdateImage(pathProvider, image, imageFile);
            //        if (image != null)
            //        {
            //            safeHavenCard.ImageId = image.Id;
            //        }

            //        this.Repository.Update(safeHavenCard);
            //        space.SafeHavenCardId = safeHavenCard.Id;
            //    }
            //    else
            //    {
            //        // delete unused records
            //        if (space.NameCardId != 0)
            //        {
            //            if (space.NameCard.Image != null)
            //            {
            //                space.NameCard.Image.Delete();
            //            }
            //            this.Repository.Remove<NameCard>(space.NameCardId);
            //            space.NameCardId = 0;
            //        }
            //        if (space.SafeHavenCardId != 0)
            //        {
            //            if (space.SafeHavenCard.Image != null)
            //            {
            //                space.SafeHavenCard.Image.Delete();
            //            }
            //            this.Repository.Remove<SafeHavenCard>(space.SafeHavenCardId);
            //            space.SafeHavenCardId = 0;
            //        }
            //    }

            //    // update challenge categories
            //    Persistence.Connection.Execute("delete from SpaceChallengeCategory where SpaceId=?", space.Id);
            //    if ((space.Type == Haven.SpaceType.Challenge) || (space.Type == Haven.SpaceType.War))
            //    {
            //        var categoryIds = JsonConvert.DeserializeObject<IEnumerable<int>>((string)this.Request.Form.ChallengeCategories);
            //        foreach (int categoryId in categoryIds)
            //        {
            //            this.Repository.Add(new SpaceChallengeCategory() { ChallengeCategoryId = categoryId, SpaceId = space.Id });
            //        }
            //    }

            //    this.Repository.Update(space);

            //    return JsonConvert.SerializeObject(space);
        }
Exemple #14
0
        public void Delete(Space space)
        {
            // remove any dependent records
            if (space.NameCardId != 0)
            {
                this.Repository.Remove<NameCard>(new NameCard { Id = space.NameCardId });
            }
            if (space.SafeHavenCardId != 0)
            {
                this.Repository.Remove<SafeHavenCard>(new SafeHavenCard { Id = space.SafeHavenCardId });
            }
            foreach (SpaceChallengeCategory category in this.Repository.Find<SpaceChallengeCategory>(x => x.SpaceId == space.Id))
            {
                this.Repository.Remove<SpaceChallengeCategory>(category);
            }

            // remove space
            this.Repository.Remove<Space>(space);
        }
Exemple #15
0
 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;
 }
Exemple #16
0
        public void CloneSpaceWithCategories()
        {
            var repository = new TestRepository();

            // create a space with category links
            var space = new Space() { Order = 10 };
            repository.Add(space);
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 1 });
            repository.Add(new SpaceChallengeCategory() { SpaceId = space.Id, ChallengeCategoryId = 2 });

            // clone the space
            var clonedSpace = space.Clone();

            // verify that space and category links were cloned
            Assert.AreNotEqual(space.Id, clonedSpace.Id);
            Assert.AreEqual(clonedSpace.Order, space.Order);
            Assert.AreNotEqual(clonedSpace.ChallengeCategories.Select(x => x.Id), space.ChallengeCategories.Select(x => x.Id));
            Assert.AreEqual(clonedSpace.ChallengeCategories.Select(x => x.ChallengeCategoryId), space.ChallengeCategories.Select(x => x.ChallengeCategoryId));
        }
Exemple #17
0
        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));
        }
Exemple #18
0
        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);
        }