Example #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)));
            }
        }
Example #2
0
        public static bool WithdrawCash(Owner owner)
        {
            int cashToWithdraw;

            Console.WriteLine("How much money do you want to withdraw?");
            try
            {
                cashToWithdraw = Convert.ToInt32(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Invalid data type.");
                return(false);
            }

            using (var context = new CardDbContext())
            {
                var card = context.Card
                           .Where(c => c.OwnerId == owner.Id)
                           .FirstOrDefault();
                card.Money = card.Money - cashToWithdraw;
                context.SaveChanges();

                return(true);
            }
        }
        public static bool DepositCash(Owner owner)
        {
            int cashToDeposit;

            Console.WriteLine("How much money do you want to deposit?");
            try
            {
                cashToDeposit = Convert.ToInt32(Console.ReadLine());
            }
            catch
            {
                return(false);
            }

            using (var context = new CardDbContext())
            {
                var card = context.Card
                           .Where(c => c.OwnerId == owner.Id)
                           .FirstOrDefault();
                card.Money = card.Money + cashToDeposit;
                context.SaveChanges();

                return(true);
            }
        }
Example #4
0
 public CardTest(CardLimitFixture fixture)
 {
     _cards = fixture.Scope.ServiceProvider
              .GetRequiredService <ICardService>();
     _dbContext = fixture.Scope.ServiceProvider
                  .GetRequiredService <CardDbContext>();
     _limits = fixture.Scope.ServiceProvider
               .GetRequiredService <ILimitService>();
 }
Example #5
0
 public static int CheckCash(Owner owner)
 {
     using (var context = new CardDbContext())
     {
         var cash = context.Card
                    .Where(c => c.OwnerId == owner.Id)
                    .FirstOrDefault();
         return(cash.Money);
     }
 }
Example #6
0
        public async Task CanGetNewUser()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("GetNewUser").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                UserMgmtSvc svc = new UserMgmtSvc(context);

                Assert.Equal("test", (await svc.GetUserAsync("test")).Name);
            }
        }
Example #7
0
 public CardDbContext GetContext()
 {
     if (_cardDbContext == null || !_cardDbContext.CardDbLocation.Equals(CardDbLocation))
     {
         _cardDbContext = Create();
         return(_cardDbContext);
     }
     else
     {
         return(_cardDbContext);
     }
 }
        public static void Main(string[] args)
        {
            IWebHost webHost = CreateWebHostBuilder(args).Build();

            using (IServiceScope serviceScope = webHost.Services.CreateScope())
            {
                using (CardDbContext cardDb = serviceScope.ServiceProvider.GetRequiredService <CardDbContext>())
                {
                    if (!cardDb.Cards.Any())
                    {
                        Card Card1 = new Card()
                        {
                            Number    = "5678123491234567",
                            ValidTHRU = "17/08",
                            CVV       = "179",
                            AddedDate = DateTime.Now,
                            Balance   = 400,
                            IsUsed    = true
                        };

                        Card Card2 = new Card()
                        {
                            Number    = "1234567891234567",
                            ValidTHRU = "15/08",
                            CVV       = "178",
                            AddedDate = DateTime.Now,
                            Balance   = 800,
                            IsUsed    = true
                        };

                        Card Card3 = new Card()
                        {
                            Number    = "9123123456784567",
                            ValidTHRU = "03/08",
                            CVV       = "158",
                            AddedDate = DateTime.Now,
                            Balance   = 500,
                            IsUsed    = true
                        };

                        cardDb.Cards.AddRange(Card1, Card2, Card3);

                        cardDb.SaveChanges();
                    }
                }
            }

            webHost.Run();
        }
Example #9
0
        public async Task CanCreateCollectDeck()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("GetNewUser").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                UserMgmtSvc svc = new UserMgmtSvc(context);

                User user = await svc.GetUserAsync("test");

                var query = await context.Decks.FirstOrDefaultAsync(d => d.UserID == user.ID && d.DeckType == DeckType.Collect);

                Assert.NotNull(query);
            }
        }
Example #10
0
        public async Task CanUpdateSecondCard()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("TestUserCards").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                UserMgmtSvc svc = new UserMgmtSvc(context);

                User user = await svc.GetUserAsync("test");

                user.SecondCard = 1;
                await svc.UpdateFirstCard("test", 1);

                Assert.Equal(1, user.SecondCard);
            }
        }
