Exemplo n.º 1
0
        public void GetCardsTest()
        {
            var options = new DbContextOptionsBuilder <CardDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var context = new CardDBContext(options))
            {
                context.Cards.Add(new Card {
                    Description = "Han Solo", Type = "hero", Name = "Han Solo", Value = 80, ImageUrl = "hansolo.jpg", Id = 1
                });
                context.Cards.Add(new Card {
                    Description = "r2d2", Type = "hero", Name = "r2d2", Value = 32, ImageUrl = "r2d2.jpg", Id = 2
                });
                context.Cards.Add(new Card {
                    Description = "c3po", Type = "hero", Name = "c3po", Value = 34, ImageUrl = "c3po.jpg", Id = 3
                });
                context.Cards.Add(new Card {
                    Description = "Death Star", Type = "starship", Name = "Death Star", Value = 9000, ImageUrl = "deathstar.jpg", Id = 4
                });
                context.Cards.Add(new Card {
                    Description = "Millenium Falcon", Type = "starship", Name = "Millenium Falcon", Value = 6, ImageUrl = "milleniumfalcon.jpg", Id = 5
                });
                context.Cards.Add(new Card {
                    Description = "X-wing", Type = "starship", Name = "X-wing", Value = 1, ImageUrl = "xwing.jpg", Id = 6
                });
                context.SaveChanges();
            };

            using (var context = new CardDBContext(options))
            {
                var service = new SFCardGameService(context);
                var result  = service.GetCards();
                Assert.True(6 == result.Result.Count);
            }
        }
Exemplo n.º 2
0
        public void GetRandomHeroManyHeroesCardTest()
        {
            var options = new DbContextOptionsBuilder <CardDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var context = new CardDBContext(options))
            {
                context.Cards.Add(new Card {
                    Description = "Han Solo", Type = "hero", Name = "Han Solo", Value = 80, ImageUrl = "hansolo.jpg", Id = 1
                });
                context.Cards.Add(new Card {
                    Description = "r2d2", Type = "hero", Name = "r2d2", Value = 32, ImageUrl = "r2d2.jpg", Id = 2
                });
                context.Cards.Add(new Card {
                    Description = "c3po", Type = "hero", Name = "c3po", Value = 34, ImageUrl = "c3po.jpg", Id = 3
                });
                context.SaveChanges();
            };

            using (var context = new CardDBContext(options))
            {
                var service = new SFCardGameService(context);
                var result  = service.GetRandomCard("hero");
                Assert.True("Han Solo" == result.Result.Name || "r2d2" == result.Result.Name || "c3po" == result.Result.Name);
            }
        }
Exemplo n.º 3
0
        public void GetRandomHeroManyStarshipsCardTest()
        {
            var options = new DbContextOptionsBuilder <CardDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var context = new CardDBContext(options))
            {
                context.Cards.Add(new Card {
                    Description = "Death Star", Type = "starship", Name = "Death Star", Value = 9000, ImageUrl = "deathstar.jpg", Id = 1
                });
                context.Cards.Add(new Card {
                    Description = "Millenium Falcon", Type = "starship", Name = "Millenium Falcon", Value = 6, ImageUrl = "milleniumfalcon.jpg", Id = 2
                });
                context.Cards.Add(new Card {
                    Description = "X-wing", Type = "starship", Name = "X-wing", Value = 1, ImageUrl = "xwing.jpg", Id = 3
                });
                context.SaveChanges();
            };

            using (var context = new CardDBContext(options))
            {
                var service = new SFCardGameService(context);
                var result  = service.GetRandomCard("starship");
                Assert.True("Death Star" == result.Result.Name || "Millenium Falcon" == result.Result.Name || "X-wing" == result.Result.Name);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using var dbContext = new CardDBContext();

            //  dbContext.Database.EnsureCreated();  --> Tables "Card" and "Transaction" have been created in db "CardDb"
            var card1 = new Card()
            {
                CardNumber   = "1111111111111111",
                AvailBalance = 1500M
            };

            card1.Trn.Add(new Transaction()
            {
                TrnType         = TransactionType.Ecommerce,
                LimitAm0        = 200M,
                LimitAm1        = 0M,
                AggregateAmount = 200M,
                CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd")
            });

            card1.Trn.Add(new Transaction()
            {
                TrnType         = TransactionType.CardPresent,
                LimitAm0        = 200M,
                LimitAm1        = 700M,
                AggregateAmount = 900M,
                CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd")
            });


            dbContext.Add(card1);
            dbContext.SaveChanges();
        }
