[英]How to shim XmlAttribute using Microsoft Fakes in VS 2013
I have the below code I am testing. 我有以下代码正在测试。
public Loader(XmlAttributeCollection attributes)
{
if (attributes == (XmlAttributeCollection)null)
throw new ArgumentNullException("attributes");
foreach (XmlAttribute attribute in attributes)
{
if (attribute.Name.Equals("name", StringComparison.OrdinalIgnoreCase))
{
name = attribute.Value;
}
else if (attribute.Name.Equals("type", StringComparison.OrdinalIgnoreCase))
{
loaderType = attribute.Value;
}
else
{
loaderAttributes.Add(attribute.Name, attribute.Value);
}
}
}
Is that possible to shim the attribute/attributecollection so that I can return whichever the attribute object I want to return ? 是否可以填充属性/属性集合,以便我可以返回要返回的任何属性对象?
For example I want to return two xmlattribute objects one with attribute name of "name" and another one as "type" and also their respective values . 例如,我想返回两个xmlattribute对象,一个对象的属性名称为“ name”,另一个对象为“ type”,以及它们各自的值。
What I meant is something like below shim statement where instead of returning null , can I return an xmlattribute object with name and value ? 我的意思是类似下面的shim语句,在这里我可以返回带有名称和值的xmlattribute对象,而不是返回null?
ShimXmlAttributeCollection.AllInstances.ItemOfGetInt32 = (x, y) =>
{
return null;
};
Here is the sample xml I have. 这是我的示例XML。
<add name=\"console\" type=\"DefaultTraceLoader\" value=\"Error\"/>
You could: 你可以:
var xml = new XmlDocument();
xml.LoadXml("<add name=\"console\" type=\"DefaultTraceLoader\" value=\"Error\"/>");
var enumerator = xml.DocumentElement.Attributes.GetEnumerator();
BEFORE setting the ShimXmlNamedNodeMap.AllInstances.GetEnumerator
. 在设置
ShimXmlNamedNodeMap.AllInstances.GetEnumerator
之前。
ShimXmlNamedNodeMap.AllInstances.GetEnumerator = x =>
{
return enumerator;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.