Пример #1
0
        public void LoadInstancesPopulatesListWithInstancesOfSpecifiedType()
        {
            var element   = XElement.Parse(@"
                <List xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
                    <Add Type=""" + typeof(StubTelemetryInitializer).AssemblyQualifiedName + @""" />           
                </List>");
            var instances = new List <ITelemetryInitializer>();

            TestableTelemetryConfigurationFactory.LoadInstances(element, instances);

            Assert.Equal(1, instances.Count);
            Assert.Equal(typeof(StubTelemetryInitializer), instances[0].GetType());
        }
Пример #2
0
        public void LoadInstancesIgnoresElementsOtherThanAdd() // TODO: Why? This is inconsistent with property loading, which throws InvalidOperationException.
        {
            var definition = XElement.Parse(@"
                <List xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
                    <Unknown/>
                    <Add>42</Add>
                </List>");

            var instances = new List <int>();

            Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadInstances(definition, instances));

            Assert.Equal(new[] { 42 }, instances);
        }
Пример #3
0
        public void LoadInstancesPopulatesListWithPrimitiveValues()
        {
            var definition = XElement.Parse(@"
                <List xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
                    <Add>41</Add>
                    <Add>42</Add>
                </List>");

            var instances = new List <int>();

            TestableTelemetryConfigurationFactory.LoadInstances(definition, instances);

            Assert.Equal(new[] { 41, 42 }, instances);
        }
        public void LoadInstancesIgnoresElementsOtherThanAdd()
        {
            var definition = XElement.Parse(@"
                <List xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
                    <Unknown/>
                    <Add>42</Add>
                </List>");

            var instances = new List <int>();

            Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadInstances(definition, instances, null));

            Assert.Equal(new[] { 42 }, instances);
        }
Пример #5
0
        public void LoadInstancesUpdatesInstanceWithMatchingType() // TODO: Why? This is inconsistent with the name of the element, Add.
        {
            var configuration = new TelemetryConfiguration();
            var element       = XElement.Parse(@"
                <List xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
                    <Add Type=""" + typeof(StubConfigurableWithProperties).AssemblyQualifiedName + @""" > 
                        <Int32Property>77</Int32Property>
                    </Add>
                </List>");

            var configurableElement = new StubConfigurableWithProperties(configuration);
            var instances           = new List <object>();

            instances.Add(configurableElement);

            TestableTelemetryConfigurationFactory.LoadInstances(element, instances);

            var telemetryModules = instances.OfType <StubConfigurableWithProperties>().ToArray();

            Assert.Equal(1, telemetryModules.Count());
            Assert.Equal(configurableElement, telemetryModules[0]);
            Assert.Equal(77, configurableElement.Int32Property);
        }