Exemplo n.º 5
0
        public void Test1()
        {
            using var dbContext = new CardDBContext();

            var card1 = new Card();

            card1.CardNumber   = "1111111111111111";
            card1.AvailBalance = 1500M;

            dbContext.Add(card1);
            dbContext.SaveChanges();

            var Trn1 = new Transaction();

            Trn1.TrnType         = TransactionType.Ecommerce;
            Trn1.LimitAm0        = 200M;
            Trn1.LimitAm1        = 0M;
            Trn1.AggregateAmount = 200M;
            Trn1.CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd");

            card1.AvailBalance = card1.AvailBalance - Trn1.LimitAm0 - Trn1.LimitAm1;

            if (IsGreater(Trn1.LimitAm0, Trn1.LimitAm0, card1.AvailBalance))
            {
                dbContext.Add(Trn1);
                dbContext.SaveChanges();
            }


            var Trn2 = new Transaction();

            Trn2.TrnType         = TransactionType.CardPresent;
            Trn2.LimitAm0        = 200M;
            Trn2.LimitAm1        = 700M;
            Trn2.AggregateAmount = Trn2.LimitAm0 + Trn2.LimitAm1;
            Trn2.CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd");

            card1.AvailBalance = card1.AvailBalance - Trn2.LimitAm0 - Trn2.LimitAm1;
            dbContext.SaveChanges();

            if (IsGreater(Trn2.LimitAm0, Trn2.LimitAm0, card1.AvailBalance))
            {
                dbContext.Add(Trn2);
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price,pic")] Card card, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/")
                                + file.FileName);

                    string path = Server.MapPath("~/Images/" + file.FileName);
                    card.pic = file.FileName;
                }

                db.Cards.Add(card);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(card));
        }
Exemplo n.º 7
0
        public void SaveCardTest()
        {
            var options = new DbContextOptionsBuilder <CardDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var context = new CardDBContext(options))
            {
                var service = new SFCardGameService(context);
                var result  = service.SaveCard(new Model.CardModel()
                {
                    Name = "Han Solo", Description = "Han Solo", ImageUrl = "hansolo.jpg", Type = "hero", Value = 90, Id = 1
                });
                context.SaveChanges();
            };


            using (var context = new CardDBContext(options))
            {
                Assert.Equal(1, context.Cards.CountAsync().Result);
                Assert.Equal("Han Solo", context.Cards.SingleAsync().Result.Name);
            };
        }
Exemplo n.º 8
0
        public void GetRandomStarshipCardTest()
        {
            var options = new DbContextOptionsBuilder <CardDBContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var context = new CardDBContext(options))
            {
                context.Cards.Add(new Card {
                    Description = "Han Solo", Type = "hero", Name = "Han Solo", Value = 80, ImageUrl = "hansolo.jpg", Id = 1
                });
                context.Cards.Add(new Card {
                    Description = "Death Star", Type = "starship", Name = "Death Star", Value = 9000, ImageUrl = "deathstar.hpg", Id = 2
                });
                context.SaveChanges();
            };

            using (var context = new CardDBContext(options))
            {
                var service = new SFCardGameService(context);
                var result  = service.GetRandomCard("starship");
                Assert.Equal("Death Star", result.Result.Name);
            }
        }