public void Handle_error(string id_, string jwtResponse, Type expectedExceptionType, int expectedCode, int expectedStatus, string expectedMessage, string expectedDeveloperMessage) { var testApiKey = ClientApiKeys.Builder() .SetId("2EV70AHRTYF0JOA7OEFO3SM29") .SetSecret("goPUHQMkS4dlKwl5wtbNd91I+UrRehCsEDJrIrMruK8") .Build(); var fakeRequestExecutor = Substitute.For<IRequestExecutor>(); fakeRequestExecutor.ApiKey.Returns(testApiKey); this.dataStore = TestDataStore.Create(fakeRequestExecutor, Caches.NewInMemoryCacheProvider().Build()); var request = new DefaultHttpRequest(HttpMethod.Get, new CanonicalUri($"https://foo.bar?{IdSiteClaims.JwtResponse}={jwtResponse}")); IIdSiteSyncCallbackHandler callbackHandler = new DefaultIdSiteSyncCallbackHandler(this.dataStore, request); try { var accountResult = callbackHandler.GetAccountResult(); throw new Exception("Should not reach here. Proper exception was not thrown."); } catch (IdSiteRuntimeException e) when (expectedExceptionType.IsAssignableFrom(e.GetType())) { e.Code.ShouldBe(expectedCode); e.HttpStatus.ShouldBe(expectedStatus); e.Message.ShouldBe(expectedMessage); e.DeveloperMessage.ShouldBe(expectedDeveloperMessage); } catch (Exception e) when (expectedExceptionType.IsAssignableFrom(e.GetType())) { e.Message.ShouldStartWith(expectedMessage); } }
public void Handle_response(string id_, string jwtResponse, string expectedStatus, bool isNewAccount, string expectedState) { IAccountResult accountResultFromListener = null; var listener = new InlineIdSiteSyncResultListener( onAuthenticated: result => { if (expectedStatus == IdSiteResultStatus.Authenticated) { accountResultFromListener = result; } else { throw new InvalidOperationException("This method should not have been executed"); } }, onLogout: result => { if (expectedStatus == IdSiteResultStatus.Logout) { accountResultFromListener = result; } else { throw new InvalidOperationException("This method should not have been executed"); } }, onRegistered: result => { if (expectedStatus == IdSiteResultStatus.Registered) { accountResultFromListener = result; } else { throw new InvalidOperationException("This method should not have been executed"); } }); var testApiKey = ClientApiKeys.Builder().SetId("2EV70AHRTYF0JOA7OEFO3SM29").SetSecret("goPUHQMkS4dlKwl5wtbNd91I+UrRehCsEDJrIrMruK8").Build(); var fakeRequestExecutor = Substitute.For<IRequestExecutor>(); fakeRequestExecutor.ApiKey.Returns(testApiKey); this.dataStore = TestDataStore.Create(fakeRequestExecutor, Caches.NewInMemoryCacheProvider().Build()); var request = new DefaultHttpRequest(HttpMethod.Get, new CanonicalUri($"https://foo.bar?{IdSiteClaims.JwtResponse}={jwtResponse}")); IIdSiteSyncCallbackHandler callbackHandler = new DefaultIdSiteSyncCallbackHandler(this.dataStore, request); callbackHandler.SetResultListener(listener); var accountResult = callbackHandler.GetAccountResult(); // Validate result (accountResult as DefaultAccountResult).Account.Href.ShouldBe("https://api.stormpath.com/v1/accounts/7Ora8KfVDEIQP38KzrYdAs"); (accountResultFromListener as DefaultAccountResult).Account.Href.ShouldBe("https://api.stormpath.com/v1/accounts/7Ora8KfVDEIQP38KzrYdAs"); accountResult.IsNewAccount.ShouldBe(isNewAccount); accountResultFromListener.IsNewAccount.ShouldBe(isNewAccount); accountResult.State.ShouldBe(expectedState); accountResultFromListener.State.ShouldBe(expectedState); var expectedResultStatus = IdSiteResultStatus.Parse(expectedStatus); accountResult.Status.ShouldBe(expectedResultStatus); accountResultFromListener.Status.ShouldBe(expectedResultStatus); }