Beispiel #1
0
        public async Task ShouldFilterPartsWithoutAPrefixWhenThePartHasNoPrefix()
        {
            _store.RegisterIndexes <AnimalIndexProvider>();

            using (var services = new FakeServiceCollection())
            {
                services.Populate(new ServiceCollection());
                services.Services.AddScoped(x => _store.CreateSession());
                services.Services.AddScoped(x => new ShellSettings());
                services.Services.AddScoped <IIndexProvider, ContentItemIndexProvider>();
                services.Services.AddScoped <IIndexProvider, AnimalIndexProvider>();
                services.Services.AddScoped <IIndexAliasProvider, MultipleAliasIndexProvider>();
                services.Build();

                var returnType = new ListGraphType <StringGraphType>();
                returnType.ResolvedType = new StringGraphType()
                {
                    Name = "Animal"
                };

                var animalWhereInput = new AnimalPartWhereInput();
                var inputs           = new FieldType {
                    Name = "Inputs", Arguments = new QueryArguments {
                        new QueryArgument <WhereInputObjectGraphType> {
                            Name = "where", Description = "filters the animals", ResolvedType = animalWhereInput
                        }
                    }
                };

                var context = new ResolveFieldContext
                {
                    Arguments   = new Dictionary <string, object>(),
                    UserContext = new GraphQLContext
                    {
                        ServiceProvider = services
                    },
                    ReturnType      = returnType,
                    FieldDefinition = inputs
                };

                var ci = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "1", ContentItemVersionId = "1"
                };
                ci.Weld(new AnimalPart {
                    Name = "doug"
                });

                var session = ((GraphQLContext)context.UserContext).ServiceProvider.GetService <ISession>();
                session.Save(ci);
                await session.CommitAsync();

                var type = new ContentItemsFieldType("Animal", new Schema());

                context.Arguments["where"] = JObject.Parse("{ animal: { name: \"doug\" } }");
                var dogs = await((AsyncFieldResolver <IEnumerable <ContentItem> >)type.Resolver).Resolve(context);

                Assert.Single(dogs);
                Assert.Equal("doug", dogs.First().As <AnimalPart>().Name);
            }
        }
Beispiel #2
0
        public async Task ShouldBeAbleToUseTheSameIndexForMultipleAliases()
        {
            _store.RegisterIndexes <AnimalIndexProvider>();

            using (var services = new FakeServiceCollection())
            {
                services.Populate(new ServiceCollection());
                services.Services.AddScoped(x => new ShellSettings());
                services.Services.AddScoped(x => _store.CreateSession());
                services.Services.AddScoped <IIndexProvider, ContentItemIndexProvider>();
                services.Services.AddScoped <IIndexProvider, AnimalIndexProvider>();
                services.Services.AddScoped <IIndexAliasProvider, MultipleAliasIndexProvider>();
                services.Services.AddSingleton <IIndexPropertyProvider, IndexPropertyProvider <AnimalIndex> >();

                services.Build();

                var retrunType = new ListGraphType <StringGraphType>();
                retrunType.ResolvedType = new StringGraphType()
                {
                    Name = "Animal"
                };

                var context = new ResolveFieldContext
                {
                    Arguments   = new Dictionary <string, object>(),
                    UserContext = new GraphQLContext
                    {
                        ServiceProvider = services
                    },
                    ReturnType = retrunType
                };

                var ci = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "1", ContentItemVersionId = "1"
                };
                ci.Weld(new Animal {
                    Name = "doug"
                });

                var session = ((GraphQLContext)context.UserContext).ServiceProvider.GetService <ISession>();
                session.Save(ci);
                await session.SaveChangesAsync();

                var type = new ContentItemsFieldType("Animal", new Schema(), Options.Create(new GraphQLContentOptions()), Options.Create(new GraphQLSettings {
                    DefaultNumberOfResults = 10
                }));

                context.Arguments["where"] = JObject.Parse("{ cats: { name: \"doug\" } }");
                var cats = await((LockedAsyncFieldResolver <IEnumerable <ContentItem> >)type.Resolver).Resolve(context);

                Assert.Single(cats);
                Assert.Equal("doug", cats.First().As <Animal>().Name);

                context.Arguments["where"] = JObject.Parse("{ dogs: { name: \"doug\" } }");
                var dogs = await((LockedAsyncFieldResolver <IEnumerable <ContentItem> >)type.Resolver).Resolve(context);

                Assert.Single(dogs);
                Assert.Equal("doug", dogs.First().As <Animal>().Name);
            }
        }
