Ejemplo n.º 1
0
        public static async Task ClassInitialize(TestContext context)
        {
            // Setup
            IServiceCollection services      = new ServiceCollection();
            IConfiguration     configuration = new ConfigurationBuilder().Build();

            services.AddSingleton(configuration);
            services.AddBotRuntime(configuration);

            var parent = Environment.CurrentDirectory;

            while (!string.IsNullOrEmpty(parent))
            {
                if (System.IO.Directory.EnumerateFiles(parent, "*proj").Any())
                {
                    break;
                }
                else
                {
                    parent = System.IO.Path.GetDirectoryName(parent);
                }
            }

            ResourceExplorer = new ResourceExplorer();
            ResourceExplorer.AddResourceType("yaml");
            ResourceExplorer.AddFolder(parent, monitorChanges: false);
        }
        private TestFlow BuildTestFlow(string folderPath, bool sendTrace = false)
        {
            TypeFactory.Configuration = new ConfigurationBuilder().Build();
            var storage          = new MemoryStorage();
            var convoState       = new ConversationState(storage);
            var userState        = new UserState(storage);
            var adapter          = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
            var resourceExplorer = new ResourceExplorer();

            resourceExplorer.AddFolder(folderPath);
            adapter
            .UseStorage(storage)
            .UseState(userState, convoState)
            .UseAdaptiveDialogs()
            .UseLanguageGeneration(resourceExplorer, "common.lg")
            .UseResourceExplorer(resourceExplorer)
            .Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

            var           resource = resourceExplorer.GetResource("Main.dialog");
            var           dialog   = DeclarativeTypeLoader.Load <AdaptiveDialog>(resource, resourceExplorer, DebugSupport.SourceMap);
            DialogManager dm       = new DialogManager(dialog);

            return(new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (dialog is AdaptiveDialog planningDialog)
                {
                    await dm.OnTurnAsync(turnContext, cancellationToken).ConfigureAwait(false);
                }
            }));
        }
Ejemplo n.º 3
0
        public async Task TestFolderSource_NewFiresChanged()
        {
            const string testId         = "NewFiresChanged.dialog";
            var          testDialogFile = Path.Combine(Environment.CurrentDirectory, testId);

            File.Delete(testDialogFile);

            var path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, PathUtils.NormalizePath(@"..\..\..")));

            using (var explorer = new ResourceExplorer())
            {
                explorer.AddFolder(path, monitorChanges: true);

                AssertResourceNull(explorer, testId);

                var changeFired = new TaskCompletionSource <bool>();

                explorer.Changed += (e, resources) =>
                {
                    if (resources.Any(resource => resource.Id == testId))
                    {
                        changeFired.SetResult(true);
                    }
                };

                // new file
                File.WriteAllText(testDialogFile, "{}");

                await Task.WhenAny(changeFired.Task, Task.Delay(5000)).ConfigureAwait(false);

                AssertResourceFound(explorer, testId);
            }
        }
Ejemplo n.º 4
0
        public static void ClassInitialize(TestContext context)
        {
            TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "AskingQuestionsSample"));

            resourceExplorer.AddFolder(path);
        }
        private TestFlow BuildTestFlow(string folderPath, bool sendTrace = false)
        {
            var storage          = new MemoryStorage();
            var convoState       = new ConversationState(storage);
            var userState        = new UserState(storage);
            var adapter          = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
            var resourceExplorer = new ResourceExplorer();

            resourceExplorer.AddFolder(folderPath);
            adapter
            .UseStorage(storage)
            .UseBotState(userState, convoState)
            .Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

            var           resource = resourceExplorer.GetResource("actionssample.dialog");
            var           dialog   = resourceExplorer.LoadType <AdaptiveDialog>(resource);
            DialogManager dm       = new DialogManager(dialog)
                                     .UseResourceExplorer(resourceExplorer)
                                     .UseLanguageGeneration();

            return(new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (dialog is AdaptiveDialog planningDialog)
                {
                    await dm.OnTurnAsync(turnContext, cancellationToken).ConfigureAwait(false);
                }
            }));
        }
        public static async Task ClassInitialize(TestContext context)
        {
            var parent = Environment.CurrentDirectory;

            while (!string.IsNullOrEmpty(parent))
            {
                if (System.IO.Directory.EnumerateFiles(parent, "*proj").Any())
                {
                    break;
                }
                else
                {
                    parent = System.IO.Path.GetDirectoryName(parent);
                }
            }

            ResourceExplorer = new ResourceExplorer();
            ResourceExplorer.AddFolder(parent, monitorChanges: false);

            var resource = ResourceExplorer.GetResource("test-ram.en-us.qna.json");

            Json = await resource.ReadTextAsync();

            IndexDirectory = new RAMDirectory();
            QLuceneEngine.CreateCatalog(Json, IndexDirectory);
        }
Ejemplo n.º 7
0
        public static void ClassInitialize(TestContext context)
        {
            TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
            TypeFactory.RegisterAdaptiveTypes();
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "ControllingConversation"));

            resourceExplorer.AddFolder(path);
        }
        public static void ClassInitialize(TestContext context)
        {
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "RespondingWithTextSample"));

            resourceExplorer.AddFolder(path);

            // register components.
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
        }
Ejemplo n.º 9
0
        public void TestFolderSource_Shallow()
        {
            var path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, PathUtils.NormalizePath(@"..\..\..")));

            using (var explorer = new ResourceExplorer())
            {
                explorer.AddFolder(path, false);

                var resources = explorer.GetResources("dialog").ToArray();
                Assert.Empty(resources);

                resources = explorer.GetResources("schema").ToArray();
                Assert.True(resources.Length > 0, "shallow folder should list the root files");
            }
        }
Ejemplo n.º 10
0
        public static void ClassInitialize(TestContext context)
        {
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "RespondingWithTextSample"));

            resourceExplorer.AddFolder(path);
        }
Ejemplo n.º 11
0
        public static void ClassInitialize(TestContext context)
        {
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "ControllingConversationFlowSample"));

            resourceExplorer.AddFolder(path);
        }