diff --git a/src/OpenTracing.Contrib.NetCore/Internal/PropertyFetcher.cs b/src/OpenTracing.Contrib.NetCore/Internal/PropertyFetcher.cs index a13f76c..a1dd855 100644 --- a/src/OpenTracing.Contrib.NetCore/Internal/PropertyFetcher.cs +++ b/src/OpenTracing.Contrib.NetCore/Internal/PropertyFetcher.cs @@ -1,6 +1,7 @@ // From https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs using System; +using System.Linq; using System.Reflection; namespace OpenTracing.Contrib.NetCore.Internal @@ -28,7 +29,8 @@ public object Fetch(object obj) if (objType != _expectedType) { TypeInfo typeInfo = objType.GetTypeInfo(); - _fetchForExpectedType = PropertyFetch.FetcherForProperty(typeInfo.GetDeclaredProperty(_propertyName)); + var propertyInfo = typeInfo.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, _propertyName, StringComparison.InvariantCultureIgnoreCase)); + _fetchForExpectedType = PropertyFetch.FetcherForProperty(propertyInfo); _expectedType = objType; } return _fetchForExpectedType.Fetch(obj); diff --git a/test/OpenTracing.Contrib.NetCore.Tests/Internal/PropertyFetcherTest.cs b/test/OpenTracing.Contrib.NetCore.Tests/Internal/PropertyFetcherTest.cs new file mode 100644 index 0000000..f6132e5 --- /dev/null +++ b/test/OpenTracing.Contrib.NetCore.Tests/Internal/PropertyFetcherTest.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenTracing.Contrib.NetCore.Internal; +using Xunit; + +namespace OpenTracing.Contrib.NetCore.Tests.Internal +{ + public class PropertyFetcherTest + { + public class TestClass + { + public string TestProperty { get; set; } + } + + [Fact] + public void Fetch_NameNotFound_NullReturned() + { + var obj = new TestClass { TestProperty = "TestValue" }; + + var sut = new PropertyFetcher("DifferentProperty"); + + var result = sut.Fetch(obj); + + Assert.Null(result); + } + + [Fact] + public void Fetch_NameFound_ValueReturned() + { + var obj = new TestClass { TestProperty = "TestValue" }; + + var sut = new PropertyFetcher("TestProperty"); + + var result = sut.Fetch(obj); + + Assert.Equal("TestValue", result); + } + + [Fact] + public void Fetch_NameFoundDifferentCasing_ValueReturned() + { + var obj = new TestClass { TestProperty = "TestValue" }; + + var sut = new PropertyFetcher("testproperty"); + + var result = sut.Fetch(obj); + + Assert.Equal("TestValue", result); + } + } +}