Example #1
0
        public async Task SkillMiddlewarePopulatesSkillContextDifferentDatatypes()
        {
            string jsonSkillBeginActivity = await File.ReadAllTextAsync(@".\TestData\skillBeginEvent.json");

            var skillBeginEvent = JsonConvert.DeserializeObject <Activity>(jsonSkillBeginActivity);

            var skillContextData = new SkillContext();

            skillContextData.Add("PARAM1", DateTime.Now);
            skillContextData.Add("PARAM2", 3);
            skillContextData.Add("PARAM3", null);

            // Ensure we have a copy
            skillBeginEvent.Value = new SkillContext(skillContextData);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new SkillMiddleware(_userState, _conversationState, _dialogStateAccessor));

            var testFlow = new TestFlow(adapter, async(context, cancellationToken) =>
            {
                // Validate that SkillContext has been populated by the SKillMiddleware correctly
                await ValidateSkillContextData(context, skillContextData);
            });

            await testFlow.Test(new Activity[] { skillBeginEvent }).StartTestAsync();
        }
Example #2
0
        //Method that exports the Skill Data Set to .xlsx file
        //When the scheduler clicks the button "Export to .xlsx file"
        //the following method will run and a Skills.xlsx file will be downloaded from the scheduler's browser
        //the file is saved by default in the "Downloads" folder
        public async Task <IActionResult> Excel()
        {
            using (var workbook = new XLWorkbook())
            {
                var worksheet  = workbook.Worksheets.Add("Skills");
                var currentRow = 1;
                worksheet.Cell(currentRow, 1).Value = "Id";
                worksheet.Cell(currentRow, 2).Value = "Name";
                worksheet.Cell(currentRow, 3).Value = "Description";
                worksheet.Cell(currentRow, 4).Value = "Creation Date";
                foreach (var skill in _context.Skill)
                {
                    currentRow++;
                    worksheet.Cell(currentRow, 1).Value = skill.ID;
                    worksheet.Cell(currentRow, 2).Value = skill.Name;
                    worksheet.Cell(currentRow, 3).Value = skill.Description;
                    worksheet.Cell(currentRow, 4).Value = skill.CreationDate;
                }

                using (var stream = new System.IO.MemoryStream())
                {
                    workbook.SaveAs(stream);
                    var content = stream.ToArray();


                    HistoryLog newlog = new HistoryLog();

                    newlog.EventDescription = "Skills DataSet exported to Skills.xlsx file.";
                    newlog.EventDateTime    = DateTime.Now;

                    _context.Add(newlog);
                    await _context.SaveChangesAsync();

                    return(File(
                               content,
                               "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                               "Skills.xlsx"));
                }
            }
        }
Example #3
0
        public async Task SkillInvocationWithSlotsTest()
        {
            var sp      = Services.BuildServiceProvider();
            var adapter = sp.GetService <TestAdapter>();

            var     slots  = new SkillContext();
            dynamic entity = new { key1 = "TEST1", key2 = "TEST2" };

            slots.Add("param1", JObject.FromObject(entity));

            await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithslots"), "testSkill/testActionWithSlots", slots)
            .Send("hello")
            .StartTestAsync();

            _mockSkillTransport.VerifyActivityForwardedCorrectly(activity =>
            {
                var semanticAction = activity.SemanticAction;
                Assert.AreEqual(semanticAction.Entities["param1"].Properties["key1"], "TEST1");
                Assert.AreEqual(semanticAction.Entities["param1"].Properties["key2"], "TEST2");
            });
        }
Example #4
0
        public async Task SkillInvocationNoActionPassed()
        {
            var sp      = Services.BuildServiceProvider();
            var adapter = sp.GetService <TestAdapter>();

            var     slots  = new SkillContext();
            dynamic entity = new { key1 = "TEST1", key2 = "TEST2" };

            slots.Add("param1", JObject.FromObject(entity));

            // Not passing action to test the "global" slot filling behaviour
            await this.GetTestFlow(_skillManifests.Single(s => s.Name == "testskillwithmultipleactionsandslots"), null, slots)
            .Send("hello")
            .StartTestAsync();

            _mockSkillTransport.VerifyActivityForwardedCorrectly(activity =>
            {
                var semanticAction = activity.SemanticAction;
                Assert.AreEqual(semanticAction.Entities["param1"].Properties["key1"], "TEST1");
                Assert.AreEqual(semanticAction.Entities["param1"].Properties["key2"], "TEST2");
            });
        }
Example #5
0
 public void AddSkill(Skill skill)
 {
     _dbContext.Add(skill);
     Save();
 }