public void PortraitUrl_Should_Return_Url_SpecificSize() { string characterId = "12345"; EveImageHelper.CharacterAvatarSize size = EveImageHelper.CharacterAvatarSize.Thirty_Two; string expectedUrl = $"https://image.eveonline.com/Character/{characterId}_{(int)size}.jpg"; var user = new ClaimsPrincipal( new ClaimsIdentity( new Claim[] { new Claim("PrimaryCharacterId", characterId), new Claim(ClaimTypes.Name, "fakeusername") }) ); ApplicationUser expectedApplicationUser = new ApplicationUser() { PrimaryCharacterId = characterId, Id = "1" }; Mock <UserManager <ApplicationUser> > mockUserManager = MockUserManager <ApplicationUser>(); mockUserManager.Setup(x => x.GetUserAsync(user)).ReturnsAsync(expectedApplicationUser); string result = IdentityExtensions.AvatarUrl(user, mockUserManager.Object, size); Assert.AreEqual(expectedUrl, result); }
public static string PortraitUrl(this IIdentity identity, EveImageHelper.CharacterAvatarSize imageSize = EveImageHelper.CharacterAvatarSize.Two_Fifty_Six) { var characterId = ((ClaimsIdentity)identity).FindFirst(ClaimTypes.NameIdentifier).Value; var avatarUri = EveImageHelper.GetCharacterAvatar(characterId, imageSize); return(avatarUri.ToString()); }
public void GetCharacterAvatar_Should_Return_CorrectUri_SpecificSize() { string characterId = "12345"; EveImageHelper.CharacterAvatarSize size = EveImageHelper.CharacterAvatarSize.Five_Hundred_Twelve; string expectedUrl = $"https://image.eveonline.com/Character/{characterId}_512.jpg"; string actualUri = EveImageHelper.GetCharacterAvatar(characterId, size); Assert.AreEqual(expectedUrl, actualUri); }
public void PortraitUrl_Should_Return_Url_SpecificSize() { string characterId = "12345"; EveImageHelper.CharacterAvatarSize size = EveImageHelper.CharacterAvatarSize.Thirty_Two; string expectedUrl = $"https://image.eveonline.com/Character/{characterId}_{(int)size}.jpg"; var user = new ClaimsPrincipal( new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.NameIdentifier, characterId), new Claim(ClaimTypes.Name, "fakeusername") }) ); string result = user.Identity.PortraitUrl(size); Assert.AreEqual(expectedUrl, result); }
public static string AvatarUrl(this ClaimsPrincipal identity, UserManager <ApplicationUser> userManager, EveImageHelper.CharacterAvatarSize imageSize = EveImageHelper.CharacterAvatarSize.Two_Fifty_Six) { string avatarUrl = string.Empty; var characterId = userManager.GetUserAsync(identity).Result.PrimaryCharacterId; if (string.IsNullOrEmpty(characterId)) { avatarUrl = "/images/guest.png"; } else { avatarUrl = EveImageHelper.GetCharacterAvatar(characterId, imageSize).ToString(); } return(avatarUrl); }