Beispiel #1
0
        private void GenMockData()
        {
            var uId = new Guid("ec04ee08-f434-41d0-a208-15bd2dcb3389");
            var pId = Guid.NewGuid();
            var ppc = new PizzaPriceCategory {
                Description = "LOL", Id = 1
            };
            var user = new ApplicationUser {
                Id = uId.ToString(), Email = "*****@*****.**", UserName = "******"
            };

            _context.Users.Add(user);
            _context.Users.Add(new ApplicationUser {
                Id = Guid.NewGuid().ToString(), Email = "*****@*****.**", UserName = "******"
            });
            _context.PizzaPriceCategories.Add(ppc);
            _context.SaveChanges();
            _context.PizzaPriceInfo.Add(new PizzaPriceInfo {
                Id = 1, Price = 6.05m, PriceCategory = ppc, Size = 32
            });
            _context.Pizzas.Add(new Pizza {
                Id = pId, NameEn = "Havaian", PriceCategory = _context.PizzaPriceCategories.Single(c => c.Id == 1)
            });
            _context.SaveChangesAsync();
        }
        public async Task User_use_code()
        {
            Guid   code = Guid.NewGuid();
            string uid  = "ec04ee08-f434-41d0-a208-15bd2dcb3389";

            // Add a code (non user)
            _context.PrepaidCodes.Add(new PrepaidCode {
                Amount = 10, CreationDate = DateTime.Now.AddDays(-1), Id = code
            });
            _context.Users.Add(new ApplicationUser {
                Id = uid
            });
            _context.SaveChanges();


            var m_User = new Mock <ClaimsPrincipal>();
            var m_Data = new Mock <ITempDataProvider>();

            m_User.Setup(t => t.Claims).Returns(new[] { new Claim(ClaimTypes.NameIdentifier, uid) });
            var httpContext = new DefaultHttpContext()
            {
                User = m_User.Object
            };
            var manageCtrl =
                new Controllers.ManageController(null, null, null, null, null, _context,
                                                 new Mock <IMemoryCache>().Object, new Mock <IStringLocalizer <Controllers.ManageController> >().Object)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = httpContext
                },
                TempData = new TempDataDictionary(httpContext, m_Data.Object)
            };

            // Actual test
            var money1 = _context.Users.Single(u => u.Id == uid).Coins;
            await manageCtrl.Redeem(new ViewModels.ManageViewModels.RedeemViewModel {
                Id = code.ToString()
            });

            var money2 = _context.Users.Single(u => u.Id == uid).Coins;

            Assert.Equal(money1 + 10, money2);
            Assert.NotNull(_context.PrepaidCodes.Single(c => c.Id == code).RedemptionDate);
            Assert.Equal(uid, _context.PrepaidCodes.Single(c => c.Id == code).Redeemer.Id);
        }