Esempio n. 1
0
        public override void OnBeforeCompleteName(ITypeCompletionContext context, DefinitionBase?definitionBase, IDictionary <string, object?> contextData)
        {
            if (definitionBase is not ObjectTypeDefinition definition)
            {
                return;
            }

            if (definition.RuntimeType.IsSubclassOf(typeof(BaseEntity)))
            {
                foreach (PropertyInfo property in definition.RuntimeType.GetProperties())
                {
                    if (property.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType) && property.PropertyType != typeof(NpgsqlTsVector))
                    {
                        ObjectFieldDefinition fieldDefinition = definition.Fields.First(e => e.Name == context.DescriptorContext.Naming.GetMemberName(property, MemberKind.ObjectField));
                        ObjectFieldDescriptor fieldDescriptor = ObjectFieldDescriptor.From(context.DescriptorContext, fieldDefinition);

                        fieldDescriptor
                        .UseSorting()
                        .UseFiltering();

                        int index = definition.Fields.IndexOf(fieldDefinition);
                        definition.Fields.RemoveAt(index);
                        definition.Fields.Insert(index, fieldDescriptor.CreateDefinition());
                    }
                }
            }
        }
Esempio n. 2
0
        public void UseSorting_WithoutTypeParam_ShouldRegisterPlaceholderMiddleware()
        {
            // arrange
            ObjectFieldDescriptor descriptor =
                ObjectFieldDescriptor.New(Context, "field");
            FieldMiddleware placeholder = next => context => default;

            // act
            descriptor.UseSorting <object>();

            // assert
            Assert.Single(descriptor.CreateDefinition().MiddlewareComponents);
        }
Esempio n. 3
0
        public void UseSorting_WithoutParams_ShouldRegisterPlaceholderMiddleware()
        {
            // arrange
            ObjectFieldDescriptor descriptor = ObjectFieldDescriptor.New(Context, "field");

            descriptor.Resolve("abc");

            // act
            descriptor.UseSorting();

            // assert
            Assert.Single(descriptor.CreateDefinition().MiddlewareComponents);
        }