Skip to content

Instantly share code, notes, and snippets.

@avanderhoorn
Created October 8, 2015 18:43
Show Gist options
  • Save avanderhoorn/f0106bca8be1a33acd37 to your computer and use it in GitHub Desktop.
Save avanderhoorn/f0106bca8be1a33acd37 to your computer and use it in GitHub Desktop.
Testing edge cases for casing of params/properties
public class ProxyMethodEmitterTest
{
public class TargetClass
{
public void TargetMethod(string name, int age)
{
Name = name;
Age = age;
}
public string Name { get; set; }
public int Age { get; set; }
}
[Fact]
public void CanCreateProxyMethodForBasicType()
{
// Arrange
var target = new TargetClass();
var source = new { name = "John", age = 1234 };
var targetMethodInfo = target.GetType().GetMethod(nameof(TargetClass.TargetMethod));
// Act
var adapter = new ProxyTelemetrySourceMethodAdapter();
var callback = adapter.Adapt(targetMethodInfo, source.GetType());
var result = callback(target, source);
// Assert
Assert.True(result);
Assert.Equal(target.Name, source.name);
Assert.Equal(target.Age, source.age);
}
public class TargetClassUpperCase
{
public void TargetMethod(string Name, int Age)
{
SafeName = Name;
SafeAge = Age;
}
public string SafeName { get; set; }
public int SafeAge { get; set; }
}
[Fact]
public void CanCreateProxyMethodForBasicTypeWithUpperCasing()
{
// Arrange
var target = new TargetClassUpperCase();
var source = new { Name = "John", Age = 1234 };
var targetMethodInfo = target.GetType().GetMethod(nameof(TargetClassUpperCase.TargetMethod));
// Act
var adapter = new ProxyTelemetrySourceMethodAdapter();
var callback = adapter.Adapt(targetMethodInfo, source.GetType());
var result = callback(target, source);
// Assert
Assert.True(result);
Assert.Equal(target.SafeName, source.Name);
Assert.Equal(target.SafeAge, source.Age);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment