public void LoadInstanceReturnsNullGivenEmptyXmlElementForReferenceType() { var definition = new XElement("Definition"); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(string), "Test Value"); Assert.Null(instance); }
public void LoadInstanceReturnsOriginalValueGivenNullXmlElement() { var original = "Test Value"; object loaded = TestableTelemetryConfigurationFactory.LoadInstance(null, original.GetType(), original); Assert.Same(original, loaded); }
public void LoadInstanceConvertsValueToExpectedTypeGivenXmlDefinitionWithNoChildElements() { var definition = new XElement("Definition", "42"); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(int), null); Assert.Equal(42, instance); }
public void LoadInstanceReturnsInstanceOfTypeSpecifiedInTypeAttributeOfGivenXmlDefinition() { var definition = new XElement("Definition", new XAttribute("Type", typeof(StubClassWithProperties).AssemblyQualifiedName)); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), null); Assert.Equal(typeof(StubClassWithProperties), instance.GetType()); }
public void LoadInstanceReturnsDefaultValueGivenValueEmptyXmlElementForValueType() { var definition = new XElement("Definition"); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(int), 12); Assert.Equal(0, instance); }
public void LoadInstanceThrowsInvalidOperationExceptionWhenDefinitionElementDoesNotHaveTypeAttributeAndInstanceIsNotInitialized() { var elementWithoutType = new XElement("Add", new XElement("PropertyName")); var exception = Assert.Throws <InvalidOperationException>(() => TestableTelemetryConfigurationFactory.LoadInstance(elementWithoutType, typeof(IComparable), null)); Assert.Contains(elementWithoutType.Name.ToString(), exception.Message, StringComparison.OrdinalIgnoreCase); Assert.Contains("Type", exception.Message, StringComparison.OrdinalIgnoreCase); }
public void LoadInstanceTrimsValueOfGivenXmlElementToIgnoreWhitespaceUsersMayAddToConfiguration() { string expected = Guid.NewGuid().ToString(); var definition = new XElement("InstrumentationKey", "\n" + expected + "\n"); object actual = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(string), null); Assert.Equal(expected, actual); }
public void LoadInstanceSetsInstancePropertiesOfTimeSpanTypeFromChildElementValuesOfDefinitionWithInvalidFormatThrowsException() { var definition = new XElement( "Definition", new XAttribute("Type", typeof(StubClassWithProperties).AssemblyQualifiedName), new XElement("TimeSpanProperty", "TestValue")); Assert.Throws <FormatException>(() => TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), null)); }
public void LoadInstanceThrowsInvalidOperationExceptionWhenDefinitionElementContainsInvalidContentAndNoTypeAttribute() { var definition = new XElement("InvalidElement", "InvalidText"); var exception = Assert.Throws <InvalidOperationException>( () => TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(ITelemetryChannel), null)); Assert.Contains("InvalidElement", exception.Message, StringComparison.OrdinalIgnoreCase); Assert.Contains("InvalidText", exception.Message, StringComparison.OrdinalIgnoreCase); Assert.NotNull(exception.InnerException); }
public void LoadInstanceCreatesNewInstanceOfExpectedTypeWhenPropertiesAreSpecifiedOnlyAsAttributes() { var definition = new XElement("Definition", new XAttribute("Int32Property", 42)); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), null); var loaded = Assert.IsType <StubClassWithProperties>(instance); Assert.Equal(42, loaded.Int32Property); }
public void LoadInstanceHandlesEnumPropertiesWithEnumerationValueName() { var definition = new XElement( "Definition", new XElement("EnumProperty", "Informational")); var original = new StubClassWithProperties(); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), original, null); Assert.Equal(System.Diagnostics.Tracing.EventLevel.Informational, original.EnumProperty); }
public void LoadInstanceSetsInstancePropertiesOfTimeSpanTypeFromChildElementValuesOfDefinitionWithOneInteger() { var definition = new XElement( "Definition", new XAttribute("Type", typeof(StubClassWithProperties).AssemblyQualifiedName), new XElement("TimeSpanProperty", "7")); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), null); Assert.Equal(TimeSpan.FromDays(7), ((StubClassWithProperties)instance).TimeSpanProperty); }
public void LoadInstanceSetsInstancePropertiesFromChildElementValuesOfDefinition() { var definition = new XElement( "Definition", new XAttribute("Type", typeof(StubClassWithProperties).AssemblyQualifiedName), new XElement("StringProperty", "TestValue")); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), null); Assert.Equal("TestValue", ((StubClassWithProperties)instance).StringProperty); }
public void LoadInstanceInitializesGivenInstanceAndDoesNotRequireSpecifyingTypeAttributeToSimplifyConfiguration() { var definition = new XElement( "Definition", new XElement("StringProperty", "TestValue")); var original = new StubClassWithProperties(); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), original); Assert.Equal("TestValue", original.StringProperty); }
public void LoadInstanceHandlesEnumPropertiesWithNumericValue() { var definition = new XElement( "Definition", new XElement("EnumProperty", "3")); var original = new StubClassWithProperties(); object instance = TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(StubClassWithProperties), original, null); Assert.Equal(EventLevel.Warning, original.EnumProperty); }
public void LoadInstanceReturnsNullWhenDefinitionElementDoesNotHaveTypeAttributeAndInstanceIsNotInitialized() { var elementWithoutType = new XElement("Add", new XElement("PropertyName")); Assert.Null(TestableTelemetryConfigurationFactory.LoadInstance(elementWithoutType, typeof(IComparable), null, null)); }
public void LoadInstanceReturnsNullWhenDefinitionElementContainsInvalidContentAndNoTypeAttribute() { var definition = new XElement("InvalidElement", "InvalidText"); Assert.Null(TestableTelemetryConfigurationFactory.LoadInstance(definition, typeof(ITelemetryChannel), null, null)); }