public void EqualsMethodAgainstOtherAsObject_Matches() { var id = new SubscriptionEventName("schema", "abc"); var secondId = new SubscriptionEventName("schema", "abc"); Assert.IsTrue(id.Equals((object)secondId)); }
/// <summary> /// Attempts to generate a dictionary of value relating field path to the possible event names. /// </summary> /// <param name="schema">The schema.</param> /// <returns>Dictionary<System.String, GraphFieldPath>.</returns> public static Dictionary <SubscriptionEventName, GraphFieldPath> CreateEventMap(ISchema schema) { var dic = new Dictionary <SubscriptionEventName, GraphFieldPath>(SubscriptionEventNameEqualityComparer.Instance); if (schema == null || !schema.OperationTypes.ContainsKey(GraphCollection.Subscription)) { return(dic); } foreach (var field in schema.KnownTypes.OfType <IObjectGraphType>() .SelectMany(x => x.Fields.OfType <ISubscriptionGraphField>())) { var route = field.Route.Clone(); foreach (var eventName in SubscriptionEventName.FromGraphField(schema, field)) { if (dic.ContainsKey(eventName)) { var path = dic[eventName]; throw new DuplicateNameException( $"Duplciate Subscription Event Name. Unable to register the field '{route.Path}' " + $"with event name '{eventName}'. The schema '{schema.GetType().FriendlyName()}' already contains " + $"a field with the event name '{eventName}'. (Event Owner: {path.Path})."); } dic.Add(eventName, route); } } return(dic); }
public void EqualsMethodAgainstEvent_Matches() { var id = new SubscriptionEventName("schema", "abc"); var id2 = new SubscriptionEventName("schema", "abc"); Assert.IsTrue(id.Equals(id2)); }
private void ApolloClient_SubscriptionRouteRemoved(object sender, ApolloSubscriptionFieldEventArgs e) { var client = sender as ApolloClientProxy <TSchema>; if (client == null) { return; } var names = SubscriptionEventName.FromGraphField(_schema, e.Field); foreach (var name in names) { lock (_syncLock) { if (_subCountByName.TryGetValue(name, out var clients)) { if (clients.Contains(client)) { clients.Remove(client); if (clients.Count == 0) { _subCountByName.Remove(name); _eventRouter.RemoveReceiver(name, this); _logger?.EventMonitorEnded(name); } } } } } }
public void MapOfFieldWithEventName_RendersTwoItem() { using var restorePoint = new GraphQLProviderRestorePoint(); SchemaSubscriptionEventMap.ClearCache(); var schema = new TestServerBuilder <EventMapSchema>() .AddSubscriptionServer() .AddGraphController <OneFieldMapWithEventNameController>() .Build() .Schema; var map = SchemaSubscriptionEventMap.CreateEventMap(schema); var pathName = "[subscription]/OneFieldMapWithEventName/TestActionMethod"; var pathEventName = new SubscriptionEventName(typeof(EventMapSchema), pathName); var eventName = new SubscriptionEventName(typeof(EventMapSchema), "shortTestName"); Assert.AreEqual(2, map.Count); Assert.IsTrue(map.ContainsKey(eventName)); Assert.IsNotNull(map[eventName]); Assert.AreEqual(pathName, map[eventName].Path); Assert.IsTrue(map.ContainsKey(eventName)); Assert.IsNotNull(map[eventName]); Assert.AreEqual(pathName, map[eventName].Path); // ensure both items reference the same object Assert.AreSame(map[pathEventName], map[eventName]); }
private void ApolloClient_SubscriptionRouteAdded(object sender, ApolloSubscriptionFieldEventArgs e) { var client = sender as ApolloClientProxy <TSchema>; if (client == null) { return; } var names = SubscriptionEventName.FromGraphField(_schema, e.Field); foreach (var name in names) { lock (_syncLock) { if (!_subCountByName.ContainsKey(name)) { _subCountByName.Add(name, new HashSet <ApolloClientProxy <TSchema> >()); } _subCountByName[name].Add(client); if (_subCountByName[name].Count == 1) { _eventRouter.AddReceiver(name, this); _logger?.EventMonitorStarted(name); } } } }
public void GeneralPropertyCheck() { var id = new SubscriptionEventName("schema", "abc"); Assert.AreEqual("schema:abc", id.ToString()); Assert.AreEqual("schema:abc".GetHashCode(), id.GetHashCode()); }
public void NotEqualsOperator_AgainstObject(string schema1, string value1, object value2, bool isSuccess) { var id1 = new SubscriptionEventName(schema1, value1); Assert.AreEqual(isSuccess, id1 != value2); Assert.AreEqual(isSuccess, value2 != id1); }
public void NotEqualsOperatorAgainstSelf_IsFalse() { var id = new SubscriptionEventName("schema", "123"); #pragma warning disable CS1718 // Comparison made to same variable Assert.IsFalse(id != id); #pragma warning restore CS1718 // Comparison made to same variable }
public void GeneralPropertyCheck_FromType() { var schema = new GraphSchema(); var id = new SubscriptionEventName(typeof(GraphSchema), "abc"); Assert.AreEqual($"{schema.FullyQualifiedSchemaTypeName()}:abc", id.ToString()); Assert.AreEqual($"{schema.FullyQualifiedSchemaTypeName()}:abc".GetHashCode(), id.GetHashCode()); }
public void NotEqualsOperator(string schema1, string value1, string schema2, string value2, bool isSuccess) { var id1 = new SubscriptionEventName(schema1, value1); var id2 = new SubscriptionEventName(schema2, value2); Assert.AreEqual(isSuccess, id1 != id2); Assert.AreEqual(isSuccess, id2 != id1); }
public void EqualsMethodAgainstNonString_DoesNotMatch() { var id = new SubscriptionEventName("schema", "abc"); var idValue = (object)123; Assert.IsFalse(id.Equals(idValue)); }
public void EqualsMethodAgainstStringObject_Matches() { var id = new SubscriptionEventName("schema", "abc"); var obj = (object)"schema:abc"; Assert.IsTrue(id.Equals(obj)); }
public void EqualsOperatorAgainstSelf_IsTrue() { var id = new SubscriptionEventName("schema", "123"); // ReSharper disable once EqualExpressionComparison #pragma warning disable CS1718 // Comparison made to same variable Assert.IsTrue(id == id); #pragma warning restore CS1718 // Comparison made to same variable }
/// <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; }
public void ShouldThrow(string schema1, string value1) { try { var id = new SubscriptionEventName(schema1, value1); } catch { return; } Assert.Fail("expected constructor exception"); }
public void UnPack(string packedValue, string schema, string value = null) { var result = SubscriptionEventName.UnPack(packedValue); if (schema == null) { Assert.IsNull(result); } else { Assert.AreEqual(new SubscriptionEventName(schema, value), result); } }
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 RetrieveFieldPathByName_YieldsCorrectPath() { using var restorePoint = new GraphQLProviderRestorePoint(); SchemaSubscriptionEventMap.ClearCache(); var schema = new TestServerBuilder <EventMapSchema>() .AddSubscriptionServer() .AddGraphController <OneFieldMapController>() .Build() .Schema; var map = SchemaSubscriptionEventMap.CreateEventMap(schema); var pathName = "[subscription]/OneFieldMap/TestActionMethod"; var eventName = new SubscriptionEventName(typeof(EventMapSchema), pathName); var fieldPath = schema.RetrieveSubscriptionFieldPath(eventName); Assert.IsNotNull(fieldPath); Assert.AreEqual(pathName, fieldPath.Path); }
public void MapOfFieldWithNoEventName_RendersOneItem() { using var restorePoint = new GraphQLProviderRestorePoint(); SchemaSubscriptionEventMap.ClearCache(); var schema = new TestServerBuilder <EventMapSchema>() .AddSubscriptionServer() .AddGraphController <OneFieldMapController>() .Build() .Schema; var map = SchemaSubscriptionEventMap.CreateEventMap(schema); var pathName = "[subscription]/OneFieldMap/TestActionMethod"; var eventName = new SubscriptionEventName(typeof(EventMapSchema), pathName); Assert.AreEqual(1, map.Count); Assert.IsTrue(map.ContainsKey(eventName)); Assert.IsNotNull(map[eventName]); Assert.AreEqual(pathName, map[eventName].Path); }
/// <summary> /// Recorded when an Apollo server component unregistered a subscription event on the configured /// listener for this ASP.NET server instance. This log entry is recorded when the last connected client /// stops its last subscription for a given event. /// </summary> /// <param name="eventName">Name of the event that is no longer being monitored.</param> public void EventMonitorEnded(SubscriptionEventName eventName) { _logger.Log( LogLevel.Trace, () => new ApolloServerEventMonitorEndedLogEntry <TSchema>(_server, eventName)); }
/// <summary> /// Attempts to find the fully qualifed <see cref="GraphFieldPath"/> that is pointed at by the supplied event name. /// </summary> /// <param name="schema">The schema.</param> /// <param name="eventName">The short or long name of the event.</param> /// <returns>System.String.</returns> public static GraphFieldPath RetrieveSubscriptionFieldPath(this ISchema schema, SubscriptionEventName eventName) { Validation.ThrowIfNull(schema, nameof(schema)); Validation.ThrowIfNull(eventName, nameof(eventName)); if (eventName.OwnerSchemaType != schema.FullyQualifiedSchemaTypeName()) { return(null); } if (NAME_CATALOG.TryGetValue(eventName, out var routePath)) { return(routePath); } // attempt to load the schema into the cache in case it wasnt before if (PreLoadSubscriptionEventNames(schema)) { if (NAME_CATALOG.TryGetValue(eventName, out routePath)) { return(routePath); } } return(null); }
public void EqualsMethodAgainstSelfAsObject_Matches() { var id = new SubscriptionEventName("schema", "abc"); Assert.IsTrue(id.Equals((object)id)); }
public void EqualsMethodAgainstNullAsEvent_DoesNotMatch() { var id = new SubscriptionEventName("schema", "abc"); Assert.IsFalse(id.Equals(null as SubscriptionEventName)); }