public async Task CreateAsync_SkipsDisabledFunctions(Type jobType, string methodName) { Environment.SetEnvironmentVariable("EnvironmentSettingTrue", "True"); Mock <IFunctionDefinition> mockFunctionDefinition = new Mock <IFunctionDefinition>(); Mock <IFunctionInstanceFactory> mockInstanceFactory = new Mock <IFunctionInstanceFactory>(MockBehavior.Strict); Mock <IListenerFactory> mockListenerFactory = new Mock <IListenerFactory>(MockBehavior.Strict); SingletonManager singletonManager = new SingletonManager(); TestTraceWriter traceWriter = new TestTraceWriter(TraceLevel.Verbose); // create a bunch of function definitions that are disabled List <FunctionDefinition> functions = new List <FunctionDefinition>(); FunctionDescriptor descriptor = new FunctionDescriptor { Method = jobType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static), ShortName = string.Format("{0}.{1}", jobType.Name, methodName) }; FunctionDefinition definition = new FunctionDefinition(descriptor, mockInstanceFactory.Object, mockListenerFactory.Object); functions.Add(definition); // Create the composite listener - this will fail if any of the // function definitions indicate that they are not disabled HostListenerFactory factory = new HostListenerFactory(functions, singletonManager, DefaultJobActivator.Instance, null, traceWriter); IListener listener = await factory.CreateAsync(CancellationToken.None); Assert.Equal(1, traceWriter.Traces.Count); Assert.Equal(TraceLevel.Info, traceWriter.Traces[0].Level); Assert.Equal(TraceSource.Host, traceWriter.Traces[0].Source); Assert.Equal(string.Format("Function '{0}' is disabled", descriptor.ShortName), traceWriter.Traces[0].Message); Environment.SetEnvironmentVariable("EnvironmentSettingTrue", null); }
public async Task CreateAsync_SkipsDisabledFunctions(Type jobType, string methodName) { ConfigurationUtility.Reset(); Environment.SetEnvironmentVariable("EnvironmentSettingTrue", "True"); Mock <IFunctionDefinition> mockFunctionDefinition = new Mock <IFunctionDefinition>(); Mock <IFunctionInstanceFactory> mockInstanceFactory = new Mock <IFunctionInstanceFactory>(MockBehavior.Strict); Mock <IListenerFactory> mockListenerFactory = new Mock <IListenerFactory>(MockBehavior.Strict); SingletonManager singletonManager = new SingletonManager(); TestTraceWriter traceWriter = new TestTraceWriter(TraceLevel.Verbose); ILoggerFactory loggerFactory = new LoggerFactory(); TestLoggerProvider loggerProvider = new TestLoggerProvider(); loggerFactory.AddProvider(loggerProvider); // create a bunch of function definitions that are disabled List <FunctionDefinition> functions = new List <FunctionDefinition>(); var method = jobType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static); FunctionDescriptor descriptor = FunctionIndexer.FromMethod(method, DefaultJobActivator.Instance); FunctionDefinition definition = new FunctionDefinition(descriptor, mockInstanceFactory.Object, mockListenerFactory.Object); functions.Add(definition); // Create the composite listener - this will fail if any of the // function definitions indicate that they are not disabled HostListenerFactory factory = new HostListenerFactory(functions, singletonManager, DefaultJobActivator.Instance, null, traceWriter, loggerFactory); IListener listener = await factory.CreateAsync(CancellationToken.None); string expectedMessage = $"Function '{descriptor.ShortName}' is disabled"; // Validate TraceWriter Assert.Equal(1, traceWriter.Traces.Count); Assert.Equal(TraceLevel.Info, traceWriter.Traces[0].Level); Assert.Equal(TraceSource.Host, traceWriter.Traces[0].Source); Assert.Equal(expectedMessage, traceWriter.Traces[0].Message); // Validate Logger var logMessage = loggerProvider.CreatedLoggers.Single().LogMessages.Single(); Assert.Equal(LogLevel.Information, logMessage.Level); Assert.Equal(Logging.LogCategories.Startup, logMessage.Category); Assert.Equal(expectedMessage, logMessage.FormattedMessage); Environment.SetEnvironmentVariable("EnvironmentSettingTrue", null); }