Beispiel #3
0
        public async Task ShouldFilterOnMultipleIndexesOnSameAlias()
        {
            _store.RegisterIndexes <AnimalIndexProvider>();
            _store.RegisterIndexes <AnimalTraitsIndexProvider>();

            using (var services = new FakeServiceCollection())
            {
                services.Populate(new ServiceCollection());
                services.Services.AddScoped(x => new ShellSettings());
                services.Services.AddScoped(x => _store.CreateSession());
                services.Services.AddScoped <IIndexProvider, ContentItemIndexProvider>();
                services.Services.AddScoped <IIndexProvider, AnimalIndexProvider>();
                services.Services.AddScoped <IIndexProvider, AnimalTraitsIndexProvider>();
                services.Services.AddScoped <IIndexAliasProvider, MultipleIndexesIndexProvider>();
                services.Build();

                var retrunType = new ListGraphType <StringGraphType>();
                retrunType.ResolvedType = new StringGraphType()
                {
                    Name = "Animal"
                };

                var context = new ResolveFieldContext
                {
                    Arguments   = new Dictionary <string, object>(),
                    UserContext = new GraphQLContext
                    {
                        ServiceProvider = services
                    },
                    ReturnType = retrunType
                };

                var ci = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "1", ContentItemVersionId = "1"
                };
                ci.Weld(new Animal {
                    Name = "doug", IsHappy = true, IsScary = false
                });

                var ci1 = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "2", ContentItemVersionId = "2"
                };
                ci1.Weld(new Animal {
                    Name = "doug", IsHappy = false, IsScary = true
                });

                var ci2 = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "3", ContentItemVersionId = "3"
                };
                ci2.Weld(new Animal {
                    Name = "tommy", IsHappy = false, IsScary = true
                });


                var session = ((GraphQLContext)context.UserContext).ServiceProvider.GetService <ISession>();
                session.Save(ci);
                session.Save(ci1);
                session.Save(ci2);
                await session.CommitAsync();

                var type = new ContentItemsFieldType("Animal", new Schema());

                context.Arguments["where"] = JObject.Parse("{ animals: { name: \"doug\", isScary: true } }");
                var animals = await((AsyncFieldResolver <IEnumerable <ContentItem> >)type.Resolver).Resolve(context);

                Assert.Single(animals);
                Assert.Equal("doug", animals.First().As <Animal>().Name);
                Assert.True(animals.First().As <Animal>().IsScary);
                Assert.False(animals.First().As <Animal>().IsHappy);
            }
        }
