Created
October 19, 2010 17:25
-
-
Save scottwater/634610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IEnumerable<AuditParameter> GetParametersFromEnumeration(IEnumerable args) | |
{ | |
var parameters = new List<AuditParameter>(); | |
foreach(var arg in args) | |
{ | |
var iaudit = arg as IAuditableParameter; | |
if(iaudit != null) | |
{ | |
parameters.Add(new AuditParameter {Value = iaudit.AuditParameter}); | |
continue; | |
} | |
if (arg.GetType() != typeof(string)) | |
{ | |
var enumeration = arg as IEnumerable; | |
if (enumeration != null) | |
{ | |
parameters.AddRange(GetParametersFromEnumeration(enumeration)); | |
continue; | |
} | |
} | |
parameters.Add(new AuditParameter {Value = arg.ToString()}); | |
} | |
return parameters; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Can_I_Handle_Enumerations() | |
{ | |
var method = GetType().GetMethod("DummyEnumeration"); | |
var details = new MethodDetails(method, new object[]{ new[] { "scott", "was", "here" }}); | |
var entry = AuditEntry.FromMethodExecutionArgs(3, details); | |
Assert.IsTrue(entry.Parameters.Count == 3); | |
Assert.IsTrue(entry.Parameters[0].Value == "scott"); | |
Assert.IsTrue(entry.Parameters[1].Value == "was"); | |
Assert.IsTrue(entry.Parameters[2].Value == "here"); | |
} | |
[Test] | |
public void Can_I_Handle_Deep_Nesting() | |
{ | |
var method = GetType().GetMethod("DummyEnumeration"); | |
var objects = new object[4]; | |
objects[0] = new[] {"scott", "was", "here"}; | |
objects[1] = new[] {"another", "string"}; | |
objects[2] = true; | |
objects[3] = new[] {1, 2, 3, 4}; //for now, we are going to skip arrays of value types | |
var details = new MethodDetails(method,objects); | |
var entry = AuditEntry.FromMethodExecutionArgs(3, details); | |
Assert.IsTrue(entry.Parameters.Count == 7, "Expected 7 parameters, but found {0}", entry.Parameters.Count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment