Пример #1
0
        public async Task CanGetDeck()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("GetDeck").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                DeckCardMgmtSvc svc  = new DeckCardMgmtSvc(context);
                Deck            deck = new Deck()
                {
                    ID = 1, UserID = 1, DeckType = DeckType.Play
                };
                await context.Decks.AddAsync(deck);

                List <DeckCard> cards = new List <DeckCard>();
                cards.Add(new DeckCard()
                {
                    CardID = 1, DeckID = 1
                });
                await context.DeckCards.AddAsync(cards[0]);

                await context.SaveChangesAsync();

                Assert.Equal(cards, (await svc.GetDeck(1, DeckType.Play)));
            }
        }
Пример #2
0
        public async Task CanCleanDeck()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("CleanDeck").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                DeckCardMgmtSvc svc   = new DeckCardMgmtSvc(context);
                Card            card1 = new Card()
                {
                    ID = 1, Rank = Rank.Ace, Suit = Suit.hearts
                };
                Card card2 = new Card()
                {
                    ID = 2, Rank = Rank.Ace, Suit = Suit.spades
                };
                Card card3 = new Card()
                {
                    ID = 3, Rank = Rank.Ace, Suit = Suit.clubs
                };
                Card card4 = new Card()
                {
                    ID = 4, Rank = Rank.Ace, Suit = Suit.diamonds
                };
                await context.Cards.AddAsync(card1);

                await context.Cards.AddAsync(card2);

                await context.Cards.AddAsync(card3);

                await context.Cards.AddAsync(card4);

                Deck deck = new Deck()
                {
                    ID = 1, UserID = 3, DeckType = DeckType.Collect
                };
                await context.Decks.AddAsync(deck);

                DeckCard dc1 = new DeckCard()
                {
                    CardID = 1, DeckID = 1
                };
                DeckCard dc2 = new DeckCard()
                {
                    CardID = 2, DeckID = 1
                };
                DeckCard dc3 = new DeckCard()
                {
                    CardID = 3, DeckID = 1
                };
                DeckCard dc4 = new DeckCard()
                {
                    CardID = 4, DeckID = 1
                };
                await context.DeckCards.AddAsync(dc1);

                await context.DeckCards.AddAsync(dc2);

                await context.DeckCards.AddAsync(dc3);

                await context.DeckCards.AddAsync(dc4);

                await context.SaveChangesAsync();

                await svc.CleanDeck(deck);

                Assert.Empty(await svc.GetDeck(deck.UserID, deck.DeckType));
            }
        }
Пример #3
0
        public async Task CanSlap()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("Slap").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                DeckCardMgmtSvc svc   = new DeckCardMgmtSvc(context);
                Card            card1 = new Card()
                {
                    ID = 1, Rank = Rank.Ace, Suit = Suit.hearts
                };
                Card card2 = new Card()
                {
                    ID = 2, Rank = Rank.Ace, Suit = Suit.spades
                };
                Card card3 = new Card()
                {
                    ID = 3, Rank = Rank.Ace, Suit = Suit.clubs
                };
                Card card4 = new Card()
                {
                    ID = 4, Rank = Rank.Ace, Suit = Suit.diamonds
                };
                await context.Cards.AddAsync(card1);

                await context.Cards.AddAsync(card2);

                await context.Cards.AddAsync(card3);

                await context.Cards.AddAsync(card4);

                Deck deck1 = new Deck()
                {
                    ID = 1, UserID = 1, DeckType = DeckType.Discard
                };
                Deck deck2 = new Deck()
                {
                    ID = 2, UserID = 3, DeckType = DeckType.Collect
                };
                await context.Decks.AddAsync(deck1);

                await context.Decks.AddAsync(deck2);

                DeckCard dc1 = new DeckCard()
                {
                    CardID = 1, DeckID = 1
                };
                DeckCard dc2 = new DeckCard()
                {
                    CardID = 2, DeckID = 1
                };
                DeckCard dc3 = new DeckCard()
                {
                    CardID = 3, DeckID = 1
                };
                DeckCard dc4 = new DeckCard()
                {
                    CardID = 4, DeckID = 1
                };
                await context.DeckCards.AddAsync(dc1);

                await context.DeckCards.AddAsync(dc2);

                await context.DeckCards.AddAsync(dc3);

                await context.DeckCards.AddAsync(dc4);

                User comp = new User()
                {
                    ID = 1, Name = "computer"
                };
                User player = new User()
                {
                    ID = 3, Name = "person"
                };
                await context.Users.AddAsync(comp);

                await context.Users.AddAsync(player);

                await context.SaveChangesAsync();

                List <DeckCard> queryBefore = await svc.GetDeck(1, DeckType.Discard);

                await svc.Slap("person");

                List <DeckCard> queryAfter = await svc.GetDeck(3, DeckType.Collect);

                List <int> cardsBefore = new List <int>();
                List <int> cardsAfter  = new List <int>();
                for (int i = 0; i < cardsBefore.Count; i++)
                {
                    cardsBefore.Add(queryBefore[i].CardID);
                    cardsAfter.Add(queryAfter[i].CardID);
                }

                Assert.Equal(cardsBefore, cardsAfter);
            }
        }
Пример #4
0
        public async Task CanDealGame()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("DealGame").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                DeckCardMgmtSvc svc   = new DeckCardMgmtSvc(context);
                Card            card1 = new Card()
                {
                    ID = 1, Rank = Rank.Ace, Suit = Suit.hearts
                };
                Card card2 = new Card()
                {
                    ID = 2, Rank = Rank.Ace, Suit = Suit.spades
                };
                Card card3 = new Card()
                {
                    ID = 3, Rank = Rank.Ace, Suit = Suit.clubs
                };
                Card card4 = new Card()
                {
                    ID = 4, Rank = Rank.Ace, Suit = Suit.diamonds
                };
                await context.Cards.AddAsync(card1);

                await context.Cards.AddAsync(card2);

                await context.Cards.AddAsync(card3);

                await context.Cards.AddAsync(card4);

                Deck deck1 = new Deck()
                {
                    ID = 1, UserID = 10, DeckType = DeckType.Play
                };
                Deck deck2 = new Deck()
                {
                    ID = 2, UserID = 2, DeckType = DeckType.Play
                };
                Deck discard = new Deck()
                {
                    ID = 3, UserID = 1, DeckType = DeckType.Discard
                };
                Deck deck3 = new Deck()
                {
                    ID = 4, UserID = 10, DeckType = DeckType.Collect
                };
                Deck deck4 = new Deck()
                {
                    ID = 5, UserID = 2, DeckType = DeckType.Collect
                };
                await context.Decks.AddAsync(deck1);

                await context.Decks.AddAsync(deck2);

                await context.Decks.AddAsync(deck3);

                await context.Decks.AddAsync(deck4);

                await context.Decks.AddAsync(discard);

                await context.SaveChangesAsync();


                await svc.DealGameAsync(10);

                List <DeckCard> query1 = await svc.GetDeck(10, DeckType.Play);

                List <DeckCard> query2 = await svc.GetDeck(2, DeckType.Play);

                bool tests = true;
                if (query2.Contains(query1[0]) || query2.Contains(query1[1]) || query1.Count != 2 || query2.Count != 2)
                {
                    tests = false;
                }

                Assert.True(tests);
            }
        }