public void TestInitialize()
        {
            _tableClientService = Substitute.For <ITableClientService>();

            _storageService = new TableStorageService(_tableClientService);
            _tableClientService.IsConnected.Returns(true);

            _users = new List <User>
            {
                new User {
                    Id = "3C039142-CF1A-42CC-87E8-893D8791D4A9", PartitionKey = "47157C92-9836-47CE-83DD-00F32D197BCE", OpenAirUserId = 1
                },
                new User {
                    Id = "C32EC69C-977C-4C42-B84E-13E51195FE6D", PartitionKey = "47157C92-9836-47CE-83DD-00F32D197BCE", OpenAirUserId = 2
                },
                new User {
                    Id = "7408FCFA-6F55-4824-A192-A88D7C12FECE", PartitionKey = "47157C92-9836-47CE-83DD-00F32D197BCE", OpenAirUserId = 3
                },
            };

            _addresses = new List <GoogleAddress>
            {
                new GoogleAddress {
                    Id = "01BE6A6F-821B-465B-B2D9-7621C0A1C55B", PartitionKey = "5DF2E025-E886-43CE-A389-6A0DB9B74083", SpaceName = "Space 1", UserName = "******"
                },
                new GoogleAddress {
                    Id = "C5BAA1D5-7C96-4899-B15A-B846D98975D9", PartitionKey = "5DF2E025-E886-43CE-A389-6A0DB9B74083", SpaceName = "Space 1", UserName = "******"
                },
                new GoogleAddress {
                    Id = "F25E143F-67CD-40D4-A311-3A224E48A40C", PartitionKey = "5DF2E025-E886-43CE-A389-6A0DB9B74083", SpaceName = "Space 1", UserName = "******"
                }
            };

            _messages = new List <Message>
            {
                new Message {
                    Id = "01BE6A6F-821B-465B-B2D9-7621C0A1C55B", PartitionKey = "5DF2E025-E886-43CE-A389-6A0DB9B74083", Input = "question 1", Output = new ChatEventResult("text 1"), ProbabilityPercentage = 65
                },
                new Message {
                    Id = "C5BAA1D5-7C96-4899-B15A-B846D98975D9", PartitionKey = "5DF2E025-E886-43CE-A389-6A0DB9B74083", Input = "question 2", Output = new ChatEventResult("text 2"), ProbabilityPercentage = 76
                },
                new Message {
                    Id = "F25E143F-67CD-40D4-A311-3A224E48A40C", PartitionKey = "5DF2E025-E886-43CE-A389-6A0DB9B74083", Input = "question 3", Output = new ChatEventResult("text 3"), ProbabilityPercentage = 98
                }
            };

            _settings = new MentorBotSettings
            {
                Processors = new List <ProcessorSettings>
                {
                    new ProcessorSettings {
                        Name = "Processor 1", Enabled = true
                    },
                    new ProcessorSettings {
                        Name = "Processor 2", Enabled = false
                    }
                }
            };
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <bool> SaveSettingsAsync(MentorBotSettings settings)
        {
            if (!_tableClientService.IsConnected)
            {
                return(false);
            }

            await _tableClientService.MergeOrInsertAsync(settings);

            return(true);
        }
Exemplo n.º 3
0
        public static async Task SaveSettingsAsync(
            [HttpTrigger(AuthorizationLevel.Function, nameof(HttpMethod.Post), nameof(HttpMethod.Options), Route = null)] HttpRequest req)
        {
            ServiceLocator.EnsureServiceProvider();

            var storageService = ServiceLocator.Get <IStorageService>();

            ServiceLocator.Get <IMemoryCache>().Remove(Constants.SettingsCacheKey);

            var settings = new MentorBotSettings
            {
                Processors = await GetBodyAsync(req),
            };

            await storageService.SaveSettingsAsync(settings);
        }
Exemplo n.º 4
0
        public async Task CognitiveService_ProcessShouldReturnActiveProcessor()
        {
            var processor1 = Substitute.For <ICommandProcessor>();
            var processor2 = Substitute.For <ICommandProcessor>();
            var chatEvent  = GetChatEvent("@mentorbot Get My Processor. ");
            var info       = new TextDeconstructionInformation(null, "My");
            var settings   = new MentorBotSettings
            {
                Processors = new[]
                {
                    new ProcessorSettings
                    {
                        Name    = "Processor 1",
                        Enabled = false
                    },
                    new ProcessorSettings
                    {
                        Name    = "Processor 2",
                        Enabled = true,
                        Data    = new[] { new KeyValuePair <string, string>("K", "") }
                    }
                }
            };

            _commandProcessors.Add(processor1);
            _commandProcessors.Add(processor2);

            processor1.Subject.Returns("My");
            processor2.Subject.Returns("My");
            processor1.Name.Returns("Processor 1");
            processor2.Name.Returns("Processor 2");

            _connector.DeconstructAsync("Get My Processor").Returns(info);

            _cache.TryGetValue(Constants.SettingsCacheKey, out Arg.Any <object>())
            .Returns(x =>
            {
                x[1] = settings;
                return(true);
            });

            var result = await _service.ProcessAsync(chatEvent);

            Assert.AreEqual(result.TextDeconstructionInformation, info);
            Assert.AreEqual(result.CommandProcessor.Name, "Processor 2");
            Assert.AreEqual(result.Settings.Count, 1);
        }
Exemplo n.º 5
0
 /// <inheritdoc/>
 public Task <bool> SaveSettingsAsync(MentorBotSettings settings) =>
 ExecuteIfConnectedAsync <MentorBotSettings, bool>(doc => doc.AddOrUpdateAsync(settings), SettingsDocumentName, false);