Skip to content

Resolves #48 Make the PropertyFetcher case insensitive #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}