示例#1
0
        public IActionResult Secret()
        {
            int?userId = HttpContext.Session.GetInt32("UserId");

            if (userId == null)
            {
                ModelState.AddModelError("myUser.Email", "Login to continue");
                return(View("Index"));
            }
            int id = (int)userId;

            ViewBag.User = id;

            string Name = HttpContext.Session.GetString("Username");

            ViewBag.Name = Name;

            AllSecrets Secrets = new AllSecrets()
            {
                allSecrets = dbContext.Secrets.Include(sec => sec.Poster)
                             .Include(sec => sec.Likes)
                             .ThenInclude(Like => Like.User)
                             .OrderByDescending(d => d.CreatedAt).Take(10)
                             .ToList()
            };

            return(View(Secrets));
        }
示例#2
0
        public IActionResult createPost(Secret newSecret)
        {
            int?userId = HttpContext.Session.GetInt32("UserId");

            ViewBag.User = (int)userId;

            string Name = HttpContext.Session.GetString("Username");

            ViewBag.Name = Name;

            if (ModelState.IsValid)
            {
                if (newSecret.UserId == userId)
                {
                    dbContext.Add(newSecret);
                    dbContext.SaveChanges();
                }
                return(RedirectToAction("Secret"));
            }
            else
            {
                AllSecrets Secrets = new AllSecrets()
                {
                    allSecrets = dbContext.Secrets.Include(sec => sec.Poster)
                                 .Include(sec => sec.Likes)
                                 .ThenInclude(Like => Like.User)
                                 .OrderByDescending(d => d.CreatedAt).Take(10)
                                 .ToList()
                };
                return(View("Secret", Secrets));
            }
        }
示例#3
0
        public void HandlesKeys()
        {
            // Arrange
            var secretDict   = CreateSecretDictionary(AllSecrets, AllSecrets);
            var keysToVerify = AllSecrets.Select(secret => secret.Key).ToList();

            // Act
            foreach (var secretKey in secretDict.Keys)
            {
                // Assert
                Assert.Contains(secretKey, keysToVerify);
                keysToVerify.Remove(secretKey);
            }
            Assert.Empty(keysToVerify);
        }
示例#4
0
        public void HandlesValues()
        {
            // Arrange
            var secretDict      = CreateSecretDictionary(AllSecrets, AllSecrets);
            var secretsToVerify = AllSecrets.Select(secret => secret.InjectedValue).ToList();

            // Act
            foreach (var secretValue in secretDict.Values)
            {
                // Assert
                Assert.Contains(secretValue, secretsToVerify);
                secretsToVerify.Remove(secretValue);
            }
            Assert.Empty(secretsToVerify);
        }