mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 00:38:28 +02:00
Add MatchOperator "Or", "And" and "Average" for patterns (#755)
* wip * ... * . * ... * ... * path * url * b * t * client * . * RequestMessageMethodMatcherTests * . * h * . * fix tests * .
This commit is contained in:
@@ -1,70 +1,69 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
public static class TestUtils
|
||||
{
|
||||
public static class TestUtils
|
||||
public static T GetPrivateFieldValue<T>(this object obj, string fieldName)
|
||||
{
|
||||
public static T GetPrivateFieldValue<T>(this object obj, string fieldName)
|
||||
{
|
||||
var field = obj.GetType().GetTypeInfo().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var field = obj.GetType().GetTypeInfo().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
return (T)field.GetValue(obj);
|
||||
return (T)field.GetValue(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a _private_ Field Value on a given Object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the Property</typeparam>
|
||||
/// <param name="obj">Object from where the Property Value is returned</param>
|
||||
/// <param name="propertyName">Property name as string.</param>
|
||||
/// <param name="value">the value to set</param>
|
||||
public static void SetPrivateFieldValue<T>(this object obj, string propertyName, T value)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a _private_ Field Value on a given Object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the Property</typeparam>
|
||||
/// <param name="obj">Object from where the Property Value is returned</param>
|
||||
/// <param name="propertyName">Property name as string.</param>
|
||||
/// <param name="value">the value to set</param>
|
||||
public static void SetPrivateFieldValue<T>(this object obj, string propertyName, T value)
|
||||
Type t = obj.GetType();
|
||||
FieldInfo fi = null;
|
||||
while (fi == null && t != null)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
Type t = obj.GetType();
|
||||
FieldInfo fi = null;
|
||||
while (fi == null && t != null)
|
||||
{
|
||||
fi = t.GetField(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
t = t.BaseType;
|
||||
}
|
||||
|
||||
if (fi == null)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(propertyName), $"Field {propertyName} was not found in Type {obj.GetType().FullName}");
|
||||
}
|
||||
|
||||
fi.SetValue(obj, value);
|
||||
fi = t.GetField(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
t = t.BaseType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a _private_ Property Value from a given Object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the Property</typeparam>
|
||||
/// <param name="obj">Object from where the Property Value is set</param>
|
||||
/// <param name="propertyName">Property name as string.</param>
|
||||
/// <param name="value">Value to set.</param>
|
||||
public static void SetPrivatePropertyValue<T>(this object obj, string propertyName, T value)
|
||||
if (fi == null)
|
||||
{
|
||||
Type t = obj.GetType();
|
||||
PropertyInfo propertyInfo = null;
|
||||
while (propertyInfo == null && t != null)
|
||||
{
|
||||
propertyInfo = t.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
t = t.BaseType;
|
||||
}
|
||||
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(propertyName), $"Private property {propertyName} was not found in Type {obj.GetType().FullName}");
|
||||
}
|
||||
|
||||
propertyInfo.SetValue(obj, value);
|
||||
throw new ArgumentOutOfRangeException(nameof(propertyName), $"Field {propertyName} was not found in Type {obj.GetType().FullName}");
|
||||
}
|
||||
|
||||
fi.SetValue(obj, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a _private_ Property Value from a given Object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the Property</typeparam>
|
||||
/// <param name="obj">Object from where the Property Value is set</param>
|
||||
/// <param name="propertyName">Property name as string.</param>
|
||||
/// <param name="value">Value to set.</param>
|
||||
public static void SetPrivatePropertyValue<T>(this object obj, string propertyName, T value)
|
||||
{
|
||||
Type? t = obj.GetType();
|
||||
PropertyInfo? propertyInfo = null;
|
||||
while (propertyInfo == null && t != null)
|
||||
{
|
||||
propertyInfo = t.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
t = t.BaseType;
|
||||
}
|
||||
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(propertyName), $"Private property {propertyName} was not found in Type {obj.GetType().FullName}");
|
||||
}
|
||||
|
||||
propertyInfo.SetValue(obj, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user