Example #1
0
        public void PlayFromHand()
        {
            // Arrange
            var options = new DeckOptions()
            {
                Hands = new HandOptions {
                    InitialHandSize = 0
                },
                Table = new TableOptions {
                    Enabled = true
                }
            };
            var deck = new Deck <string>(options);

            deck.Add("This");
            deck.Add("is");
            deck.Add("a");
            deck.Add("sample");
            deck.Add("deck.");
            var hand = deck.Deal();

            hand.Draw();
            // Act
            Assert.AreEqual(1, hand.Count);
            Assert.AreEqual("deck.", hand.First());
            // Assert
            hand.Play(hand.First());
            Assert.AreEqual(4, deck.DrawPile.Count);
            Assert.AreEqual(1, deck.Table.Count);
            Assert.AreEqual(0, deck.DiscardPile.Count);
            Assert.AreEqual(5, deck.Count);
        }
Example #2
0
        public async Task <IActionResult> Get(Guid id)
        {
            using (var repository = new Repository(HttpContext.GetUserGuid()))
            {
                var deck = await repository.Context.Decks.FindByGuidAsync(id);

                await repository.Context.Entry(deck).Reference(x => x.Status).LoadAsync();

                await repository.Context.Entry(deck).Reference(x => x.Creator).LoadAsync();

                var deckOptions = new DeckOptions();
                if (repository.ServiceUser != null)
                {
                    await repository.Context.Entry(repository.ServiceUser).Reference(x => x.Role).LoadAsync();

                    if (deck.Creator.Guid == repository.ServiceUser.Guid ||
                        repository.ServiceUser.Role.Guid == PredefinedGuids.Developer ||
                        repository.ServiceUser.Role.Guid == PredefinedGuids.Administrator ||
                        repository.ServiceUser.Role.Guid == PredefinedGuids.ServiceUser)
                    {
                        deckOptions.IsEditable             = true;
                        deckOptions.IsStatusChangedAllowed = true;
                    }
                }

                deckOptions.Statuses = repository.Context.Statuses.AsNoTracking().ToList().Select(x => x.FromDal()).ToList();

                return(Ok(deckOptions));
            }
        }
Example #3
0
        public void CreateIntoAllLocationsTests()
        {
            // Arrange
            var options = new DeckOptions()
            {
                Hands = new HandOptions {
                    InitialHandSize = 0
                },
                Table = new TableOptions {
                    Enabled = true
                },
                Tableau = new TableauOptions {
                    Enabled = true
                },
            };
            var deck = new Deck <string>(options);

            // Act
            deck.Add("This");
            deck.Add("is", Location.DiscardPile);
            deck.Add("a", Location.Table);
            deck.Add("sample");
            deck.Add("string", Location.Tableau);
            deck.Add("deck.", Location.DiscardPile);
            deck.DrawPile.Shuffle(false);
            // Assert
            Assert.AreEqual(2, deck.DrawPile.Count);
            Assert.AreEqual(1, deck.Table.Count);
            Assert.AreEqual(2, deck.DiscardPile.Count);
            Assert.AreEqual(1, deck.Tableau.Count);
            Assert.AreEqual(6, deck.Count);
        }
Example #4
0
        public void ContainsElements()
        {
            // Arrange
            var options = new DeckOptions()
            {
                Hands = new HandOptions {
                    InitialHandSize = 1
                },
                Table = new TableOptions {
                    Enabled = true
                }
            };
            var deck = new Deck <string>(options);

            // Act
            deck.Add("This");
            deck.Add("is", Location.DiscardPile);
            deck.Add("a", Location.Table);
            deck.Add("sample");
            deck.Add("deck.", Location.DiscardPile);
            var hand = deck.Deal();

            // Act
            // Assert
            Assert.IsTrue(deck.Contains("is", Location.DiscardPile));
            Assert.IsFalse(deck.Contains("is", Location.DrawPile));
            Assert.IsTrue(deck.Contains("This"));
            Assert.IsTrue(deck.Contains("a", Location.Table));
            Assert.IsTrue(deck.Contains("sample", Location.Hand));
            Assert.IsTrue(hand.Contains("sample"));
        }
Example #5
0
        public void MuckFromHand()
        {
            // Arrange
            var options = new DeckOptions()
            {
                Hands = new HandOptions {
                    InitialHandSize = 3
                }
            };
            var deck = new Deck <string>(options);

            // Act 1
            deck.Add("This");
            deck.Add("is");
            deck.Add("a");
            deck.Add("sample");
            deck.Add("deck.");
            var hand = deck.Deal();

            // Assert 1
            Assert.AreEqual(3, hand.Count);
            Assert.AreEqual(5, deck.Count);
            Assert.AreEqual(2, deck.DrawPile.Count);
            Assert.AreEqual(0, deck.DiscardPile.Count);
            // Act 2
            hand.Muck();
            // Assert 2
            Assert.AreEqual(0, hand.Count);
            Assert.IsTrue(hand.HasBeenMucked);
            Assert.AreEqual(5, deck.Count);
            Assert.AreEqual(2, deck.DrawPile.Count);
            Assert.AreEqual(3, deck.DiscardPile.Count);
        }
        public async Task <IActionResult> Get(Guid id)
        {
            using (var repository = new Repository(HttpContext.GetUserGuid()))
            {
                var deckModel = await repository.Context.Decks.FindByGuidAsync(id);

                await repository.Context.Entry(deckModel).Reference(x => x.Status).LoadAsync();

                await repository.Context.Entry(deckModel).Reference(x => x.Creator).LoadAsync();

                var deckOptions = new DeckOptions();
                var isMyDeck    = deckModel.Creator.Guid == repository.ServiceUser?.Guid;

                deckOptions.IsEditable =
                    (isMyDeck && AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.EditDeck)) ||
                    (!isMyDeck && AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.AllowOthersDeckEdit));

                deckOptions.IsStatusChangedAllowed =
                    (isMyDeck && AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.EditDeck)) ||
                    (!isMyDeck && AuthorizeService.HashRight(repository.ServiceUser?.Role, Rights.AllowDeckStatusChange));

                deckOptions.Statuses = repository.Context.Statuses.AsNoTracking().ToList().Select(x => x.FromDal()).ToList();

                return(Ok(deckOptions));
            }
        }
Example #7
0
        public void OversizeAndShrink()
        {
            // Arrange
            var options = new DeckOptions
            {
                Tableau = new TableauOptions
                {
                    Enabled      = true,
                    InitialSize  = 2,
                    MaximumSize  = 3,
                    OverflowRule = TableauOverflowRule.DiscardRandom
                }
            };
            var deck = new Deck <String>(options)
                       .Add("This")
                       .Add("is", Location.Tableau)
                       .Add("a", Location.Tableau)
                       .Add("bunch")
                       .Add("of", Location.Tableau)
                       .Add("strings", Location.Tableau)
                       .Add("in")
                       .Add("the", Location.Tableau)
                       .Add("deck", Location.Tableau);

            // Act & Assert
            Assert.AreEqual(6, deck.Tableau.Count);
            Assert.AreEqual(3, deck.DrawPile.Count);
            Assert.AreEqual(0, deck.DiscardPile.Count);
            deck.Tableau.DrawUp();
            Assert.AreEqual(3, deck.Tableau.Count);
            Assert.AreEqual(3, deck.DrawPile.Count);
            Assert.AreEqual(3, deck.DiscardPile.Count);
        }
Example #8
0
        public void AddToHandFails()
        {
            // Arrange
            var options = new DeckOptions();
            var deck    = new Deck <string>(options);

            // Act
            deck.Add("This", Location.Hand);
        }
 public async Task <IActionResult> Get()
 {
     using (var repository = new Repository(HttpContext.GetUserGuid()))
     {
         var deckOptions = new DeckOptions();
         deckOptions.Statuses = repository.Context.Statuses.AsNoTracking().ToList().Select(x => x.FromDal()).ToList();
         return(Ok(deckOptions));
     }
 }
