Ejemplo n.º 1
0
        public async Task Should_load_extension_in_directory()
        {
            var directory = Create.EmptyWorkspace().Directory;

            const string nugetPackageName      = "myNugetPackage";
            var          nugetPackageDirectory = new InMemoryDirectoryAccessor(
                directory.Subdirectory($"{nugetPackageName}/2.0.0"))
                                                 .CreateFiles();

            var extensionsDir =
                (FileSystemDirectoryAccessor)nugetPackageDirectory.GetDirectoryAccessorForRelativePath(new RelativeDirectoryPath("interactive-extensions/dotnet/cs"));

            var extensionDll = await KernelExtensionTestHelper.CreateExtensionInDirectory(
                directory, @"await kernel.SendAsync(new SubmitCode(""using System.Reflection;""));",
                extensionsDir);

            var kernel = CreateKernel();

            await kernel.SendAsync(new LoadExtensionsInDirectory(nugetPackageDirectory));


            KernelEvents.Should()
            .ContainSingle(e => e.Value is ExtensionLoaded &&
                           e.Value.As <ExtensionLoaded>().ExtensionPath.FullName.Equals(extensionDll.FullName));

            KernelEvents.Should()
            .ContainSingle(e => e.Value is CommandHandled &&
                           e.Value
                           .As <CommandHandled>()
                           .Command
                           .As <SubmitCode>()
                           .Code
                           .Contains("using System.Reflection;"));
        }
Ejemplo n.º 2
0
        public async Task The_extend_directive_can_be_used_to_load_a_kernel_extension()
        {
            var extensionDir = Create.EmptyWorkspace()
                               .Directory;

            var extensionDllPath = (await KernelExtensionTestHelper.CreateExtension(extensionDir, @"await kernel.SendAsync(new SubmitCode(""using System.Reflection;""));"))
                                   .FullName;

            var kernel = CreateKernel();

            using var events = kernel.KernelEvents.ToSubscribedList();

            await kernel.SendAsync(new SubmitCode($"#extend \"{extensionDllPath}\""));

            events.Should()
            .ContainSingle(e => e is ExtensionLoaded &&
                           e.As <ExtensionLoaded>().ExtensionPath.FullName.Equals(extensionDllPath));

            events.Should()
            .ContainSingle(e => e is CommandHandled &&
                           e.As <CommandHandled>()
                           .Command
                           .As <SubmitCode>()
                           .Code
                           .Contains("using System.Reflection;"));

            events.Should()
            .ContainSingle(e => e is DisplayedValueProduced &&
                           e.As <DisplayedValueProduced>()
                           .Value
                           .ToString()
                           .Contains($"Loaded kernel extension TestKernelExtension from assembly {extensionDllPath}"));
        }
Ejemplo n.º 3
0
        public async Task Gives_kernel_extension_load_exception_event_when_extension_throws_exception_during_load()
        {
            var extensionDir = Create.EmptyWorkspace()
                               .Directory;

            var extensionDllPath = (await KernelExtensionTestHelper.CreateExtension(extensionDir, @"throw new Exception();")).FullName;

            var kernel = CreateKernel();

            await kernel.SendAsync(new SubmitCode($"#extend \"{extensionDllPath}\""));

            KernelEvents.Should()
            .ContainSingle(e => e.Value is KernelExtensionLoadException);
        }
Ejemplo n.º 4
0
        public async Task The_extend_directive_can_be_used_to_load_a_kernel_extension()
        {
            var extensionDir = Create.EmptyWorkspace()
                               .Directory;

            var extensionDllPath = (await KernelExtensionTestHelper.CreateExtension(extensionDir, @"await kernel.SendAsync(new SubmitCode(""using System.Reflection;""));")).FullName;

            var kernel = CreateKernel();

            await kernel.SendAsync(new SubmitCode($"#extend \"{extensionDllPath}\""));

            KernelEvents.Should().ContainSingle(e => e.Value is ExtensionLoaded &&
                                                e.Value.As <ExtensionLoaded>().ExtensionPath.FullName.Equals(extensionDllPath));
            KernelEvents.Should()
            .ContainSingle(e => e.Value is CommandHandled &&
                           e.Value.As <CommandHandled>()
                           .Command
                           .As <SubmitCode>()
                           .Code
                           .Contains("using System.Reflection;"));
        }