public async Task StartConnection_OnReadClose_IfConnectionIsOpen_CloseConnection()
        {
            // set the underlying connection to not auto close when it retrieves a close message
            // from the queue, leaving it up to the apollo client to do the close
            var socketClient = new MockClientConnection(autoCloseOnReadCloseMessage: false);
            var options      = new SubscriptionServerOptions <GraphSchema>();

            var provider     = new ServiceCollection().BuildServiceProvider();
            var apolloClient = new ApolloClientProxy <GraphSchema>(
                socketClient,
                options,
                new ApolloMessageConverterFactory(),
                null,
                false);

            var eventCalled = false;

            void ConnectionClosed(object sender, EventArgs e)
            {
                eventCalled = true;
            }

            apolloClient.ConnectionClosed += ConnectionClosed;

            // execute the connection sequence
            socketClient.QueueConnectionCloseMessage();
            await apolloClient.StartConnection();

            Assert.IsTrue(eventCalled, "Connection Closed Event Handler not called");
        }
 /// <summary>
 /// Asserts that a response message from the server queued and that it is of the supplied type.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="type">The type of message to check for.</param>
 /// <param name="dequeue">if true, the message is removed from the queue.</param>
 internal static void AssertApolloResponse(
     this MockClientConnection connection,
     ApolloMessageType type,
     bool dequeue = true)
 {
     AssertApolloResponse(connection, type, null, false, null, false, dequeue);
 }
 /// <summary>
 /// Asserts that the next message on the received queue is a DATA message and that the payload
 /// matches the provided json string.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="type">The expected type of the message.</param>
 /// <param name="id">The expected identifier of the subscription that rendered the data.</param>
 /// <param name="expectedPayloadJson">The expected payload of the message, converted to a json string.</param>
 /// <param name="dequeue">if set to <c>true</c> if the message should be removed from the queue.</param>
 internal static void AssertApolloResponse(
     this MockClientConnection connection,
     ApolloMessageType type,
     string id,
     string expectedPayloadJson,
     bool dequeue = true)
 {
     AssertApolloResponse(connection, type, id, true, expectedPayloadJson, true, dequeue);
 }
Exemple #4
0
            public IMessageEndpointConnection CreateConnection(MessageEndpoint endpoint)
            {
                var retVal =
                    new MockClientConnection(endpoint)
                {
                    ErrorLogic = _errorLogic,
                };

                return(retVal);
            }
        public void Setup()
        {
            user    = new UserInfo("Nickname", "Phonetic", "Username", 1, 2, true);
            manager = new ServerUserManager();

            provider = new MockConnectionProvider(GablarskiProtocol.Instance);
            provider.Start(MessageTypes.All);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);

            server = cs.Item2;
            client = cs.Item1;
        }
Exemple #6
0
        private void connectAndJoinRoom()
        {
            mockClientConnection = new MockClientConnection();
            mockClientConnection.SendEventBehaviourHandler             = sendEventBehaviourHandler;
            mockClientConnection.SendOperationResponseBehaviourHandler = sendOperationResponseBehaviourHandler;

            instanceServerApplication.ListenForClientJoinRoomRequest(mockClientConnection);

            // Step 1. Fake join room request
            Task.Delay(100).ContinueWith(t => {
                Core.Logging.Log.Info("---- Mock client " + mockClientConnection.ConnectionId + " sending JoinRoomOpRequest.");
                mockClientConnection.OnOperationRequest(
                    new JoinRoomOpRequest(Mocking.Net.Services.Session.MockSessionService.VALID_SESSION_ID,
                                          "testRoom", "testPassword").ToOperationRequest(), new SendParameters());
            });
        }
        private static void AssertApolloResponse(
            this MockClientConnection connection,
            ApolloMessageType type,
            string id,
            bool compareId,
            string expectedPayloadJson,
            bool compareJson,
            bool dequeue = true)
        {
            if (connection.ResponseMessageCount == 0)
            {
                Assert.Fail("No messages queued.");
            }

            var message = dequeue ? connection.DequeueNextReceivedMessage() : connection.PeekNextReceivedMessage();
            var str     = Encoding.UTF8.GetString(message.Data);

            var options = new JsonSerializerOptions();

            options.PropertyNameCaseInsensitive = true;
            options.AllowTrailingCommas         = true;
            options.Converters.Add(new ApolloResponseMessageConverter());

            var convertedMessage = System.Text.Json.JsonSerializer.Deserialize <ApolloResponseMessage>(str, options);

            Assert.IsNotNull(convertedMessage, "Could not deserialized response message");
            Assert.AreEqual(type, convertedMessage.Type, $"Expected message type of {type.ToString()} but got {convertedMessage.Type.ToString()}");

            if (compareJson)
            {
                if (expectedPayloadJson == null)
                {
                    Assert.IsNull(convertedMessage.Payload);
                }
                else
                {
                    CommonAssertions.AreEqualJsonStrings(expectedPayloadJson, convertedMessage.Payload);
                }
            }

            if (compareId)
            {
                Assert.AreEqual(id, convertedMessage.Id);
            }
        }
        public void Setup()
        {
            var provider = new MockConnectionProvider(SocialProtocol.Instance);

            provider.ConnectionMade += (sender, args) => server = new ConnectionBuffer(args.Connection);
            provider.Start(MessageTypes.Reliable);

            var c = new MockClientConnection(provider);

            client = new ConnectionBuffer(c);

            clientContext = new SerializationContext(c, new Dictionary <byte, Protocol> {
                { 2, SocialProtocol.Instance }
            });

            var context = new TempestClient(c, MessageTypes.Reliable);

            context.ConnectAsync(new Target(Target.LoopbackIP, 1)).Wait();

            list = new WatchList(context);
        }