Example #10
0
    private void OnValidate()
    {
        cardOptions = GetComponent <CardOptions>();
        deckOptions = GetComponent <DeckOptions>();

        if (DeckType == TypeOfDeck.Custom)
        {
        }
        else
        {
        }
    }
Example #11
0
        public void TableauAddToDrawFrom()
        {
            // Arrange
            var options = new DeckOptions {
                Tableau = new TableauOptions
                {
                    Enabled      = true,
                    InitialSize  = 3,
                    MaintainSize = true,
                },
                Hands = new HandOptions {
                    InitialHandSize = 2
                }
            };
            var deck = new Deck <string>(options);

            deck.Add("This")
            .Add("is")
            .Add("a", Location.Tableau)
            .Add("deck")
            .Add("with")
            .Add("the")
            .Add("tableau");
            // Act & Assert
            Assert.AreEqual(1, deck.Tableau.Count);
            Assert.AreEqual(6, deck.DrawPile.Count);

            deck.Tableau.DrawUp();
            Assert.AreEqual(3, deck.Tableau.Count);
            Assert.AreEqual(4, deck.DrawPile.Count);
            var wasLast = deck.Tableau.Last();

            deck.Tableau.Play(deck.Tableau.ElementAt(1));
            Assert.AreEqual(3, deck.Tableau.Count);
            Assert.AreEqual(3, deck.DrawPile.Count);
            Assert.AreEqual(wasLast, deck.Tableau.ElementAt(1));

            var hand = deck.Deal(1, 1).First();

            Assert.AreEqual(3, deck.Tableau.Count);
            Assert.AreEqual(2, deck.DrawPile.Count);
            Assert.AreEqual(1, deck.Hands.Count);
            Assert.AreEqual(1, hand.Count);

            deck.Tableau.DrawInto(deck.Tableau.ElementAt(1), hand);
            Assert.AreEqual(3, deck.Tableau.Count);
            Assert.AreEqual(1, deck.DrawPile.Count);
            Assert.AreEqual(1, deck.Hands.Count);
            Assert.AreEqual(2, hand.Count);
        }
Example #12
0
        public void NoTableauByOptions()
        {
            // Arrange
            var options = new DeckOptions {
                Tableau = new TableauOptions
                {
                    InitialSize = 0,
                }
            };
            var deck = new Deck <string>(options);
            // Act & Assert
            var enabled = deck.Tableau.Enabled;

            Assert.IsFalse(enabled);
        }
Example #13
0
        public void ShuffleFailsWithoutOnceAllowed()
        {
            // Arrange
            var options = new DeckOptions()
            {
                DrawPile = new DrawPileOptions {
                    MaximumShuffleCount = 0
                }
            };
            var deck = new Deck <string>(options);

            // Act
            deck.Add("This");
            deck.DrawPile.Shuffle();
        }
Example #14
0
        public void TableauEnableByOptions()
        {
            // Arrange
            var options = new DeckOptions {
                Tableau = new TableauOptions
                {
                    Enabled = true,
                }
            };
            var deck = new Deck <string>(options);
            // Act & Assert
            var enabled = deck.Tableau.Enabled;

            Assert.IsTrue(enabled);
        }
Example #15
0
        public void DefaultTableauCanBottomDeck()
        {
            // Arrange
            var options = new DeckOptions
            {
                Tableau = new TableauOptions
                {
                    Enabled     = true,
                    InitialSize = 3,
                }
            };
            var deck = new Deck <string>(options)
                       .Add("Thing");

            // Act & Assert
            deck.Tableau.DrawUp();
        }
