public void Dispose()
 {
     try
     {
         _host.Dispose();
         Directory.Delete(_hostPath, true);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 2
0
        public async Task DisposedScriptLoggerFactory_UsesFullStackTrace()
        {
            var host = new TestFunctionHost(@"TestScripts\CSharp",
                                            configureScriptHostServices: s =>
            {
                s.AddSingleton <IExtensionConfigProvider, CustomTriggerExtensionConfigProvider>();
                s.Configure <ScriptJobHostOptions>(o => o.Functions = new[] { "CustomTrigger" });
            });

            await CustomListener.RunAsync("one");

            host.Dispose();

            // In this scenario, the logger throws an exception before we enter the try/catch for the function invocation.
            var ex = await Assert.ThrowsAsync <HostDisposedException>(() => CustomListener.RunAsync("two"));

            Assert.Equal($"The host is disposed and cannot be used. Disposed object: '{typeof(ScriptLoggerFactory).FullName}'; Found IListener in stack trace: '{typeof(CustomListener).AssemblyQualifiedName}'", ex.Message);
            Assert.Contains("CustomListener.RunAsync", ex.StackTrace);
        }
Exemplo n.º 3
0
        public async Task DisposedResolver_UsesFullStackTrace()
        {
            var host = new TestFunctionHost(@"TestScripts\CSharp",
                                            configureScriptHostServices: s =>
            {
                s.AddSingleton <IExtensionConfigProvider, CustomTriggerExtensionConfigProvider>();
                s.Configure <ScriptJobHostOptions>(o => o.Functions = new[] { "CustomTrigger" });
                s.AddSingleton <ILoggerFactory, TestScriptLoggerFactory>();
            });

            await CustomListener.RunAsync("one");

            host.Dispose();

            // In this scenario, the function is considered failed even though the function itself was never called.
            var result = await CustomListener.RunAsync("two");

            Assert.False(result.Succeeded);

            var ex = result.Exception;

            Assert.Equal($"The host is disposed and cannot be used. Disposed object: '{typeof(ScopedResolver).FullName}'; Found IListener in stack trace: '{typeof(CustomListener).AssemblyQualifiedName}'", ex.Message);
            Assert.Contains("CustomListener.RunAsync", ex.StackTrace);
        }