public void ServiceProviderBuilder_WithUserSpecificServices_Should_ReturnMatchingService() { var provider = new ServiceProviderBuilder(); var defaultService = provider.Build().GetService <IOrganizationServiceFactory>().CreateOrganizationService(null); Assert.IsNotNull(defaultService); var userId = Guid.NewGuid(); provider.WithService(defaultService, userId); var userService = provider.Build().GetService <IOrganizationServiceFactory>().CreateOrganizationService(userId); var response = userService.GetCurrentlyExecutingUserInfo(); Assert.AreEqual(userId, response.UserId); }
private IServiceProvider CreateServiceProvider(TestProgrammingPlatform generator, bool scriptOnly) { var sourceCodeFolder = Path.Combine(_testDirPath, "src"); Directory.CreateDirectory(sourceCodeFolder); var outputFolder = Path.Combine(_testDirPath, "output"); Directory.CreateDirectory(outputFolder); var servicesBuilder = new ServiceProviderBuilder() .ConfigureServices(services => { // Add 'test' script generator here as we can control what the script output is rather // than depending on in-built script generators whose script could change overtime causing // this test to be difficult to manage. services.RemoveAll <ILanguageDetector>(); services.TryAddEnumerable( ServiceDescriptor.Singleton <ILanguageDetector>( new TestLanguageDetectorUsingLangName( detectedLanguageName: "test", detectedLanguageVersion: "1.0.0"))); services.RemoveAll <IProgrammingPlatform>(); services.TryAddEnumerable( ServiceDescriptor.Singleton <IProgrammingPlatform>(generator)); services.AddSingleton <ITempDirectoryProvider>( new TestTempDirectoryProvider(Path.Combine(_testDirPath, "temp"))); }) .ConfigureScriptGenerationOptions(o => { o.SourceDir = sourceCodeFolder; o.DestinationDir = outputFolder; o.ScriptOnly = scriptOnly; }); return(servicesBuilder.Build()); }
public TestServiceProvider() { var serviceCollection = new ServiceCollection(); var configuration = GenerateConfiguration(); var serviceProviderBuilder = new ServiceProviderBuilder(new LoggerFactory(), configuration) { ServiceCollection = serviceCollection }; var encodingService = new Mock <IEncodingService>(); encodingService.Setup(x => x.Decode(It.Is <string>(s => s.Equals(TestDataValues.NonLevyHashedAccountId)), It.IsAny <EncodingType>())).Returns(TestDataValues.NonLevyAccountId); encodingService.Setup(x => x.Encode(It.Is <long>(l => l.Equals(TestDataValues.NonLevyAccountId)), It.IsAny <EncodingType>())).Returns(TestDataValues.NonLevyHashedAccountId); encodingService.Setup(x => x.Decode(It.Is <string>(s => s.Equals(TestDataValues.LevyHashedAccountId)), It.IsAny <EncodingType>())).Returns(TestDataValues.LevyAccountId); encodingService.Setup(x => x.Encode(It.Is <long>(l => l.Equals(TestDataValues.LevyAccountId)), It.IsAny <EncodingType>())).Returns(TestDataValues.LevyHashedAccountId); serviceCollection.AddSingleton(encodingService.Object); var findApprenticeshipTrainingService = new Mock <IFindApprenticeshipTrainingService>(); serviceCollection.AddSingleton(findApprenticeshipTrainingService.Object); var mockAccountApiClient = new Mock <IAccountApiClient>(); serviceCollection.AddSingleton(mockAccountApiClient.Object); var mockNotificationService = new Mock <INotificationsService>(); serviceCollection.AddSingleton(mockNotificationService.Object); var mockReservationIndex = new Mock <IReservationIndexRepository>(); serviceCollection.AddSingleton(mockReservationIndex.Object); var mockProviderPermissions = new Mock <IProviderPermissionRepository>(); serviceCollection.AddSingleton(mockProviderPermissions.Object); var mockReservationCreatedHandler = new Mock <IReservationCreatedHandler>(); serviceCollection.AddSingleton(mockReservationCreatedHandler.Object); var mockReservationDeletedHandler = new Mock <IReservationDeletedHandler>(); serviceCollection.AddSingleton(mockReservationDeletedHandler.Object); var mockAccountsService = new Mock <IAccountsService>(); serviceCollection.AddSingleton(mockAccountsService.Object); var mockNotificationTokenBuilder = new Mock <INotificationTokenBuilder>(); serviceCollection.AddSingleton(mockNotificationTokenBuilder.Object); _serviceProvider = serviceProviderBuilder.Build(); }
public TestsSetup() { _serviceProvider = ServiceProviderBuilder.Build(); _snapshot = _serviceProvider.GetRequiredService <Snapshot>(); _dockerSetup = DockerSetup.Create(SolutionPathProvider.GetSolutionPath("Hexure").DirectoryName, new List <string>() { "docker-compose.yml" }); }
private static IServiceProvider GetServiceProvider(DetectCommand cmd) { var servicesBuilder = new ServiceProviderBuilder() .ConfigureServices(services => { var configuration = new ConfigurationBuilder().Build(); services.AddSingleton <IConfiguration>(configuration); }); return(servicesBuilder.Build()); }
private void Given_a_service_collection_with_a_imMemoryDb_and_SlackFacadeSpy() { var serviceProviderBuilder = new ServiceProviderBuilder(); serviceProviderBuilder = serviceProviderBuilder .WithServicesFromStartup() .WithInMemoryDb() .RemoveType(typeof(ISlackFacade)); var slackFacadeSpy = new SlackFacadeSpy(); serviceProviderBuilder.Services.AddSingleton <ISlackFacade>(slackFacadeSpy); _serviceProvider = serviceProviderBuilder.Build(); }
/// <summary> /// Configures the services injected at runtime. /// </summary> /// <param name="services">The services.</param> /// <returns>The service provider.</returns> public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddDbContext(); services.AddAuthentication() .AddBotAuthentication(configuration) .AddManageConversationAuthentication(configuration); services.AddMvc(options => options.Filters.Add <TrustServiceUrlAttribute>()); services.AddSpaStaticFiles(options => options.RootPath = "wwwroot"); ServiceProviderBuilder serviceProviderBuilder = new ServiceProviderBuilder(); IServiceProvider serviceProvider = serviceProviderBuilder.Build(services); configuration.Bind(serviceProvider.GetRequiredService <IApplicationConfiguration>()); return(serviceProvider); }
public TestServiceProvider() { var serviceCollection = new ServiceCollection(); var configuration = GenerateConfiguration(); var serviceProviderBuilder = new ServiceProviderBuilder(new LoggerFactory(), configuration) { ServiceCollection = serviceCollection }; var encodingService = new Mock <IEncodingService>(); encodingService.Setup(x => x.Decode(It.Is <string>(s => s.Equals(TestDataValues.NonLevyHashedAccountId)), It.Is <EncodingType>(t => t == EncodingType.PublicAccountId))) .Returns(TestDataValues.NonLevyAccountId); encodingService.Setup(x => x.Encode(It.Is <long>(l => l.Equals(TestDataValues.NonLevyAccountId)), It.Is <EncodingType>(t => t == EncodingType.PublicAccountId))) .Returns(TestDataValues.NonLevyHashedAccountId); encodingService.Setup(x => x.Decode(It.Is <string>(s => s.Equals(TestDataValues.LevyHashedAccountId)), It.Is <EncodingType>(t => t == EncodingType.PublicAccountId))) .Returns(TestDataValues.LevyAccountId); encodingService.Setup(x => x.Encode(It.Is <long>(l => l.Equals(TestDataValues.LevyAccountId)), It.Is <EncodingType>(t => t == EncodingType.PublicAccountId))) .Returns(TestDataValues.LevyHashedAccountId); serviceCollection.AddSingleton(encodingService.Object); var mockAccountApiClient = new Mock <IAccountApiClient>(); serviceCollection.AddSingleton(mockAccountApiClient.Object); var mockNotificationService = new Mock <INotificationsService>(); serviceCollection.AddSingleton(mockNotificationService.Object); _serviceProvider = serviceProviderBuilder.Build(); }
public static async Task Main(string[] args) { _serviceProvider = ServiceProviderBuilder.Build(); var parser = _serviceProvider.GetService <Parser>(); await parser.ParseArguments <CommandLineOptions>(args).MapResult(async o => { if (o.Any()) { var mediator = _serviceProvider.GetService <IMediator>(); if (o.ArchiveLists) { await mediator.Send(new ArchiveLists.Command()); } if (o.ValidateUrls) { await mediator.Send(new ValidateAllUrls.Command()); } } }, e => Task.FromResult(0) ); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Event Collector API", Version = "v1" }); }); ServiceProviderBuilder serviceProviderBuilder = new ServiceProviderBuilder(); IServiceProvider serviceProvider = serviceProviderBuilder.Build(services); configuration.Bind(serviceProvider.GetRequiredService <IApplicationConfiguration>()); IEventCollectorServerContext eventCollectorServerContext = serviceProvider.GetRequiredService <IEventCollectorServerContext>(); eventCollectorServerContext.Configure(); return(serviceProvider); }