public IEnumerator ItUpdatesSessionExpirationWithEveryRequest() { yield return(OnFacet <SessionFacet> .Call( nameof(SessionFacet.Set), "foo", Vector3.up ).AsCoroutine()); string oldSessionExpiration = null; yield return(OnFacet <SessionFacet> .Call <JsonObject>( nameof(SessionFacet.GetSessionRecord) ).Then(r => { oldSessionExpiration = r["expiresAt"].AsString; }).AsCoroutine()); yield return(OnFacet <SessionFacet> .Call( nameof(SessionFacet.EmptyFacetMethod) ).AsCoroutine()); yield return(OnFacet <SessionFacet> .Call <JsonObject>( nameof(SessionFacet.GetSessionRecord) ).Then(r => { Assert.AreNotEqual( oldSessionExpiration, r["expiresAt"].AsString ); }).AsCoroutine()); }
public IEnumerator JohnCanLogIn() { yield return(OnFacet <AuthenticationFacet> .Call( nameof(AuthenticationFacet.Login), "John" ).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call <PlayerEntity>( nameof(AuthenticationFacet.GetPlayer) ).Then(p => { Assert.AreEqual("John", p.name); }).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call <bool>( nameof(AuthenticationFacet.Check) ).Then(c => { Assert.IsTrue(c); }).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call <string>( nameof(AuthenticationFacet.Id) ).Then(id => { Assert.IsNotNull(id); }).AsCoroutine()); }
public IEnumerator JsonCanBeSentCorrectlyThroughPhp() { yield return(OnFacet <FcFacet> .Call <JsonValue>( nameof(FcFacet.JsonTest), new JsonObject() ) .Then(json => { Assert.AreEqual("{}", json.ToString()); }) .AsCoroutine()); yield return(OnFacet <FcFacet> .Call <JsonValue>( nameof(FcFacet.JsonTest), new JsonArray() ) .Then(json => { Assert.AreEqual("[]", json.ToString()); }) .AsCoroutine()); yield return(OnFacet <FcFacet> .Call <JsonValue>( nameof(FcFacet.JsonTest), new object[] { null } // "null" would be an object[], not object ) .Then(json => { Assert.AreEqual("null", json.ToString()); }) .AsCoroutine()); }
public IEnumerator JohnCanLogOut() { yield return(OnFacet <AuthenticationFacet> .Call( nameof(AuthenticationFacet.Login), "John" ).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call( nameof(AuthenticationFacet.Logout) ).AsCoroutine()); 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 IEnumerator ItDoesntReceiveMessageForDifferentChannel() { CreateClient(ChannelParameterOne); yield return(WaitForClientToSettle()); Assert.IsEmpty(client.receivedMessages); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterTwo, // TWO "Send to another channel" ).AsCoroutine()); // send one message afterwards for which we can wait yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), ChannelParameterOne, "Hello world!" ).AsCoroutine()); // wait for the one message yield return(WaitForMessages(1)); // and check it's the hello-world one 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 CriticalCanBeLogged() { LogAssert.ignoreFailingMessages = true; yield return(OnFacet <LogFacet> .Call( nameof(LogFacet.LogCritical) ).AsCoroutine()); }
public IEnumerator DebugLogExceptionCanBeUsed() { LogAssert.ignoreFailingMessages = true; yield return(OnFacet <LogFacet> .Call( nameof(LogFacet.DebugLogException) ).AsCoroutine()); }
public IEnumerator ItReceivesLostEventsOnReconnection() { /* * Send a message, * simulate a drop by decrementing lastEventId and * disabling/enabling the SSE socket. * Assert the last message was received again. */ CreateClient(); yield return(WaitForClientToSettle()); Assert.IsEmpty(client.receivedMessages); yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), "foo", "Hello world!" ).AsCoroutine()); yield return(WaitForMessages(1)); var tunnel = ClientFacade.ClientApp .Resolve <ClientBroadcastingManager>() .Tunnel; var idOfLastActuallyReceived = tunnel.Socket.lastReceivedEventId; Assert.AreEqual(1, client.receivedMessages.Count); Assert.IsInstanceOf <MyMessage>(client.receivedMessages[0]); Assert.AreEqual( "Hello world!", ((MyMessage)client.receivedMessages[0]).foo ); // simulate drop tunnel.Socket.gameObject.SetActive(false); yield return(null); // repeat the last message only tunnel.Socket.lastReceivedEventId = idOfLastActuallyReceived - 1; tunnel.Socket.gameObject.SetActive(true); // wait for the re-sending yield return(WaitForMessages(2)); Assert.AreEqual(2, client.receivedMessages.Count); Assert.IsInstanceOf <MyMessage>(client.receivedMessages[1]); Assert.AreEqual( "Hello world!", ((MyMessage)client.receivedMessages[1]).foo ); yield return(null); }
public IEnumerator GuardedMethodThrowsIfNotLoggedIn() { yield return(OnFacet <AuthenticationFacet> .Call( nameof(AuthenticationFacet.GuardedMethod) ).Then(() => { Assert.Fail("Exception wasn't thrown."); }).Catch(e => { Assert.IsInstanceOf <AuthException>(e); }).AsCoroutine()); }
public IEnumerator GuardedMethodWorksIfLoggedIn() { yield return(OnFacet <AuthenticationFacet> .Call( nameof(AuthenticationFacet.Login), "John" ).AsCoroutine()); yield return(OnFacet <AuthenticationFacet> .Call( nameof(AuthenticationFacet.GuardedMethod) ).AsCoroutine()); }
public IEnumerator ItCanDeserializeResults() { yield return(OnFacet <RawAqlFacet> .Call <Vector3>( nameof(RawAqlFacet.FirstAsVector), @" RETURN { x: 1, y: 2, z: 3 } " ).Then(v => { Assert.AreEqual(1, v.x); Assert.AreEqual(2, v.y); Assert.AreEqual(3, v.z); }).AsCoroutine()); }
public IEnumerator SetUp() { yield return(OnFacet <FullstackUtilsFacet> .Call( nameof(FullstackUtilsFacet.ClearDatabase) ).AsCoroutine()); yield return(OnFacet <SupportFacet> .Call( nameof(SupportFacet.CreatePlayer), new PlayerEntity { name = "John" } ).AsCoroutine()); }
public IEnumerator DebugLogWarningCanBeUsed() { LogAssert.Expect( LogType.Warning, new Regex( @"Hello world!", RegexOptions.Multiline ) ); yield return(OnFacet <LogFacet> .Call( nameof(LogFacet.DebugLogWarning) ).AsCoroutine()); }
public IEnumerator WarningCanBeLogged() { LogAssert.Expect( LogType.Warning, new Regex( @"SERVER\.WARNING.*Hello world![\s\S]*Context: 42", RegexOptions.Multiline ) ); yield return(OnFacet <LogFacet> .Call( nameof(LogFacet.LogWarning) ).AsCoroutine()); }
public IEnumerator ItCallsNetworkConnectivityHooks() { CreateClient(); yield return(WaitForClientToSettle()); Assert.False(client.onConnectionLostCalled); Assert.False(client.onConnectionRegainedCalled); // check connection is made yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), "foo", "Hello world!" ).AsCoroutine()); yield return(WaitForMessages(1)); var tunnel = ClientFacade.ClientApp .Resolve <ClientBroadcastingManager>() .Tunnel; // drop connection tunnel.Socket.retryMilliseconds = 500; // retry in 0.5s tunnel.Socket.RunningRequest.Abort(); while (tunnel.Socket.RunningRequest != null) { yield return(null); } Assert.True(client.onConnectionLostCalled); Assert.False(client.onConnectionRegainedCalled); client.onConnectionLostCalled = false; // wait for reconnect (by sending and waiting for a message) yield return(OnFacet <BroadcastingFacet> .Call( nameof(BroadcastingFacet.SendMyMessage), "foo", "Hello world!" ).AsCoroutine()); yield return(WaitForMessages(2)); // check the callback was called Assert.False(client.onConnectionLostCalled); Assert.True(client.onConnectionRegainedCalled); }
public IEnumerator ItCanReturnResults() { yield return(OnFacet <RawAqlFacet> .Call <List <JsonValue> >( nameof(RawAqlFacet.Get), @" FOR i IN 1..4 RETURN i ", null ).Then(results => { Assert.AreEqual( "[1,2,3,4]".Replace('\'', '"'), Serializer.ToJson(results).ToString() ); }).AsCoroutine()); }
public IEnumerator VoidFacetMethodCanThrowException() { string message = "Lorem ipsum dolor sit..."; yield return(OnFacet <FcFacet> .Call( nameof(FcFacet.VoidFacetThatThrows), message ) .Then(() => { Assert.Fail("Method has not thrown an exception."); }) .Catch(e => { Assert.AreEqual(message, e.Message); }) .AsCoroutine()); }
public IEnumerator CriticalCanBeLogged() { LogAssert.ignoreFailingMessages = true; LogAssert.Expect( LogType.Error, new Regex( @"SERVER\.CRITICAL.*Hello world![\s\S]*Context: 42", RegexOptions.Multiline ) ); yield return(OnFacet <LogFacet> .Call( nameof(LogFacet.LogCritical) ).AsCoroutine()); }
public IEnumerator DebugLogExceptionCanBeUsed() { LogAssert.ignoreFailingMessages = true; LogAssert.Expect( LogType.Error, new Regex( @"Some exception.", RegexOptions.Multiline ) ); yield return(OnFacet <LogFacet> .Call( nameof(LogFacet.DebugLogException) ).AsCoroutine()); }
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 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 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()); }
// 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 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 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); }
public IEnumerator VoidFacetMethodCanBeCalled() { yield return(OnFacet <FcFacet> .Call( nameof(FcFacet.VoidFacet) ).AsCoroutine()); }
public IEnumerator EntityCanBeFoundByEnumAttribute() { yield return(OnFacet <SeoFacet> .Call( nameof(SeoFacet.EntityCanBeFoundByEnumAttribute) ).AsCoroutine()); }
public IEnumerator EntityCanBeCreatedQueriedAndDeleted() { yield return(OnFacet <SeoFacet> .Call( nameof(SeoFacet.EntityCanBeCreatedQueriedAndDeleted) ).AsCoroutine()); }