Example #11
0
        public async Task CanGetAllCards()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("GetAllCards").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);

                await context.SaveChangesAsync();

                List <Card> list = new List <Card>();
                list.Add(card1);
                list.Add(card2);
                list.Add(card3);
                list.Add(card4);

                var query = await svc.GetAllCardsAsync();

                Assert.Equal(list, query);
            }
        }
Example #12
0
        public void CanCompareCardsFalse()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("CompareCardsFalse").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.King, Suit = Suit.spades
                };

                Assert.False(svc.CompareCards(card1, card2));
            }
        }
Example #13
0
        public static Owner CheckOwner(string ownerId)
        {
            try
            {
                Guid ownerGuidId = new Guid(ownerId);

                using (var context = new CardDbContext())
                {
                    var owner = context.Owner
                                .Where(o => o.Id == ownerGuidId)
                                .FirstOrDefault();
                    return(owner);
                }
            }
            catch
            {
                return(null);
            }
        }
Example #14
0
        public async Task CanFlipReturnNull()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("FlipReturnNull").Options;

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

                await context.SaveChangesAsync();

                var query = await svc.Flip(deck.UserID);

                Assert.Null(query);
            }
        }
Example #15
0
        public async Task CanGetCardFromPile()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("GetCardFromPile").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);

                DeckCard card1 = new DeckCard()
                {
                    CardID = 1, DeckID = 1
                };
                DeckCard card2 = new DeckCard()
                {
                    CardID = 2, DeckID = 1
                };
                DeckCard card3 = new DeckCard()
                {
                    CardID = 3, DeckID = 1
                };
                await context.DeckCards.AddAsync(card1);

                await context.DeckCards.AddAsync(card2);

                await context.DeckCards.AddAsync(card3);

                await context.SaveChangesAsync();

                List <DeckCard> list = new List <DeckCard>();
                list.Add(card1);
                list.Add(card2);
                list.Add(card3);

                Assert.Contains(await svc.GetCard(1, DeckType.Play), list);
            }
        }
Example #16
0
        public async Task CanUpdateDeckCard()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("UpdateDeckCard").Options;

            using (CardDbContext context = new CardDbContext(options))
            {
                DeckCardMgmtSvc svc   = new DeckCardMgmtSvc(context);
                DeckCard        card1 = new DeckCard()
                {
                    CardID = 1, DeckID = 1
                };
                await context.DeckCards.AddAsync(card1);

                await context.SaveChangesAsync();

                await svc.UpdateDeckCard(card1.CardID, card1.DeckID, 2);

                var query = await context.DeckCards.FirstOrDefaultAsync(d => d.CardID == 1);

                Assert.Equal(2, query.DeckID);
            }
        }
Example #17
0
 public CardsController(CardDbContext context)
 {
     _context = context;
 }
Example #18
0
 public CardService(CardDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public CardUsersController(CardDbContext context, IUserService userService)
 {
     _userService = userService;
 }
Example #20
0
 public DeckCardMgmtSvc(CardDbContext context)
 {
     _context = context;
 }
Example #21
0
 public CardEmployersController(CardDbContext context)
 {
     _context = context;
 }
Example #22
0
 public UserMgmtSvc(CardDbContext context)
 {
     _context = context;
 }
Example #23
0
 public RolesController(CardDbContext context)
 {
     _context = context;
 }
Example #24
0
        //ivate ILimitService _limit;

        public LimitService(CardDbContext dbContext, ICardService card)
        {
            _dbContext = dbContext;
            _card      = card;
            //imit = limit;
        }
Example #25
0
 public UserService(IOptions <AppSettings> appSettings, CardDbContext context)
 {
     _appSettings = appSettings.Value;
     _context     = context;
 }
Example #26
0
 public ValuesController(CardDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #27
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);
            }
        }
Example #28
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);
            }
        }
Example #29
0
        public async Task CanFlipReturnCard()
        {
            DbContextOptions <CardDbContext> options = new DbContextOptionsBuilder <CardDbContext>().UseInMemoryDatabase("FlipReturnCard").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.Play
                };
                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();

                Assert.NotNull(await svc.Flip(deck.UserID));
            }
        }