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="ApolloServerEventMonitorEndedLogEntry{TSchema}" /> class. /// </summary> /// <param name="server">The server that registered with the listener.</param> /// <param name="eventName">Name of the event that is no longer being monitored.</param> public ApolloServerEventMonitorEndedLogEntry( ApolloSubscriptionServer <TSchema> server, SubscriptionEventName eventName) : base(ApolloLogEventIds.ServerSubscriptionEventMonitorStarted) { _schemaTypeShortName = typeof(TSchema).FriendlyName(); this.SchemaTypeName = typeof(TSchema).FriendlyName(true); this.SubscriptionEventName = eventName.ToString(); this.ServerId = server.Id; }
/// <summary> /// Creates the apollo subscription server and logs its creation. /// </summary> /// <param name="sp">The service provider to create the server from.</param> /// <returns>ISubscriptionServer<TSchema>.</returns> private ISubscriptionServer <TSchema> CreateSubscriptionServer(IServiceProvider sp) { using var scope = sp.CreateScope(); var schema = scope.ServiceProvider.GetRequiredService <TSchema>(); var eventListener = scope.ServiceProvider.GetRequiredService <ISubscriptionEventRouter>(); var logger = scope.ServiceProvider.GetService <IGraphEventLogger>(); var server = new ApolloSubscriptionServer <TSchema>(schema, this.SubscriptionOptions, eventListener, logger); logger?.SubscriptionServerCreated(server); return(server); }
/// <summary> /// Initializes a new instance of the <see cref="ApolloServerSubscriptionEventReceived{TSchema}" /> class. /// </summary> /// <param name="server">The server instance that received the event.</param> /// <param name="eventRecieved">The event that was recieved from the global listener.</param> /// <param name="clientsToReceive">The filtered list of clients that will receive the event /// from the server.</param> public ApolloServerSubscriptionEventReceived( ApolloSubscriptionServer <TSchema> server, SubscriptionEvent eventRecieved, IReadOnlyList <ApolloClientProxy <TSchema> > clientsToReceive) : base(ApolloLogEventIds.ServerSubcriptionEventReceived) { this.SchemaTypeName = eventRecieved.SchemaTypeName; this.SubscriptionEventName = eventRecieved.EventName; this.SubscriptionEventId = eventRecieved.Id; this.ClientCount = clientsToReceive.Count; this.ServerId = server.Id; this.ClientIds = clientsToReceive.Select(x => x.Id).ToList(); }
public void ApolloEventMonitorStarted_PropertyCheck() { var router = new Mock <ISubscriptionEventRouter>(); var server = new ApolloSubscriptionServer <GraphSchema>( new GraphSchema(), new SubscriptionServerOptions <GraphSchema>(), router.Object); var eventName = new SubscriptionEventName("schema", "event"); var entry = new ApolloServerEventMonitorStartedLogEntry <GraphSchema>(server, eventName); Assert.AreEqual(typeof(GraphSchema).FriendlyName(true), entry.SchemaTypeName); Assert.AreEqual(eventName.ToString(), entry.SubscriptionEventName); Assert.AreEqual(server.Id, entry.ServerId); Assert.AreNotEqual(entry.GetType().Name, entry.ToString()); }
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()); }
/// <summary> /// Initializes a new instance of the <see cref="ApolloServerEventLogger{TSchema}" /> class. /// </summary> /// <param name="server">The server being logged.</param> /// <param name="logger">The root graph logger to send apollo events to.</param> public ApolloServerEventLogger(ApolloSubscriptionServer <TSchema> server, IGraphEventLogger logger) { _server = Validation.ThrowIfNullOrReturn(server, nameof(server)); _logger = Validation.ThrowIfNullOrReturn(logger, nameof(logger)); }