0

I'm trying to create units test for our graphql C# Function Application. I've started following along with the video from the Chilicream website on how to create the tests, but I cannot seem to get past the first part he does in his video (here).

Here is what I have so far.

public class SimpleTest
{
    [Fact]
    public async Task SchemaChangeTest()
    {
        var schema = 
            await new ServiceCollection()
            .AddGraphQLServer()
            .AddQueryType(q => q.name("PHQuery")) //copied from the FA's Program.cs file
            //.AddQueryType<InventoryQuery>(q => q.name("PHQuery")) tried this as well, No Joy
            .AddType<InventoryQuery>()
            .BuildSchemaAsync();

            schema.toString().MatchSnapshot();
    }
}

The test fails with the following exception:

    HotChocolate.SchemaException : For more details look at the 'Errors' property.
    
    1. Could not load type 'HotChocolate.Types.Descriptors.ITypeRefernce' from assembly 'HotChocolate.Types... (HotChocolate.Types.ObjectTypeExtension<PH.Core.Queries.InventoryQuery>)

I'm really at a loss. I can't seem to find any useful information about how to get this working. Any help would be greatly appreciated.

TIA


EDIT 1

//InventoryQuery.cs

using PH.Core.Interfaces;
using PH.Core.Models;

namespace PH.Core.Queries
{
    [ExtendObjectType("PHQuery")]
    public class InventoryQuery
    {
        [UseOffesetPaging(IncludeTotalCount = true, MaxPageSize = (int.MaxValue - 1), DefaultPageSize = int.MaxValue)]
        [UseFiltering()]
        [UseSorting]
        public IQueryable<Inventory> GetInventory([Service] 
            IInventoryRepository inventoryRepository){
            return inventoryRepository.GetInventory();
        }
    }
}

//Program.cs (partial)

...
var host = new HostBuilder()
...
    .ConfigureServices(services => 
    {
        ...
        services.AddTransient<IInventoryRepository,InventoryRepository>();
        ...
        services.AddGraphQLServer()
            .RegisterDbContext<PHContext>()
            .AddFiltering()
            .AddSorting()
            .AddQueryType(q => q.Name("PHQuery"))
            .AddType<InventoryQuery>();
        ...
     });
    
Rob M
  • 1,007
  • 2
  • 17
  • 38
  • I glad to help but for me there is not enough information. Can you show how `InventoryQuery` and `PHQuery` looks like? – Eugene May 24 '23 at 07:29
  • @Eugene Sure. I have been focused on other things, but I'm finally getting back to this. I've edited the initial post with the requested data. – Rob M Jun 27 '23 at 17:01

0 Answers0