protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.UseEnvironment("Testing"); builder.ConfigureAppConfiguration((context, conf) => { conf.AddJsonFile(AppDomain.CurrentDomain.BaseDirectory + "appsettings.Testing.json"); conf.AddUserSecrets <Startup>(); }); builder.ConfigureTestServices((services) => { var configuration = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); services.RegisterDebugRepositoriesModule(configuration); services.AddDebugServicesModule(configuration); var testGraphsMapping = configuration.GetSection("FunctionalTests:Graphs").Get <Dictionary <string, string> >(); var fakeRepo = new FakeTripleStoreRepository(testGraphsMapping); services.RemoveAll(typeof(ITripleStoreRepository)); services.AddSingleton <ITripleStoreRepository>(provider => { return(fakeRepo); }); services.RemoveAll(typeof(IRemoteAppDataService)); services.AddTransient <IRemoteAppDataService>(provider => { var remoteAppDataMock = new Mock <IRemoteAppDataService>(); var validPersons = new List <string> { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; remoteAppDataMock.Setup(mock => mock.CheckPerson(It.IsIn <string>(validPersons))).Returns(Task.FromResult(true)); remoteAppDataMock.Setup(mock => mock.CheckPerson(It.IsNotIn <string>(validPersons))).Returns(Task.FromResult(false)); remoteAppDataMock.Setup(t => t.CreateConsumerGroup(It.IsAny <Uri>())); remoteAppDataMock.Setup(t => t.DeleteConsumerGroup(It.IsAny <Uri>())); remoteAppDataMock.Setup(t => t.NotifyResourcePublished(It.IsAny <Resource>())); return(remoteAppDataMock.Object); }); services.RemoveAll(typeof(IMessageQueueService)); services.AddTransient <IMessageQueueService>(provider => { return(new Mock <IMessageQueueService>().Object); }); services.RemoveAll(typeof(IReindexingService)); services.AddTransient <IReindexingService>(provider => { return(new Mock <IReindexingService>().Object); }); }); }
protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.UseEnvironment("Testing"); builder.ConfigureAppConfiguration((context, conf) => { conf.AddJsonFile(AppDomain.CurrentDomain.BaseDirectory + "appsettings.Testing.json"); conf.AddUserSecrets <Startup>(); }); builder.ConfigureTestServices((services) => { var configuration = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); services.AddRepositoryModules(configuration); services.AddServiceModules(configuration); services.AddMemoryCacheModule(configuration, JsonSerializerSettings.GetSerializerSettings()); var testGraphsMapping = configuration.GetSection("FunctionalTests:Graphs").Get <Dictionary <string, string> >(); var fakeRepo = new FakeTripleStoreRepository(testGraphsMapping); services.RemoveAll(typeof(IRemoteRegistrationService)); services.AddSingleton <IRemoteRegistrationService>(provider => { var mockRegServices = new Mock <IRemoteRegistrationService>(); var cgs = new ConsumerGroupBuilder().GenerateSampleDataList(); mockRegServices.Setup(s => s.GetConsumerGroups()).ReturnsAsync(cgs); return(mockRegServices.Object); }); services.RemoveAll(typeof(ITripleStoreRepository)); services.AddSingleton <ITripleStoreRepository>(provider => { return(fakeRepo); }); }); }