public void Initialize() { var builder = new TestBuilder(); var mock = builder.MockBuilder; mock.Setup(b => b.TryRegister(typeof(IDocumentWriter), It.IsAny <Func <IServiceProvider, object> >(), ServiceLifetime.Transient)) .Returns <Type, Func <IServiceProvider, object>, ServiceLifetime>((_, func, serviceLifetime) => { Should.Throw <InvalidOperationException>(() => func(null)); return(builder); }).Verifiable(); mock.Setup(b => b.TryRegister(typeof(IDocumentExecuter), typeof(DocumentExecuter), ServiceLifetime.Singleton)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(IDocumentBuilder), typeof(GraphQLDocumentBuilder), ServiceLifetime.Singleton)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(IDocumentValidator), typeof(DocumentValidator), ServiceLifetime.Singleton)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(IComplexityAnalyzer), typeof(ComplexityAnalyzer), ServiceLifetime.Singleton)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(IDocumentCache), DefaultDocumentCache.Instance)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(IErrorInfoProvider), typeof(ErrorInfoProvider), ServiceLifetime.Singleton)).Returns(builder).Verifiable(); mock.Setup(b => b.Configure((Action <ErrorInfoProviderOptions, IServiceProvider>)null)).Returns(builder).Verifiable(); mock.Setup(b => b.Register(typeof(IConfigureExecution), It.IsAny <IConfigureExecution>(), false)).Returns <Type, IConfigureExecution, bool>((_, action, _) => { var schema = Mock.Of <ISchema>(MockBehavior.Strict); //verify no action if schema is set action.ConfigureAsync(new ExecutionOptions { Schema = schema, RequestServices = Mock.Of <IServiceProvider>(MockBehavior.Strict) }).Wait(); //verify schema is pulled from service provider if schema is not set var mockServiceProvider = new Mock <IServiceProvider>(MockBehavior.Strict); mockServiceProvider.Setup(s => s.GetService(typeof(ISchema))).Returns(schema).Verifiable(); var opts = new ExecutionOptions() { RequestServices = mockServiceProvider.Object, }; action.ConfigureAsync(opts).Wait(); opts.Schema.ShouldBe(schema); mockServiceProvider.Verify(); return(builder); }).Verifiable(); mock.Setup(b => b.TryRegister(typeof(EnumerationGraphType <>), typeof(EnumerationGraphType <>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(ConnectionType <>), typeof(ConnectionType <>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(ConnectionType <,>), typeof(ConnectionType <,>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(EdgeType <>), typeof(EdgeType <>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(PageInfoType), typeof(PageInfoType), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(InputObjectGraphType <>), typeof(InputObjectGraphType <>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(AutoRegisteringInputObjectGraphType <>), typeof(AutoRegisteringInputObjectGraphType <>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); mock.Setup(b => b.TryRegister(typeof(AutoRegisteringObjectGraphType <>), typeof(AutoRegisteringObjectGraphType <>), ServiceLifetime.Transient)).Returns(builder).Verifiable(); builder.CallInitialize(); mock.Verify(); mock.VerifyNoOtherCalls(); }