Example #16
0
        public void PlayToTableRequiresPermissions()
        {
            // Arrange
            var options = new DeckOptions {
                Tableau = new TableauOptions
                {
                    InitialSize     = 1,
                    CanPlayToTable  = true,
                    CanDrawIntoHand = false,
                },
            };
            var deck = new Deck <string>(options)
                       .Add("Thing");

            deck.Tableau.DrawUp();
            // Act & Assert
            deck.Tableau.Play(deck.Tableau.First());
        }
Example #17
0
        public void AlteredTableauCannotBottomDeck()
        {
            // Arrange
            var options = new DeckOptions
            {
                Tableau = new TableauOptions
                {
                    Enabled       = true,
                    InitialSize   = 3,
                    DrawsUpSafely = true
                }
            };
            var deck = new Deck <string>(options)
                       .Add("Thing");

            // Act & Assert
            deck.Tableau.DrawUp();
        }
Example #18
0
        public void CreateIntoTopDeckTests()
        {
            // Arrange
            var options = new DeckOptions();
            var deck    = new Deck <string>(options);

            // Act
            deck.Add("This");
            deck.Add("is");
            deck.Add("a");
            deck.Add("sample");
            deck.Add("deck.");
            deck.DrawPile.Shuffle();
            // Assert
            Assert.AreEqual(5, deck.DrawPile.Count);
            Assert.AreEqual(0, deck.Table.Count);
            Assert.AreEqual(0, deck.DiscardPile.Count);
            Assert.AreEqual(5, deck.Count);
        }
Example #19
0
        public void Initialize()
        {
            this.DealerDeckOptions = new DeckOptions(52)
            {
                CardDisplayFormat = Card.Formats.ConciseLetter
            };
            this.HandDeckOptions = new DeckOptions(1)
            {
                CardDisplayFormat = Card.Formats.ConciseLetter
            };

            this.DealerDeck = new Deck()
            {
                DeckName = "Dealer Deck",
                Options  = DealerDeckOptions
            };

            this.DealerHand = new Deck()
            {
                DeckName = "Dealer Hand",
                Options  = HandDeckOptions
            };

            this.PlayerHand = new Deck()
            {
                DeckName = "Player Hand",
                Options  = HandDeckOptions
            };

            this.Table = new Table()
            {
            };

            this.TableManager = new TableManager()
            {
                Table = this.Table
            };
            this.TableManager.OnCardAddedToDeck += this.OnCardAddedToDeck;

            TableManager.AddDecksToTable(this.Table, this.DealerDeck, this.DealerHand, this.PlayerHand);
            TableManager.FillDeck(this.DealerDeck);
            TableManager.Shuffle(this.DealerDeck);
        }
Example #20
0
        public void ShuffleWithRetreival()
        {
            // Arrange
            var options = new DeckOptions()
            {
                Table = new TableOptions {
                    Enabled = true
                }
            };
            var deck = new Deck <string>(options);

            // Act
            deck.Add("This");
            deck.Add("is", Location.DiscardPile);
            deck.Add("a", Location.Table);
            deck.Add("sample");
            deck.Add("deck.", Location.DiscardPile);
            deck.DrawPile.Shuffle();
            // Assert
            Assert.AreEqual(4, deck.DrawPile.Count);
            Assert.AreEqual(1, deck.Table.Count);
            Assert.AreEqual(0, deck.DiscardPile.Count);
            Assert.AreEqual(5, deck.Count);
        }
Example #21
0
        public void PlayToHandRequiresPermissions()
        {
            // Arrange
            var options = new DeckOptions
            {
                Tableau = new TableauOptions
                {
                    InitialSize     = 1,
                    CanPlayToTable  = false,
                    CanDrawIntoHand = true,
                },
                Hands = new HandOptions {
                    InitialHandSize = 1
                },
            };
            var deck = new Deck <string>(options)
                       .Add("Thing");

            deck.Tableau.DrawUp();
            var hand = deck.Deal(1, 0).First();

            // Act & Assert
            deck.Tableau.DrawInto(deck.Tableau.First(), hand);
        }