private static void AssertDependenciesForSecurity(IServiceProvider serviceProvider) { DependencyRegistrarSupport.AssertServiceIsInstanceOfType <ApiKeyConfiguration, ApiKeyConfiguration>(serviceProvider); DependencyRegistrarSupport.AssertServiceIsNotNull <IApiKeyRepository>(serviceProvider); AssertApiKeyConfiguration(serviceProvider); }
private static void AssertDependenciesForTodoItems(IServiceProvider serviceProvider) { // Cannot verify the TodoContext because it is internal only // We can test the handlers and contracts were setup. DependencyRegistrarSupport.AssertServiceIsNotNull <IRequestHandler <GetTodoItemsRequest, Response <List <TodoItem> > > >(serviceProvider); DependencyRegistrarSupport.AssertServiceIsNotNull <IRequestHandler <GetTodoItemRequest, Response <TodoItem> > >(serviceProvider); DependencyRegistrarSupport.AssertServiceIsNotNull <IRequestHandler <CreateTodoItemRequest, Response <TodoItem> > >(serviceProvider); DependencyRegistrarSupport.AssertServiceIsNotNull <IRequestHandler <DeleteTodoItemRequest, Response> >(serviceProvider); DependencyRegistrarSupport.AssertServiceIsNotNull <IRequestHandler <UpdateTodoItemRequest, Response> >(serviceProvider); }
public void RegisterTest() { var configurationRootFromJson = new ConfigurationBuilder().AddJsonFile(@"Configuration\appsettings.test.json").Build(); var serviceCollection = new ServiceCollection(); DependencyRegistrar.Register(serviceCollection, configurationRootFromJson); var serviceProvider = serviceCollection.BuildServiceProvider(); DependencyRegistrarSupport.AssertServiceIsInstanceOfType <ProblemDetailsConfiguration, ProblemDetailsConfiguration>(serviceProvider); DependencyRegistrarSupport.AssertServiceIsInstanceOfType <IProblemDetailsFactory, ProblemDetailsFactory>(serviceProvider); AssertConfiguration(serviceProvider); }
public void RegisterTest() { // Given that the LoggingBehavior class has a dependency // on an ILogger<> implementation, we could build the // service provider and verify that the registration // was added, but that would enforce an order of events // on service registration. Skip for now. var serviceCollection = new ServiceCollection(); DependencyRegistrarSupport.AddScopedLogger(serviceCollection); DependencyRegistrar.Register(serviceCollection); var serviceProvider = serviceCollection.BuildServiceProvider(); DependencyRegistrarSupport.AssertServiceIsInstanceOfType <ILogger <LoggingBehavior>, FakeLogger <LoggingBehavior> >(serviceProvider); DependencyRegistrarSupport.AssertServiceIsInstanceOfType <IPipelineBehavior, LoggingBehavior>(serviceProvider); }
public void RegisterDependencies() { var configurationRootFromJson = new ConfigurationBuilder().AddJsonFile(@"Configuration\appSettings.test.json").Build(); var serviceCollection = new ServiceCollection(); DependencyRegistrarSupport.AddScopedLogger(serviceCollection); serviceCollection.RegisterDependencies(configurationRootFromJson); var serviceProvider = serviceCollection.BuildServiceProvider(); // No clean way of getting the count of ILogger<out TCategoryName> // without changing the class implemented for the logger // from internal to public, which defeats the purpose. // Long term solution was to create a Facade for the ILogger, // but that's not worth the time, effort, maintenance, and is // not a critical feature here that must be tested. // In order to verify the internals were actually registered properly // we could make them public, but that would defeat the purpose. // We could also create verify methods in the dependent Test projects // and the references here to call them, but that would mean adding // dependencies on each test project. Again, that would defeat the // purpose of doing the tests. // Best solution to honor the dependencies while still testing, // would be to change ServiceCollectionExtensions to a concrete // class that is registered in the Program so it could be // injected in the Startup. // As a rule of thumb, unit test the critical logic, anything // discovered as a bug to verify the issue is fixed. // If the infrastructure is critical then, unit test it. // If the rules are critical, then unit test the rules. // Remember to perform integration tests, manual and automated // to ensure your app works as expected and is hooked up properly. AssertDependenciesForPipeline(serviceProvider); AssertDependenciesForMiddleware(serviceProvider); AssertDependenciesForSecurity(serviceProvider); AssertDependenciesForRules(serviceProvider); AssertDependenciesForTodoItems(serviceProvider); }
public static void VerifyDependencyRegistrar(ServiceProvider serviceProvider) { DependencyRegistrarSupport.AssertServiceIsInstanceOfType <ApiKeyConfiguration, ApiKeyConfiguration>(serviceProvider); DependencyRegistrarSupport.AssertServiceIsInstanceOfType <IApiKeyRepository, ApiKeyRepository>(serviceProvider); AssertApiKeyConfiguration(serviceProvider); }
private static void AssertDependenciesForRules(IServiceProvider serviceProvider) { DependencyRegistrarSupport.AssertServiceIsNotNull <IRulesEngine>(serviceProvider); DependencyRegistrarSupport.AssertServiceIsNotNull <IRulesFactory <string, int> >(serviceProvider); }
private static void AssertDependenciesForPipeline(IServiceProvider serviceProvider) => DependencyRegistrarSupport.AssertServiceIsNotNull <IPipelineBehavior>(serviceProvider);
public static void VerifyDependencyRegistrar(ServiceProvider serviceProvider) { DependencyRegistrarSupport.AssertServiceIsInstanceOfType <IRulesEngine, RulesEngine>(serviceProvider); DependencyRegistrarSupport.AssertServiceIsInstanceOfType <IRulesFactory <string, int>, RulesFactory <string, int> >(serviceProvider); }