Skip to content

Commit

Permalink
fixed more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlwoodhouse committed Apr 9, 2021
1 parent 79d6ce2 commit c97640f
Showing 1 changed file with 59 additions and 20 deletions.
79 changes: 59 additions & 20 deletions test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,23 @@ public async Task ShouldFilterByContentItemIndex()
services.Build();

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

var context = new ResolveFieldContext
{
Arguments = new Dictionary<string, ArgumentValue>(),
UserContext = new GraphQLUserContext(),
FieldDefinition = inputs,
FieldDefinition = new FieldType
{
Name = "Inputs",
ResolvedType = new ListGraphType(new StringGraphType() { Name = "Animal" }),
Arguments = new QueryArguments {
new QueryArgument<WhereInputObjectGraphType> {
Name = "where",
Description = "filters the animals",
ResolvedType = animalWhereInput
}
}
},
RequestServices = services
};

Expand Down Expand Up @@ -180,13 +190,23 @@ public async Task ShouldFilterByContentItemIndexWhenSqlTablePrefixIsUsed()
services.Build();

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


var context = new ResolveFieldContext
{
Arguments = new Dictionary<string, ArgumentValue>(),
UserContext = new GraphQLUserContext(),
FieldDefinition = inputs,
FieldDefinition = new FieldType
{
Name = "Inputs",
ResolvedType = new ListGraphType(new StringGraphType() { Name = "Animal" }),
Arguments = new QueryArguments {
new QueryArgument<WhereInputObjectGraphType> {
Name = "where",
Description = "filters the animals",
ResolvedType = animalWhereInput
}
}
},
RequestServices = services
};

Expand Down Expand Up @@ -228,13 +248,22 @@ public async Task ShouldFilterByAliasIndexRegardlessOfInputFieldCase(string fiel

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

var context = new ResolveFieldContext
{
Arguments = new Dictionary<string, ArgumentValue>(),
FieldDefinition = new FieldType {
Name = "Inputs",
ResolvedType = new ListGraphType(new StringGraphType() { Name = "Animal" }),
Arguments = new QueryArguments {
new QueryArgument<WhereInputObjectGraphType> {
Name = "where",
Description = "filters the animals",
ResolvedType = animalWhereInput
}
}
},
UserContext = new GraphQLUserContext(),
FieldDefinition = inputs,
RequestServices = services
};

Expand All @@ -245,7 +274,7 @@ public async Task ShouldFilterByAliasIndexRegardlessOfInputFieldCase(string fiel
session.Save(ci);
await session.SaveChangesAsync();

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

context.Arguments["where"] = new ArgumentValue(JObject.Parse(string.Concat("{ ", fieldName, ": { name: \"doug\" } }")), ArgumentSource.Variable);
var dogs = await ((LockedAsyncFieldResolver<IEnumerable<ContentItem>>)type.Resolver).Resolve(context);
Expand Down Expand Up @@ -279,7 +308,10 @@ public async Task ShouldBeAbleToUseTheSameIndexForMultipleAliases()
{
Arguments = new Dictionary<string, ArgumentValue>(),
UserContext = new GraphQLUserContext(),
FieldDefinition = new FieldType { ResolvedType = new StringGraphType() { Name = "Animal" } },
FieldDefinition = new FieldType
{
ResolvedType = new ListGraphType(new StringGraphType() { Name = "Animal" })
},
RequestServices = services
};

Expand Down Expand Up @@ -326,17 +358,15 @@ public async Task ShouldFilterOnMultipleIndexesOnSameAlias()
services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalTraitsIndex>>();
services.Build();

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

var context = new ResolveFieldContext
{
Arguments = new Dictionary<string, ArgumentValue>(),
//UserContext = new GraphQLUserContext
//{
// ServiceProvider = services
//},
//ReturnType = returnType
UserContext = new GraphQLUserContext(),
FieldDefinition = new FieldType
{
ResolvedType = new ListGraphType(new StringGraphType() { Name = "Animal" })
},
RequestServices = services
};

var ci = new ContentItem { ContentType = "Animal", Published = true, ContentItemId = "1", ContentItemVersionId = "1" };
Expand Down Expand Up @@ -382,15 +412,24 @@ public async Task ShouldFilterPartsWithoutAPrefixWhenThePartHasNoPrefix()
services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalIndex>>();
services.Build();


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

var context = new ResolveFieldContext
{
Arguments = new Dictionary<string, ArgumentValue>(),
UserContext = new GraphQLUserContext(),
FieldDefinition = inputs,
FieldDefinition = new FieldType
{
Name = "Inputs",
ResolvedType = new ListGraphType(new StringGraphType() { Name = "Animal" }),
Arguments = new QueryArguments {
new QueryArgument<WhereInputObjectGraphType> {
Name = "where",
Description = "filters the animals",
ResolvedType = animalWhereInput
}
}
},
RequestServices = services
};

Expand Down

0 comments on commit c97640f

Please sign in to comment.