public void WhenSelfIsNull_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { PrincipalExtensions.GetAuthenticationType(null); }); }
public void WhenSelfIsNull_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { PrincipalExtensions.GetScopesFromClaim(null); }); }
public void WhenSelfIsNull_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { PrincipalExtensions.HasScopeThatAllowsActions(null, "action"); }); }
public void WhenClaimTypeIsEmptyOrNull_ThrowsArgumentNullException(string claimType) { Assert.Throws <ArgumentNullException>(() => { PrincipalExtensions.GetClaimOrDefault(new ClaimsPrincipal(), claimType); }); }
public void WhenNoAdminRoleClaim_ReturnsFalse() { var user = new User("admin"); var principal = Fakes.ToPrincipal(user); Assert.False(PrincipalExtensions.IsAdministrator(principal)); }
public void WhenSelfIsNull_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { PrincipalExtensions.GetClaimOrDefault(null, NuGetClaims.ApiKey); }); }
// GET: Tweets public async Task <IActionResult> Index() { var model = new TweetHomePageViewModel(); var userId = PrincipalExtensions.FindFirstValue(this.User, ClaimTypes.NameIdentifier); var tweets = await Queryable.Where <Tweet>(_context.Tweet, t => t.UserId == userId) .AsNoTracking() .ToListAsync(); var twitterUser = _context.TwitterUsers .SingleOrDefault(t => t.UserID == userId); if (twitterUser == null) { return(RedirectToAction("Join", new { id = userId })); } model.User = twitterUser; model.User.UserImage = "https://graph.facebook.com/" + _userManager.FindByIdAsync(userId).Result.FbProfile + "/?fields=picture&type=large"; model.User.UserName = _userManager.FindByIdAsync(twitterUser.UserID).Result.UserName; foreach (var tweet in tweets) { tweet.UserImage = "https://graph.facebook.com/" + _userManager.FindByIdAsync(userId).Result.FbProfile + "/?fields=picture&type=large"; tweet.UserName = _userManager.FindByIdAsync(tweet.UserId).Result.UserName; } model.Tweets = tweets; return(View(model)); }
public void WhenAdminRoleClaim_ReturnsTrue() { var user = new User("admin") { Roles = new [] { new Role { Key = 1, Name = "Admins" } } }; var principal = Fakes.ToPrincipal(user); Assert.True(PrincipalExtensions.IsAdministrator(principal)); }
public void GetName_UsingNullAsPrincipal_MustThrowException() { // Arrange IPrincipal principal = null; // Act // ReSharper disable once InvokeAsExtensionMethod // ReSharper disable once ExpressionIsAlwaysNull Action actionExpectedToFail = () => PrincipalExtensions.GetName(principal); // Assert actionExpectedToFail.Should().ThrowExactly <ArgumentNullException>() .And.ParamName.Should().Be(nameof(principal), "because a null principal does not have a name"); }
public async Task <IActionResult> Create([Bind("Id,Body")] Tweet tweet) { var userId = PrincipalExtensions.FindFirstValue(this.User, ClaimTypes.NameIdentifier); tweet.UserId = userId; tweet.TweetUserID = _context.TwitterUsers.SingleOrDefault(u => u.UserID == userId).ID; tweet.DateTime = DateTime.Now; if (ModelState.IsValid) { _context.Add(tweet); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(tweet)); }
public void WhenSelfIsNull_ReturnsFalse() { Assert.False(PrincipalExtensions.IsAdministrator(null)); }