Exemple #1
0
 public void WhenSelfIsNull_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         PrincipalExtensions.GetAuthenticationType(null);
     });
 }
Exemple #2
0
 public void WhenSelfIsNull_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         PrincipalExtensions.GetScopesFromClaim(null);
     });
 }
Exemple #3
0
 public void WhenSelfIsNull_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         PrincipalExtensions.HasScopeThatAllowsActions(null, "action");
     });
 }
Exemple #4
0
 public void WhenClaimTypeIsEmptyOrNull_ThrowsArgumentNullException(string claimType)
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         PrincipalExtensions.GetClaimOrDefault(new ClaimsPrincipal(), claimType);
     });
 }
Exemple #5
0
            public void WhenNoAdminRoleClaim_ReturnsFalse()
            {
                var user      = new User("admin");
                var principal = Fakes.ToPrincipal(user);

                Assert.False(PrincipalExtensions.IsAdministrator(principal));
            }
Exemple #6
0
 public void WhenSelfIsNull_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         PrincipalExtensions.GetClaimOrDefault(null, NuGetClaims.ApiKey);
     });
 }
Exemple #7
0
        // 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));
        }
Exemple #8
0
            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));
            }
Exemple #9
0
        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");
        }
Exemple #10
0
        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));
        }
Exemple #11
0
 public void WhenSelfIsNull_ReturnsFalse()
 {
     Assert.False(PrincipalExtensions.IsAdministrator(null));
 }