Skip to content

Commit

Permalink
Make the PropertyFetcher case insensitive (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
markvincze authored and austinlparker committed Aug 21, 2019
1 parent 5d9c340 commit 7f292f6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/OpenTracing.Contrib.NetCore/Internal/PropertyFetcher.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 7f292f6

Please sign in to comment.