Beispiel #4
0
        public async Task ShouldFilterByContentItemIndexWhenSqlTablePrefixIsUsed()
        {
            await _initializeTask;

            _prefixedStore.RegisterIndexes <AnimalIndexProvider>();

            using (var services = new FakeServiceCollection())
            {
                services.Populate(new ServiceCollection());
                services.Services.AddScoped(x => _prefixedStore.CreateSession());

                var shellSettings = new ShellSettings();
                shellSettings["TablePrefix"] = _prefix;

                services.Services.AddScoped(x => shellSettings);
                services.Build();

                var returnType = new ListGraphType <StringGraphType>();
                returnType.ResolvedType = new StringGraphType()
                {
                    Name = "Animal"
                };

                var animalWhereInput = new AnimalPartWhereInput();
                var inputs           = new FieldType {
                    Name = "Inputs", Arguments = new QueryArguments {
                        new QueryArgument <WhereInputObjectGraphType> {
                            Name = "where", Description = "filters the animals", ResolvedType = animalWhereInput
                        }
                    }
                };

                var context = new ResolveFieldContext
                {
                    Arguments   = new Dictionary <string, object>(),
                    UserContext = new GraphQLContext
                    {
                        ServiceProvider = services
                    },
                    ReturnType      = returnType,
                    FieldDefinition = inputs
                };

                var ci = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "1", ContentItemVersionId = "1"
                };
                ci.Weld(new AnimalPart {
                    Name = "doug"
                });

                var session = ((GraphQLContext)context.UserContext).ServiceProvider.GetService <ISession>();
                session.Save(ci);
                await session.CommitAsync();

                var type = new ContentItemsFieldType("Animal", new Schema(), Options.Create(new GraphQLContentOptions()), Options.Create(new GraphQLSettings {
                    DefaultNumberOfResults = 10
                }));

                context.Arguments["where"] = JObject.Parse("{ contentItemId: \"1\" }");
                var dogs = await((AsyncFieldResolver <IEnumerable <ContentItem> >)type.Resolver).Resolve(context);

                Assert.Single(dogs);
                Assert.Equal("doug", dogs.First().As <AnimalPart>().Name);
            }
        }
Beispiel #5
0
        public async Task ShouldFilterByAliasIndexRegardlessOfInputFieldCase(string fieldName)
        {
            _store.RegisterIndexes <AnimalIndexProvider>();

            using (var services = new FakeServiceCollection())
            {
                services.Populate(new ServiceCollection());
                services.Services.AddScoped(x => _store.CreateSession());
                services.Services.AddScoped(x => new ShellSettings());
                services.Services.AddScoped <IIndexProvider, AnimalIndexProvider>();
                services.Services.AddScoped <IIndexAliasProvider, MultipleAliasIndexProvider>();
                services.Services.AddSingleton <IIndexPropertyProvider, IndexPropertyProvider <AnimalIndex> >();
                services.Build();

                var returnType = new ListGraphType <StringGraphType>
                {
                    ResolvedType = new StringGraphType()
                    {
                        Name = "Animal"
                    }
                };

                // setup the whereinput fieldname with the test data
                var animalWhereInput = new AnimalPartWhereInput(fieldName);
                var inputs           = new FieldType {
                    Name = "Inputs", Arguments = new QueryArguments {
                        new QueryArgument <WhereInputObjectGraphType> {
                            Name = "where", Description = "filters the animals", ResolvedType = animalWhereInput
                        }
                    }
                };

                var context = new ResolveFieldContext
                {
                    Arguments   = new Dictionary <string, object>(),
                    UserContext = new GraphQLContext
                    {
                        ServiceProvider = services
                    },
                    ReturnType      = returnType,
                    FieldDefinition = inputs
                };

                var ci = new ContentItem {
                    ContentType = "Animal", Published = true, ContentItemId = "1", ContentItemVersionId = "1"
                };
                ci.Weld(new AnimalPart {
                    Name = "doug"
                });

                var session = ((GraphQLContext)context.UserContext).ServiceProvider.GetService <ISession>();
                session.Save(ci);
                await session.SaveChangesAsync();

                var type = new ContentItemsFieldType("Animal", new Schema(), Options.Create(new GraphQLContentOptions()), Options.Create(new GraphQLSettings {
                    DefaultNumberOfResults = 10
                }));

                context.Arguments["where"] = JObject.Parse(string.Concat("{ ", fieldName, ": { name: \"doug\" } }"));
                var dogs = await((LockedAsyncFieldResolver <IEnumerable <ContentItem> >)type.Resolver).Resolve(context);

                Assert.Single(dogs);
                Assert.Equal("doug", dogs.First().As <AnimalPart>().Name);
            }
        }