public TestBase() { var services = new ServiceCollection(); // Services services.AddMediatR(); services.AddScoped(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>)); services.AddMvc().AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining <Startup>(); }); services.AddAutoMapper(); // Database var databaseName = Guid.NewGuid().ToString(); _db = new DatabaseContext(DatabaseContextMock <DatabaseContext> .InMemoryDatabase()); // Global objects _jobClientMock = new Mock <IBackgroundJobClient>(); _jobClientMock.Setup(x => x.Create(It.IsAny <Job>(), It.IsAny <EnqueuedState>())); _fixture = new Fixture(); IContainer container = new Container(cfg => { cfg.For <IBackgroundJobClient>().Use(_jobClientMock.Object); cfg.For <DatabaseContext>().Use(_db); cfg.Populate(services); }); _mediator = container.GetInstance <IMediator>(); }
public TestBase() { var services = new ServiceCollection(); // Services services.AddMediatR(); services.AddScoped(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>)); services.AddScoped(typeof(IPipelineBehavior <,>), typeof(RequestPreProcessorBehavior <,>)); services.AddScoped(typeof(IPipelineBehavior <,>), typeof(RequestPostProcessorBehavior <,>)); services.AddMvc().AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining <Startup>(); }); services.AddAutoMapper(); // Database var databaseName = Guid.NewGuid().ToString(); _db = new DatabaseContext(DatabaseContextMock <DatabaseContext> .InMemoryDatabase()); // Global objects _fixture = new Fixture(); _seedData = new SeedData(_fixture); _jobClientMock = new Mock <IBackgroundJobClient>(); _jobClientMock.Setup(x => x.Create(It.IsAny <Job>(), It.IsAny <EnqueuedState>())); _identityOptionsMock = new Mock <IOptions <IdentityOptions> >(); _identityOptionsMock.Setup(x => x.Value).Returns(new IdentityOptions { ApiSecret = _fixture.Create <string>() }); IContainer container = new Container(cfg => { cfg.For <IBackgroundJobClient>().Use(_jobClientMock.Object); cfg.For <IOptions <IdentityOptions> >().Use(_identityOptionsMock.Object); cfg.For <DatabaseContext>().Use(_db); cfg.For(typeof(ILogger <>)).Use(typeof(NullLogger <>)); cfg.Populate(services); }); _mediator = container.GetInstance <IMediator>(); }
public TestBase() { var services = new ServiceCollection(); // Services services.AddMvc(); // GraphQL services.AddSingleton <IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService)); _executer = new DocumentExecuter(); _writer = new DocumentWriter(indent: true); services.AddGraphQL(o => { o.ExposeExceptions = true; o.ComplexityConfiguration = new GraphQL.Validation.Complexity.ComplexityConfiguration { MaxDepth = 15 }; }) .AddGraphTypes(ServiceLifetime.Singleton); services.AddSingleton <ISchema, RootSchema>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // Database _db = new DatabaseContext(DatabaseContextMock <DatabaseContext> .InMemoryDatabase()); // Global objects _jobClientMock = new Mock <IBackgroundJobClient>(); _jobClientMock.Setup(x => x.Create(It.IsAny <Job>(), It.IsAny <EnqueuedState>())); _fixture = new Fixture(); _fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => _fixture.Behaviors.Remove(b)); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); IContainer container = new Container(cfg => { cfg.For <IBackgroundJobClient>().Use(_jobClientMock.Object); cfg.For <ISchema>().Use <RootSchema>(); cfg.For <DatabaseContext>().Use(_db); cfg.For(typeof(ILogger <>)).Use(typeof(NullLogger <>)); cfg.Populate(services); }); _schema = container.GetInstance <ISchema>(); _jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }, Formatting = Formatting.Indented }; }