public void LoadPropertiesDoesNotAttemptToSetReadOnlyProperty() { XElement definition = XDocument.Parse(Configuration(@"<TelemetryModules/>")).Root; var instance = new TelemetryConfiguration(); Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadProperties(definition, instance)); }
public void LoadPropertiesIgnoresUnknownTelemetryConfigurationPropertiesToAllowStatusMonitorDefineItsOwnSections() { string configuration = Configuration("<UnknownSection/>"); XElement aplicationInsightsElement = XDocument.Parse(configuration).Root; Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadProperties(aplicationInsightsElement, new TelemetryConfiguration())); }
public void LoadPropertiesIgnoresNamespaceDeclarationWhenLoadingFromAttributes() { var definition = new XElement("Definition", new XAttribute("xmlns", "http://somenamespace")); var instance = new StubClassWithProperties(); Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadProperties(definition, instance)); }
public void LoadPropertiesInstantiatesObjectOfTypeSpecifiedInTypeAttribute() { var definition = new XElement("Definition", new XElement("ChildProperty", new XAttribute("Type", typeof(StubClassWithProperties).AssemblyQualifiedName))); var instance = new StubClassWithProperties(); TestableTelemetryConfigurationFactory.LoadProperties(definition, instance); Assert.Equal(typeof(StubClassWithProperties), instance.ChildProperty.GetType()); }
public void LoadPropertiesThrowsInvalidOperationExceptionWhenInstanceDoesNotHavePropertyWithSpecifiedName() { var definition = new XElement("Definition", new XElement("InvalidProperty", "AnyValue")); var exception = Assert.Throws <InvalidOperationException>( () => TestableTelemetryConfigurationFactory.LoadProperties(definition, new StubClassWithProperties())); Assert.Contains("InvalidProperty", exception.Message, StringComparison.OrdinalIgnoreCase); Assert.Contains(typeof(StubClassWithProperties).AssemblyQualifiedName, exception.Message, StringComparison.OrdinalIgnoreCase); }
public void LoadPropertiesGivesPrecedenceToValuesFromElementsBecauseTheyAppearBelowAttributes() { var definition = new XElement("Definition", new XAttribute("Int32Property", "41"), new XElement("Int32Property", "42")); var instance = new StubClassWithProperties(); TestableTelemetryConfigurationFactory.LoadProperties(definition, instance); Assert.Equal(42, instance.Int32Property); }
public void LoadPropertiesLoadsPropertiesFromAttributes() { var definition = new XElement("Definition", new XAttribute("Int32Property", "42")); var instance = new StubClassWithProperties(); TestableTelemetryConfigurationFactory.LoadProperties(definition, instance); Assert.Equal(42, instance.Int32Property); }
public void LoadPropertiesConvertsPropertyValuesFromStringToPropertyType() { var definition = new XElement("Definition", new XElement("Int32Property", "42")); var instance = new StubClassWithProperties(); TestableTelemetryConfigurationFactory.LoadProperties(definition, instance); Assert.Equal(42, instance.Int32Property); }
private static TelemetryConfiguration CreateTelemetryConfigurationWithDeveloperModeValue(string developerModeValue) { XElement definition = XDocument.Parse(Configuration( @"<TelemetryChannel Type=""Microsoft.ApplicationInsights.TestFramework.StubTelemetryChannel, Microsoft.ApplicationInsights.TestFramework""> <DeveloperMode>" + developerModeValue + @"</DeveloperMode> </TelemetryChannel>")).Root; var instance = new TelemetryConfiguration(); Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadProperties(definition, instance)); return(instance); }
private static TelemetryConfiguration CreateTelemetryConfigurationWithDeveloperModeValue(string developerModeValue) { XElement definition = XDocument.Parse(Configuration( @"<TelemetryChannel Type=""" + typeof(StubTelemetryChannel).AssemblyQualifiedName + @"""> <DeveloperMode>" + developerModeValue + @"</DeveloperMode> </TelemetryChannel>")).Root; var instance = new TelemetryConfiguration(); Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadProperties(definition, instance, null)); return(instance); }
public void LoadPropertiesRecursivelyLoadsInstanceSpecifiedByTypeAttribute() { var definition = new XElement( "Definition", new XElement( "ChildProperty", new XAttribute("Type", typeof(StubClassWithProperties).AssemblyQualifiedName), new XElement("StringProperty", "TestValue"))); var instance = new StubClassWithProperties(); TestableTelemetryConfigurationFactory.LoadProperties(definition, instance); Assert.Equal("TestValue", instance.ChildProperty.StringProperty); }
public void LoadPropertiesReturnsNullWhenInstanceDoesNotHavePropertyWithSpecifiedName() { var definition = new XElement("Definition", new XElement("InvalidProperty", "AnyValue")); Assert.DoesNotThrow(() => TestableTelemetryConfigurationFactory.LoadProperties(definition, new StubClassWithProperties(), null)); }