public void PullLatestNews() { text.text = "Pulling latest news..."; OnFacet <NewsFacet> .Call <List <NewsItem> >( nameof(NewsFacet.GetLatestNews) ) .Then(news => { DisplayNews(news); }) .Catch(exception => { text.text = "Pulling news failed with an exception:\n" + exception.ToString(); }); }
public void InvalidPasswordGetsRejected() { new PlayerEntity { email = "*****@*****.**", password = Hash.Make("different-secret") }.Save(); var response = OnFacet <EmailLoginFacet> .CallSync <bool>( nameof(EmailLoginFacet.Login), "*****@*****.**", "secret" ); Assert.IsFalse(response); Assert.IsFalse(Auth.Check()); }
public IEnumerator ItCanPassBindVarsResults() { yield return(OnFacet <RawAqlFacet> .Call <List <JsonValue> >( nameof(RawAqlFacet.Get), @" RETURN @foo ", new JsonObject { ["foo"] = 24 } ).Then(results => { Assert.AreEqual( "[24]".Replace('\'', '"'), Serializer.ToJson(results).ToString() ); }).AsCoroutine()); }
public IEnumerator ItRoutesMessagesByType() { CreateClient(ChannelParameterOne); yield return(WaitForClientToSettle()); Assert.IsEmpty(client.receivedMessages); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterOne, "Hello world!" ).AsCoroutine()); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyOtherMessage), ChannelParameterOne, 42 ).AsCoroutine()); yield return(WaitForMessages(2)); Assert.AreEqual(2, client.receivedMessages.Count); Assert.AreEqual(2, client.calledMethods.Count); Assert.IsInstanceOf <MyMessage>(client.receivedMessages[0]); Assert.AreEqual( "Hello world!", ((MyMessage)client.receivedMessages[0]).foo ); Assert.AreEqual( nameof(MyBroadcastingClient.OnMyMessage), client.calledMethods[0] ); Assert.IsInstanceOf <MyOtherMessage>(client.receivedMessages[1]); Assert.AreEqual( 42, ((MyOtherMessage)client.receivedMessages[1]).bar ); Assert.AreEqual( nameof(MyBroadcastingClient.OnMyOtherMessage), client.calledMethods[1] ); yield return(null); }
public void InitiatingTransactionWithNoProducts() { var transaction = new SteamTransactionEntity { playerSteamId = 123456789L }; Http.Fake(); Assert.Throws <ArgumentException>(() => { OnFacet <SteamPurchasingServerFacet> .CallSync( nameof(SteamPurchasingServerFacet.InitiateTransaction), transaction ); }, "Given transaction has no items inside of it."); Http.AssertNothingSent(); }
private async void OnEnable() { var subscription = await OnFacet <BroadcastingFacet> .CallAsync <ChannelSubscription>( nameof(BroadcastingFacet.SubscribeToMyChannel), channelParameter, sendMessageAfterSubscribing ); FromSubscription(subscription) .Forward <MyMessage>(OnMyMessage) .Forward <MyOtherMessage>(OnMyOtherMessage) .ElseLogWarning(); // now we can start doing experiments hasSettled = true; }
public void YouCanLogOut() { var player = new PlayerEntity { steamId = "123456789" }; player.Save(); ActingAs(player); var response = OnFacet <SteamLoginFacet> .CallSync <bool>( nameof(SteamLoginFacet.Logout) ); Assert.IsTrue(response); Assert.IsFalse(Auth.Check()); }
private async void LoginButtonClicked() { bool success = await OnFacet <AuthFacet> .CallAsync <bool>( nameof(AuthFacet.Login), emailInputField.text, passwordInputField.text ); if (success) { LoginSucceeded(); } else { LoginFailed(); } }
public void ItRunsMyParametrizedProcedure() { SomeFacet.flag = false; OnFacet <SomeFacet> .CallSync( nameof(SomeFacet.MyParametrizedProcedure), true ); Assert.IsTrue(SomeFacet.flag); OnFacet <SomeFacet> .CallSync( nameof(SomeFacet.MyParametrizedProcedure), false ); Assert.IsFalse(SomeFacet.flag); }
public void ItStoresLogout() { var player = new PlayerEntity { name = "John" }; player.Save(); Session.Set(AuthenticationManager.SessionKey, player.EntityId); OnFacet <AuthenticationFacet> .CallSync( nameof(AuthenticationFacet.Logout) ); Assert.IsNull( Session.Get <string>(AuthenticationManager.SessionKey) ); }
public void YouCanLogOut() { var player = new PlayerEntity { email = "*****@*****.**", password = Hash.Make("secret") }; player.Save(); ActingAs(player); var response = OnFacet <EmailLoginFacet> .CallSync <bool>( nameof(EmailLoginFacet.Logout) ); Assert.IsTrue(response); Assert.IsFalse(Auth.Check()); }
public void FinalizingTransactionThatIsNotInitiated() { var transaction = new SteamTransactionEntity { playerSteamId = 123456789L, state = SteamTransactionEntity.BeingPreparedState }; Http.Fake(); Assert.Throws <SteamPurchasingServerFacet.SteamMicrotransactionException>(() => { OnFacet <SteamPurchasingServerFacet> .CallSync <SteamTransactionEntity>( nameof(SteamPurchasingServerFacet.FinalizeTransaction), 123456789L, true ); }, "No initiated transaction with order id 123456789 was found."); Http.AssertNothingSent(); }
public void ItLogsPlayerIn() { var player = new PlayerEntity { steamId = "123456789" }; player.Save(); Env.Set("STEAM_API_URL", "https://partner.steam-api.com/"); Env.Set("STEAM_PUBLISHER_KEY", "some-publisher-key"); Env.Set("STEAM_APP_ID", "480"); Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["params"] = new JsonObject { ["result"] = "OK", ["steamid"] = "123456789", ["ownersteamid"] = "123456789", ["vacbanned"] = false, ["publisherbanned"] = false } } })); OnFacet <SteamLoginFacet> .CallSync( nameof(SteamLoginFacet.Login), "valid-session-token" ); Http.AssertSent(request => request.Url == "https://partner.steam-api.com/" + "ISteamUserAuth/AuthenticateUserTicket/v1/?" + "key=some-publisher-key&" + "appid=480&" + "ticket=valid-session-token" ); Assert.IsTrue(Auth.Check()); Assert.AreEqual( player.EntityId, Auth.Id() ); }
public async void OnRegisterClicked() { statusText.enabled = true; statusText.text = "Registering..."; if (passwordField.text != confirmPasswordField.text) { statusText.text = "Password confirmation does not match"; return; } var response = await OnFacet <EmailRegisterFacet> .CallAsync <EmailRegisterResponse>( nameof(EmailRegisterFacet.Register), emailField.text, passwordField.text ); switch (response) { case EmailRegisterResponse.Ok: statusText.text = "Registration succeeded"; break; case EmailRegisterResponse.EmailTaken: statusText.text = "This email has already been registered"; break; case EmailRegisterResponse.InvalidEmail: statusText.text = "This is not a valid email address"; break; case EmailRegisterResponse.WeakPassword: statusText.text = "Password needs to be at least 8 " + "characters long"; break; default: statusText.text = "Unknown response: " + response; break; } }
public async void OnLoginClicked() { statusText.enabled = true; statusText.text = "Logging in..."; var response = await OnFacet <EmailLoginFacet> .CallAsync <bool>( nameof(EmailLoginFacet.Login), emailField.text, passwordField.text ); if (response) { SceneManager.LoadScene(sceneAfterLogin); } else { statusText.text = "Given credentials are not valid"; } }
public void RegisteredAnyCaseEmailCanLogInWhenExact() { new PlayerEntity { email = "*****@*****.**", password = Hash.Make("secret") }.Save(); var response = OnFacet <EmailLoginFacet> .CallSync <bool>( nameof(EmailLoginFacet.Login), "*****@*****.**", "secret" ); Assert.IsTrue(response); Assert.IsTrue(Auth.Check()); Assert.AreEqual( "*****@*****.**", Auth.GetPlayer <PlayerEntity>().email ); }
public IEnumerator FirstThereIsNoAuthenticatedPlayer() { yield return(OnFacet <AuthenticationFacet> .Call <PlayerEntity>( nameof(AuthenticationFacet.GetPlayer) ).Then(p => { Assert.IsNull(p); }).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call <bool>( nameof(AuthenticationFacet.Check) ).Then(c => { Assert.IsFalse(c); }).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call <string>( nameof(AuthenticationFacet.Id) ).Then(id => { Assert.IsNull(id); }).AsCoroutine()); }
public void EmailCanBeAnyCaseAndNonTrimmed() { new PlayerEntity { email = "*****@*****.**", password = Hash.Make("secret") }.Save(); var response = OnFacet <EmailLoginFacet> .CallSync <bool>( nameof(EmailLoginFacet.Login), " [email protected] ", "secret" ); Assert.IsTrue(response); Assert.IsTrue(Auth.Check()); Assert.AreEqual( "*****@*****.**", Auth.GetPlayer <PlayerEntity>().email ); }
public void ProperCredentialsLogYouIn() { new PlayerEntity { email = "*****@*****.**", password = Hash.Make("secret") }.Save(); var response = OnFacet <EmailLoginFacet> .CallSync <bool>( nameof(EmailLoginFacet.Login), "*****@*****.**", "secret" ); Assert.IsTrue(response); Assert.IsTrue(Auth.Check()); Assert.AreEqual( "*****@*****.**", Auth.GetPlayer <PlayerEntity>().email ); }
public void ItStoresAuthenticatedPlayer() { var player = new PlayerEntity { name = "John" }; player.Save(); Assert.IsNull( Session.Get <string>(AuthenticationManager.SessionKey) ); OnFacet <AuthenticationFacet> .CallSync( nameof(AuthenticationFacet.Login), "John" ); Assert.AreEqual( player.EntityId, Session.Get <string>(AuthenticationManager.SessionKey) ); }
// buy gems for real money public void BuyGems() { // this is just a sketch, // the actual implementation (verification) will most likely differ iapController.BuySmallGems() .Then(receiptId => { // call server facet to // - verify receipt // - increment gem count OnFacet <PlayerFacet> .Call <PlayerEntity>( "PlayerHasBoughtSmallGems", receiptId ) .Then((entity) => { Debug.Log("Exchange finished."); }) .Done(); }) .Done(); }
public void LoginUpdatesTimestamp() { var player = new PlayerEntity { email = "*****@*****.**", password = Hash.Make("secret") }; player.Save(); OnFacet <EmailLoginFacet> .CallSync <bool>( nameof(EmailLoginFacet.Login), "*****@*****.**", "secret" ); var timeBefore = player.lastLoginAt; player.Refresh(); var timeNow = player.lastLoginAt; Assert.AreNotEqual(timeBefore, timeNow); }
private async void RegisterButtonClicked() { if (passwordInputField.text != passwordRepeatInputField.text) { RegistrationFailed("Passwords don't match."); return; } var result = await OnFacet <AuthFacet> .CallAsync <AuthFacet.RegistrationResult>( nameof(AuthFacet.Register), emailInputField.text, passwordInputField.text ); switch (result) { case AuthFacet.RegistrationResult.Ok: RegistrationSucceeded(); break; case AuthFacet.RegistrationResult.EmailTaken: RegistrationFailed("Email is already registered."); break; case AuthFacet.RegistrationResult.InvalidEmail: RegistrationFailed("Provided email is not valid."); break; case AuthFacet.RegistrationResult.WeakPassword: RegistrationFailed("Provided password is too weak."); break; default: RegistrationFailed("Unknown error."); break; } }
public void ItRunsMiddlewareAsProperlyDefined() { FacetWithMiddleware.middlewareLog = null; OnFacet <FacetWithMiddleware> .CallSync( nameof(FacetWithMiddleware.MethodWithoutMiddleware) ); Assert.AreEqual( "C1,C2,B2,C2',C1'", FacetWithMiddleware.middlewareLog ); FacetWithMiddleware.middlewareLog = null; OnFacet <FacetWithMiddleware> .CallSync( nameof(FacetWithMiddleware.MethodWithMiddleware) ); Assert.AreEqual( "C1,C2,M1,M2,B1,M2',M1',C2',C1'", FacetWithMiddleware.middlewareLog ); }
public void ItPreservesAuthenticatedUserFromTestCase() { var player = new PlayerEntity { name = "John" }; player.Save(); GenerateSessionId(); ActingAs(player); var returned = OnFacet <AuthenticationFacet> .CallSync <PlayerEntity>( nameof(AuthenticationFacet.GetPlayer) ); Assert.AreEqual(player.EntityId, returned?.EntityId); ActingAs(null); returned = OnFacet <AuthenticationFacet> .CallSync <PlayerEntity>( nameof(AuthenticationFacet.GetPlayer) ); Assert.IsNull(returned); }
/// <summary> /// Call this to perform player login via Steam /// </summary> public async void LoginViaSteam() { // already waiting for a ticket if (ticketPromise != null) { return; } // get a ticket (string ticket, HAuthTicket handle) = await GetSessionTicketAsync(); // send it to backend to resolve the ticket into Steam ID and login await OnFacet <SteamLoginFacet> .CallAsync( nameof(SteamLoginFacet.Login), ticket ); // we don't need the ticket anymore SteamUser.CancelAuthTicket(handle); // load the next scene SceneManager.LoadScene(sceneAfterLogin); }
public IEnumerator ItRemembersValuesBetweenRequests() { yield return(OnFacet <SessionFacet> .Call <JsonObject>( nameof(SessionFacet.GetSessionRecord) ).Then(r => { Assert.IsNull(r); }).AsCoroutine()); yield return(OnFacet <SessionFacet> .Call <Vector3>( nameof(SessionFacet.Get), "foo", Vector3.zero ).Then(v => { Assert.AreEqual(Vector3.zero, v); }).AsCoroutine()); yield return(OnFacet <SessionFacet> .Call( nameof(SessionFacet.Set), "foo", Vector3.up ).AsCoroutine()); yield return(OnFacet <SessionFacet> .Call <Vector3>( nameof(SessionFacet.Get), "foo", Vector3.zero ).Then(v => { Assert.AreEqual(Vector3.up, v); }).AsCoroutine()); yield return(OnFacet <SessionFacet> .Call <JsonObject>( nameof(SessionFacet.GetSessionRecord) ).Then(r => { Assert.IsNotNull(r); }).AsCoroutine()); }
public void ItLoadsAuthenticatedPlayer() { var player = new PlayerEntity { name = "John" }; player.Save(); GenerateSessionId(); Session.Set(AuthenticationManager.SessionKey, player.EntityId); // HACK TO STORE THE UPDATED SESSION: // I need to figure out how to properly merge test facade access // with middleware logic so that it does not interfere. App.Resolve <ISession>().StoreSession( ClientApp.Resolve <ClientSessionIdRepository>().GetSessionId() ); var returned = OnFacet <AuthenticationFacet> .CallSync <PlayerEntity>( nameof(AuthenticationFacet.GetPlayer) ); Assert.AreEqual("John", returned?.name); }
public IEnumerator ItCanSubscribeToAChannelAndReceiveAMessage() { CreateClient(ChannelParameterOne); yield return(WaitForClientToSettle()); Assert.IsEmpty(client.receivedMessages); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterOne, "Hello world!" ).AsCoroutine()); yield return(WaitForMessages(1)); Assert.AreEqual(1, client.receivedMessages.Count); Assert.IsInstanceOf <MyMessage>(client.receivedMessages[0]); Assert.AreEqual( "Hello world!", ((MyMessage)client.receivedMessages[0]).foo ); yield return(null); }
public IEnumerator ItDoesntReceiveMessagesAfterUnsubscribing() { CreateClient(ChannelParameterOne); yield return(WaitForClientToSettle()); Assert.IsEmpty(client.receivedMessages); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterOne, "Hello world!" ).AsCoroutine()); yield return(WaitForMessages(1)); // disable --> unsubscribes client.gameObject.SetActive(false); // clear log client.receivedMessages.Clear(); // send a message yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterOne, "Hello world!" ).AsCoroutine()); // wait a sec. yield return(new WaitForSeconds(1f)); // nothing Assert.IsEmpty(client.receivedMessages); yield return(null); }