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");
        }
        public void ApolloClientSubscriptionEventReceived_PropertyCheck()
        {
            var router = new Mock <ISubscriptionEventRouter>();
            var server = new ApolloSubscriptionServer <GraphSchema>(
                new GraphSchema(),
                new SubscriptionServerOptions <GraphSchema>(),
                router.Object);

            var connection = new Mock <IClientConnection>();
            var proxy      = new ApolloClientProxy <GraphSchema>(
                connection.Object,
                new SubscriptionServerOptions <GraphSchema>(),
                new AspNet.Apollo.Messages.Converters.ApolloMessageConverterFactory());

            var sub = new Mock <ISubscription>();

            sub.Setup(x => x.Id).Returns("sub1");

            var subs = new List <ISubscription>();

            subs.Add(sub.Object);

            var fieldPath = new GraphFieldPath("[subscription]/bob1");

            var entry = new ApolloClientSubscriptionEventReceived <GraphSchema>(
                proxy,
                fieldPath,
                subs);

            Assert.AreEqual(proxy.Id, entry.ClientId);
            Assert.AreEqual(fieldPath.ToString(), entry.SubscriptionRoute);
            Assert.AreEqual(1, entry.SubscriptionCount);
            CollectionAssert.AreEquivalent(subs.Select(x => x.Id).ToList(), entry.SubscriptionIds);
            Assert.AreNotEqual(entry.GetType().Name, entry.ToString());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApolloClientSubscriptionEventReceived{TSchema}" /> class.
 /// </summary>
 /// <param name="client">The client proxy that received the event.</param>
 /// <param name="fieldPath">The field path of the event recieved.</param>
 /// <param name="subscriptionsToReceive">The filtered set of subscriptions for this client
 /// that will receive the event.</param>
 public ApolloClientSubscriptionEventReceived(
     ApolloClientProxy <TSchema> client,
     GraphFieldPath fieldPath,
     IReadOnlyList <ISubscription> subscriptionsToReceive)
     : base(ApolloLogEventIds.ClientSubscriptionEventRecieved)
 {
     this.SchemaTypeName    = typeof(TSchema).FriendlyName(true);
     this.SubscriptionRoute = fieldPath.Path;
     this.SubscriptionCount = subscriptionsToReceive.Count;
     this.SubscriptionIds   = subscriptionsToReceive.Select(x => x.Id).ToList();
     this.ClientId          = client.Id;
 }
        public void ApolloServerSubscriptionEventReceived_PropertyCheck()
        {
            var router = new Mock <ISubscriptionEventRouter>();
            var server = new ApolloSubscriptionServer <GraphSchema>(
                new GraphSchema(),
                new SubscriptionServerOptions <GraphSchema>(),
                router.Object);

            var eventData = new SubscriptionEvent()
            {
                Id             = "id1",
                SchemaTypeName = "schema1",
                EventName      = "event1",
                DataTypeName   = "data1",
                Data           = new object(),
            };

            var connection = new Mock <IClientConnection>();
            var proxy      = new ApolloClientProxy <GraphSchema>(
                connection.Object,
                new SubscriptionServerOptions <GraphSchema>(),
                new AspNet.Apollo.Messages.Converters.ApolloMessageConverterFactory());

            var clients = new List <ApolloClientProxy <GraphSchema> >();

            clients.Add(proxy);

            var entry = new ApolloServerSubscriptionEventReceived <GraphSchema>(
                server,
                eventData,
                clients);

            Assert.AreEqual(eventData.SchemaTypeName, entry.SchemaTypeName);
            Assert.AreEqual(eventData.EventName, entry.SubscriptionEventName);
            Assert.AreEqual(1, entry.ClientCount);
            Assert.AreEqual("id1", entry.SubscriptionEventId);
            CollectionAssert.AreEquivalent(clients.Select(x => x.Id).ToList(), entry.ClientIds);
            Assert.AreEqual(server.Id, entry.ServerId);
            Assert.AreNotEqual(entry.GetType().Name, entry.ToString());
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApolloClientEventLogger{TSchema}" /> class.
 /// </summary>
 /// <param name="client">The client being logged.</param>
 /// <param name="logger">The root graph logger to send apollo events to.</param>
 public ApolloClientEventLogger(ApolloClientProxy <TSchema> client, IGraphEventLogger logger)
 {
     _client = Validation.ThrowIfNullOrReturn(client, nameof(client));
     _logger = Validation.ThrowIfNullOrReturn(logger, nameof(logger));
 }