public void WithAuthenticationProperties_GivenExpected_ShouldPass() { var actualAuthenticationProperties = new AuthenticationProperties(); ActionResult result = new ChallengeResult(actualAuthenticationProperties); result.Should().BeChallengeResult().WithAuthenticationProperties(actualAuthenticationProperties); }
public ActionResult ExternalLogin(string provider, string returnUrl) { // 请求重定向到外部登录提供程序 var result = new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl })); return(result); }
public async Task ChallengeResult_ExecuteResultAsync_NoSchemes() { // Arrange var result = new ChallengeResult(new string[] { }, null); var auth = new Mock <IAuthenticationService>(); var httpContext = new Mock <HttpContext>(); httpContext.SetupGet(c => c.RequestServices) .Returns(CreateServices().AddSingleton(auth.Object).BuildServiceProvider()); var routeData = new RouteData(); routeData.Routers.Add(Mock.Of <IRouter>()); var actionContext = new ActionContext(httpContext.Object, routeData, new ActionDescriptor()); // Act await result.ExecuteResultAsync(actionContext); // Assert auth.Verify(c => c.ChallengeAsync(httpContext.Object, null, null), Times.Exactly(1)); }
public ChallengePage(Configuration configuration, Challenge challenge, bool noMoreChallenges, int totalPoints, bool showMessageIfSkipChallenge, bool showActionButtons) : base(configuration) { _challengeResult = new ChallengeResult() { TotalPoints = totalPoints, ChallengeType = challenge.Type, Repeating = challenge.Completed, ChallengeId = challenge.Id, }; _showMessageIfSkipChallenge = showMessageIfSkipChallenge; _showActionButtons = showActionButtons; _noMoreChallenges = noMoreChallenges; this._challenge = challenge; _configuration = configuration; NavigatingBack = false; AnimateBottomContentOnEntry = true; AnimateBottomContentOnNext = true; TopHeightProportion = 0.05; MiddleHeightProportion = 0.5; HideHasSelectedTitle = true; _countDown = challenge.TimeInSeconds; //AnimateYouHaveChosenSectionOnEntry = navigatingBack; //AnimateYouHaveChosenSectionOnBack = false; //AnimateYouHaveChosenSectionOnNext = true; }
public ScanResultViewModel(ChallengeResult result) { switch (result) { case ChallengeResult.Added: AnimationRef = "trophy.json"; ResultHeading = "Achivement Added!"; ResultBody = "You have got the points for this achivement"; HeadingColour = (Color)Application.Current.Resources["PointsColour"]; break; case ChallengeResult.Duplicate: AnimationRef = "judgement.json"; ResultHeading = "Already Scanned!"; ResultBody = "Are you scanning a bit too aggressively?"; HeadingColour = Color.White; break; case ChallengeResult.NotFound: AnimationRef = "empty-box.json"; ResultHeading = "Oops..."; ResultBody = "This doesn't look like one of our codes!"; HeadingColour = Color.White; break; } RaisePropertyChanged(new string[] { "AnimationRef", "ResultHeading", "ResultBody", "PointsColour" }); }
public ActionResult LinkLogin(string providerKey) { var userId = this.userIdentityProvider.GetUserId(this.User.Identity); var challengeResult = new ChallengeResult(providerKey, this.Url.Action(nameof(this.LinkLoginCallback), "Manage"), userId); return(challengeResult); }
public ActionResult ExternalLinkLogin(string provider) { // Request a redirect to the external login provider var external = new ChallengeResult(provider, "/login-external"); return(external); }
public ActionResult ExternalLogin(string provider, string returnUrl) { // Request a redirect to the external login provider var result = new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl })); return(result); }
public void ChallengeResult_ReturnChallengeResult() { // Arrange var authenticationProperties = new AuthenticationProperties(new AttributeDictionary { { "TestKey", "TestValue" } }); var challengeResult = new ChallengeResult { Properties = authenticationProperties, AuthenticationSchemes = new List <string> { "TestProvider" } }; // Act & Assert var result = Assert.IsType <ChallengeResult>( MvcAssert.ChallengeResult( challengeResult, authenticationProperties, "TestProvider" ) ); Assert.Equal(challengeResult, result); }
private void OnChallengeResultEvent(ChallengeResult challengeResult) { Player selectedPlayer = GetSelectedPlayer(challengeResult); if (selectedPlayer == null) { Globals.Logger.Debug($"{challengeResult.ToLongString()} discarded because no player is logged in."); return; } var wasDataAdded = DataView.AddChallengeResult(selectedPlayer.Id, challengeResult); if (!wasDataAdded) { Globals.Logger.Debug($"Player: {selectedPlayer}, {challengeResult.ToLongString()} was not added because DataView.AddChallengeResult() returned false."); return; } Globals.Logger.Debug($"Player: {selectedPlayer}, {challengeResult.ToLongString()} was added successfully. Updating UIs."); UpdateAllUIs(challengeResult); Globals.Logger.Debug($"Player: {selectedPlayer}, {challengeResult.ToLongString()} was added successfully. Saving data."); SaveData(); Globals.SpeechSynthesizer.SpeakAsync($"New personal best for {selectedPlayer.Name}."); int playerPosition = _allChallengeStandings.GetPlayerPosition(challengeResult, selectedPlayer); if (playerPosition > 0) { Globals.SpeechSynthesizer.SpeakAsync($"You are now in position {playerPosition} in this race."); } }
public void LoginWithGoogleAccount_WhenReturnUrlIsWhiteSpaceAndCalculatedReturnUriIsTrustedDomain_ReturnsChallengeResultWhereAuthenticationSchemesContainsSchemeForGoogle() { Controller sut = CreateSut(); ChallengeResult result = (ChallengeResult)sut.LoginWithGoogleAccount(" "); Assert.That(result.AuthenticationSchemes.Contains(GoogleDefaults.AuthenticationScheme), Is.True); }
public IActionResult SignIn([FromForm] string provider) { ChallengeResult challenge = Challenge(new AuthenticationProperties { RedirectUri = "/" }); return(challenge); }
public void LoginWithMicrosoftAccount_WhenReturnUrlIsEmptyAndCalculatedReturnUriIsTrustedDomain_ReturnsChallengeResultWhereAuthenticationSchemesContainsSchemeForMicrosoftAccount() { Controller sut = CreateSut(); ChallengeResult result = (ChallengeResult)sut.LoginWithMicrosoftAccount(string.Empty); Assert.That(result.AuthenticationSchemes.Contains(MicrosoftAccountDefaults.AuthenticationScheme), Is.True); }
public ActionResult ExternalLogin(string provider) { Session["dummy"] = true; var challenge = new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", null)); // Request a redirect to the external login provider return(challenge); }
public IActionResult SignIn(String provider) { ChallengeResult challengeResult = Challenge(new AuthenticationProperties { RedirectUri = "/" }, provider);; return(challengeResult); }
public IActionResult ProviderLogin(string provider, string?returnUrl = null) { var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, $"/api/v0/authentication/provider/callback?returnUrl={returnUrl}"); var res = new ChallengeResult(provider, properties); return(res); }
public void LoginWithMicrosoftAccount_WhenReturnUrlHasValueWhichAreTrustedRelativeUrl_ReturnsChallengeResultWhereAuthenticationSchemesContainsSchemeForMicrosoftAccount() { Controller sut = CreateSut(); string returnUrl = $"/{_fixture.Create<string>()}"; ChallengeResult result = (ChallengeResult)sut.LoginWithMicrosoftAccount(returnUrl); Assert.That(result.AuthenticationSchemes.Contains(MicrosoftAccountDefaults.AuthenticationScheme), Is.True); }
public IActionResult OnGet(string idpName, string returnUrl = "/") { // Redirect to the external login provider var redirectUrl = this.Url.Page("LoginExternalCallback", values: new { returnUrl }); var properties = this._signInManager.ConfigureExternalAuthenticationProperties(idpName, redirectUrl); var result = new ChallengeResult(idpName, properties) as IActionResult; return(result ?? this.Page()); }
public IActionResult ExternalLogin(string provider, string returnUrl = null) { var redirectUrl = Url.Action("ExternalLoginCallback", values: new { returnUrl }); // var redirectUrl = "/Users/ExternalLoginCallback"; var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); var result = new ChallengeResult(provider, properties); return(result); }
public void LoginWithGoogleAccount_WhenReturnUrlHasValueWhichAreTrustedAbsoluteUrl_ReturnsChallengeResultWhereAuthenticationSchemesContainsSchemeForGoogle() { Controller sut = CreateSut(); string returnUrl = $"http://localhost/{_fixture.Create<string>()}/{_fixture.Create<string>()}"; ChallengeResult result = (ChallengeResult)sut.LoginWithGoogleAccount(returnUrl); Assert.That(result.AuthenticationSchemes.Contains(GoogleDefaults.AuthenticationScheme), Is.True); }
/// <summary> /// Returns player to main menu if challenge was rejected. /// </summary> /// <param name="challengeResult">response of enemy player to challenge</param> private void OnChallengeResult(ChallengeResult challengeResult) { if (!challengeResult.ChallengeAccepted) { Scenes.Load(Scenes.MAIN_MENU_SCENE); NotificationManager.Instance.Show(ChallengeImage, "Challenge canceled!", myChallenge.ChallengeFor + " declined your challenge"); myChallenge = null; } }
public IActionResult OnPost(string provider, string returnUrl = null) { // Request a redirect to the external login provider. var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl }); var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); var result = new ChallengeResult(provider, properties); return(result); }
public void ExternalLogin_WhenRequestUrl_ShouldReturnChallengeResult() { _subject.Url = new UrlHelper(new RequestContext(_httpContextMock.Object, new RouteData()), new RouteCollection()); var result = _subject.ExternalLogin("mark", _testUrl) as ChallengeResult; var expectedResult = new ChallengeResult("mark", null); result.Should().BeEquivalentTo(expectedResult); }
public void WithRedirectUri_GivenExpected_ShouldPass() { var actualRedirectUri = "redirectUri"; var actualAuthenticationProperties = new AuthenticationProperties { RedirectUri = actualRedirectUri }; ActionResult result = new ChallengeResult(actualAuthenticationProperties); result.Should().BeChallengeResult().WithRedirectUri(actualRedirectUri); }
public void WithIssuedUtc_GivenExpected_ShouldPass() { var actualIssuedUtc = TestLastModified; var actualAuthenticationProperties = new AuthenticationProperties { IssuedUtc = actualIssuedUtc }; ActionResult result = new ChallengeResult(actualAuthenticationProperties); result.Should().BeChallengeResult().WithIssuedUtc(actualIssuedUtc); }
public void ContainsScheme_GivenExpected_ShouldPass() { const string testScheme = "testScheme"; var actualSchemes = new List <string> { testScheme }; ActionResult result = new ChallengeResult(actualSchemes); result.Should().BeChallengeResult().ContainsScheme(testScheme); }
public void WithIsPersistent_GivenExpected_ShouldPass() { var actualIsPersistent = true; var actualAuthenticationProperties = new AuthenticationProperties { IsPersistent = actualIsPersistent }; ActionResult result = new ChallengeResult(actualAuthenticationProperties); result.Should().BeChallengeResult().WithIsPersistent(actualIsPersistent); }
public void WithAllowRefresh_GivenExpected_ShouldPass() { var actualAllowRefresh = true; var actualAuthenticationProperties = new AuthenticationProperties { AllowRefresh = actualAllowRefresh }; ActionResult result = new ChallengeResult(actualAuthenticationProperties); result.Should().BeChallengeResult().WithAllowRefresh(actualAllowRefresh); }
public async Task ConcludeChallengeAsync(long challengeId, ChallengeResult result) { var targetChallenge = await this.Context.Challenges.FirstOrDefaultAsync(x => x.Id == challengeId); targetChallenge.Status = ChallengeStatus.Concluded; targetChallenge.Result = result; // time to handle resulting transactions var wagers = this.Context.Wagers.Where(x => x.Challenge == targetChallenge); var sourceUsers = targetChallenge.SourceGroup.Relationships.Select(x => x.User); var targetUsers = targetChallenge.TargetGroup.Relationships.Select(x => x.User); var sourceWagers = wagers.Where(x => sourceUsers.Contains(x.User)); var targetWagers = wagers.Where(x => targetUsers.Contains(x.User)); if (result == ChallengeResult.Tie || result == ChallengeResult.Cancelled) { this.Context.Wagers.RemoveRange(wagers); } else if (result == ChallengeResult.SourceWon) { var totalWagerAmount = sourceWagers.Sum(x => x.Amount); var winningsAmount = totalWagerAmount / targetUsers.Count(); // split evenly for all winners foreach (var user in targetUsers) { user.MarbleAmount += winningsAmount; } foreach (var wager in sourceWagers) { var user = wager.User; user.MarbleAmount -= wager.Amount; // remove what the user wagered } } else if (result == ChallengeResult.TargetWon) { var totalWagerAmount = targetWagers.Sum(x => x.Amount); var winningsAmount = totalWagerAmount / sourceUsers.Count(); // split evenly for all winners foreach (var user in sourceUsers) { user.MarbleAmount += winningsAmount; } foreach (var wager in targetWagers) { var user = wager.User; user.MarbleAmount -= wager.Amount; // remove what the user wagered } } // now clean up all wagers since they are concluded this.Context.Wagers.RemoveRange(wagers); }
public void WithAuthenticationProperties_GivenUnexpected_ShouldFail() { var actualAuthenticationProperties = new AuthenticationProperties(); var expectedAuthenticationProperties = new AuthenticationProperties(); ActionResult result = new ChallengeResult(actualAuthenticationProperties); var failureMessage = FailureMessageHelper.AuthenticationPropertiesExpectations(result); Action a = () => result.Should().BeChallengeResult().WithAuthenticationProperties(expectedAuthenticationProperties, Reason, ReasonArgs); a.Should().Throw <Exception>().WithMessage(failureMessage); }
public async Task ChallengeResult_Execute() { // Arrange var result = new ChallengeResult("", null); var httpContext = new Mock<HttpContext>(); var auth = new Mock<AuthenticationManager>(); httpContext.Setup(o => o.Authentication).Returns(auth.Object); var routeData = new RouteData(); routeData.Routers.Add(Mock.Of<IRouter>()); var actionContext = new ActionContext(httpContext.Object, routeData, new ActionDescriptor()); // Act await result.ExecuteResultAsync(actionContext); // Assert auth.Verify(c => c.ChallengeAsync("", null), Times.Exactly(1)); }
public void ChallengeResult_ExecuteNoSchemes() { // Arrange var result = new ChallengeResult(new string[] { }, null); var httpContext = new Mock<HttpContext>(); var auth = new Mock<AuthenticationManager>(); httpContext.Setup(o => o.Authentication).Returns(auth.Object); var routeData = new RouteData(); routeData.Routers.Add(Mock.Of<IRouter>()); var actionContext = new ActionContext(httpContext.Object, routeData, new ActionDescriptor()); // Act result.ExecuteResult(actionContext); // Assert auth.Verify(c => c.Challenge((AuthenticationProperties)null), Times.Exactly(1)); }
public void ChallengeResult_Execute() { // Arrange var result = new ChallengeResult(new string[] { }, null); var httpContext = new Mock<HttpContext>(); var httpResponse = new Mock<HttpResponse>(); httpContext.Setup(o => o.Response).Returns(httpResponse.Object); var routeData = new RouteData(); routeData.Routers.Add(Mock.Of<IRouter>()); var actionContext = new ActionContext(httpContext.Object, routeData, new ActionDescriptor()); // Act result.ExecuteResult(actionContext); // Assert httpResponse.Verify(c => c.Challenge(null, (IEnumerable<string>)new string[] { }), Times.Exactly(1)); }
public void setChallengeResult2(ChallengeResult r) { result2 = r; }
public void setChallengeResult1(ChallengeResult r) { result1 = r; }