Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public IEnumerator CriticalCanBeLogged()
        {
            LogAssert.ignoreFailingMessages = true;

            yield return(OnFacet <LogFacet> .Call(
                             nameof(LogFacet.LogCritical)
                             ).AsCoroutine());
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 9
0
 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());
 }
Exemplo n.º 10
0
        public IEnumerator GuardedMethodWorksIfLoggedIn()
        {
            yield return(OnFacet <AuthenticationFacet> .Call(
                             nameof(AuthenticationFacet.Login),
                             "John"
                             ).AsCoroutine());

            yield return(OnFacet <AuthenticationFacet> .Call(
                             nameof(AuthenticationFacet.GuardedMethod)
                             ).AsCoroutine());
        }
Exemplo n.º 11
0
 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());
 }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        public IEnumerator DebugLogWarningCanBeUsed()
        {
            LogAssert.Expect(
                LogType.Warning,
                new Regex(
                    @"Hello world!",
                    RegexOptions.Multiline
                    )
                );

            yield return(OnFacet <LogFacet> .Call(
                             nameof(LogFacet.DebugLogWarning)
                             ).AsCoroutine());
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 16
0
 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());
 }
Exemplo n.º 17
0
        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());
        }
Exemplo n.º 18
0
        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());
        }
Exemplo n.º 19
0
        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());
        }
Exemplo n.º 20
0
        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();
            });
        }
Exemplo n.º 21
0
 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());
 }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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();
        }
Exemplo n.º 25
0
        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());
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
 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());
 }