Example #1
0
        public void PluginAccessorShouldGetPluginValueIfNotCorrectType()
        {
            var plugin = new Plugin
            {
                Groups = new[]
                {
                    new PluginPropertyGroup
                    {
                        Values = GetGroup(
                            new PluginPropertyValue
                        {
                            Key   = "TestBool",
                            Value = string.Empty
                        },
                            new PluginPropertyValue
                        {
                            Key   = "TestStrBool",
                            Value = "True"
                        })
                    }
                }
            };

            _accessor = PluginPropertiesAccessor.GetInstance(null, plugin, null);
            Assert.IsFalse(_accessor.GetAllPluginPropertyValues <bool>("TestBool").First());
            Assert.IsTrue(_accessor.GetAllPluginPropertyValues <bool>("TestStrBool").First());
        }
Example #2
0
        /// <inheritdoc/>
        public async Task <CognitiveTextAnalysisResult> GetCognitiveTextAnalysisResultAsync(
            TextDeconstructionInformation definition,
            string email)
        {
            var plugins = await GetPluginsAsync();

            foreach (var processor in _commandProcessors)
            {
                if (processor.Subject.Equals(definition.Subject, StringComparison.InvariantCultureIgnoreCase))
                {
                    var plugin = plugins.FirstOrDefault(
                        it => it.ProcessorTypeName.Equals(processor.Name, StringComparison.InvariantCulture));

                    if (plugin.Enabled)
                    {
                        var accessor = PluginPropertiesAccessor.GetInstance(email, plugin, _storageService);
                        return(new CognitiveTextAnalysisResult(
                                   definition,
                                   processor,
                                   accessor));
                    }
                }
            }

            return(null);
        }
Example #3
0
        public void PluginAccessorShouldGetPluginValues()
        {
            var plugin = new Plugin
            {
                Groups = new[]
                {
                    new PluginPropertyGroup
                    {
                        Values = GetGroup(
                            new PluginPropertyValue
                        {
                            Key   = "Test3",
                            Value = "a"
                        },
                            new PluginPropertyValue
                        {
                            Key   = "Test3",
                            Value = "b"
                        })
                    }
                }
            };

            _accessor = PluginPropertiesAccessor.GetInstance(null, plugin, null);
            Assert.AreEqual(2, _accessor.GetAllPluginPropertyValues <string>("Test3").Count);
        }
Example #4
0
        public async Task PluginAccessorShouldGetUserProperty()
        {
            var user = new User
            {
                Properties = new Dictionary <string, PluginPropertyValue[][]>
                {
                    { "A", GetGroup(new PluginPropertyValue {
                            Key = "Test3", Value = "a"
                        }) },
                    { "B", GetGroup(new PluginPropertyValue {
                            Key = "Test3", Value = "b"
                        }) },
                }
            };

            var storageService = Substitute.For <IStorageService>();

            _accessor = PluginPropertiesAccessor.GetInstance("[email protected]", null, storageService);

            storageService.GetUserByEmailAsync("[email protected]").Returns(user);

            var result = await _accessor.GetAllUserPropertyValuesAsync <string>("Test3");

            Assert.AreEqual(2, result.Count);
        }
Example #5
0
        public void PluginAccessorShouldGetPluginGroup()
        {
            var value1 = new PluginPropertyValue();
            var value2 = new PluginPropertyValue();
            var group1 = new PluginPropertyGroup {
                UniqueName = "G1", Values = GetGroup(value1)
            };
            var group2 = new PluginPropertyGroup {
                UniqueName = "G2", Values = GetGroup(value2)
            };
            var plugin = new Plugin {
                Groups = new[] { group1, group2 }
            };

            _accessor = PluginPropertiesAccessor.GetInstance(null, plugin, null);

            var values = _accessor.GetPluginPropertyGroup("G2");

            Assert.AreEqual(1, values.Count);
            Assert.AreEqual(value2, values[0][0]);
        }
Example #6
0
        public void PluginAccessorShouldShouldGetAllPluginValuesIfSomeIsNull()
        {
            var value1 = new PluginPropertyValue {
                Key = "V1", Value = 2
            };
            var group1 = new PluginPropertyGroup {
                UniqueName = "G1", Values = GetGroup(value1)
            };
            var group2 = new PluginPropertyGroup {
                UniqueName = "G2", Values = null
            };
            var plugin = new Plugin {
                Groups = new[] { group1, group2 }
            };

            _accessor = PluginPropertiesAccessor.GetInstance(null, plugin, null);

            var result = _accessor.GetAllPluginPropertyValues <int>("V1");

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2, result[0]);
        }
Example #7
0
 public void PluginAccessorWithPluginWithNoGroupShouldStillReturn()
 {
     _accessor = PluginPropertiesAccessor.GetInstance(null, new Plugin(), null);
     Assert.IsNotNull(_accessor.GetAllPluginPropertyValues <string>("Test"));
     Assert.IsNotNull(_accessor.GetPluginPropertyGroup("Test2"));
 }