从 XML 实例化规则后,元素 <method> 的 GetRuleXml() 方法名称不正确
Element <method> has the incorrect method name from GetRuleXml() after instantiating rule from XML
我动态地操纵规则 XML。不幸的是,在我从 XML (RuleModel.Create
) 创建规则后,生成的 XML (RuleModel.GetRuleXml()
) 丢失了操作方法名称。我可以通过将规则重新绑定到类型来解决这个问题,但这似乎是多余的,因为类型已经是 Create 方法的参数。
这里有几个 XUnit 测试可以说明这个问题:(CodeEffects 版本 5.0.10.2)
using System;
using CodeEffects.Rule.Attributes;
using CodeEffects.Rule.Models;
using Xunit;
namespace ReproSteps
{
public class ReproTests
{
[Fact]
public void Should_succeed_but_fails()
{
// Arrange
var rule = RuleModel.Create(ExecutionRuleXml, typeof(ReproType));
rule.IsValid();
// Act
var ruleXml = rule.GetRuleXml();
// Assert
// Expected XML should contain: <method name="MyAction">
// Actual XML contains: <method name="326589FDEC894FF5693EC37EB78FC387">
Assert.Contains("MyAction", ruleXml);
}
[Fact]
public void Should_succeed_with_rebind()
{
// Arrange
var rule = RuleModel.Create(ExecutionRuleXml, typeof(ReproType));
rule.BindSource(typeof(ReproType)); // this forces the correct method name in the XML
rule.IsValid();
// Act
var ruleXml = rule.GetRuleXml();
// Assert
Assert.Contains("MyAction", ruleXml);
}
private const string ExecutionRuleXml = @"<?xml version=""1.0"" encoding=""utf-8""?><codeeffects xmlns=""http://codeeffects.com/schemas/rule/41"" xmlns:ui=""http://codeeffects.com/schemas/ui/4""><rule id=""__ruleid__"" webrule=""5.0.10.2"" utc=""2020-04-24T20:09:50.5568"" type=""ReproSteps.ReproType, ReproSteps.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" eval=""false""><name>__rule_name__</name><definition><if><clause><condition type=""equal""><property name=""MyProperty"" /><value type=""string"">A</value></condition></clause><then><method name=""MyAction""><value type=""System.Int32"">1</value></method></then></if></definition><format><lines/></format></rule></codeeffects>";
}
public class ReproType
{
public string MyProperty { get; set; }
[Action]
public void MyAction(int p)
{
Console.WriteLine(p);
}
}
}
此问题已在最新的次要版本中修复。更新您的 NuGet 引用。
我动态地操纵规则 XML。不幸的是,在我从 XML (RuleModel.Create
) 创建规则后,生成的 XML (RuleModel.GetRuleXml()
) 丢失了操作方法名称。我可以通过将规则重新绑定到类型来解决这个问题,但这似乎是多余的,因为类型已经是 Create 方法的参数。
这里有几个 XUnit 测试可以说明这个问题:(CodeEffects 版本 5.0.10.2)
using System;
using CodeEffects.Rule.Attributes;
using CodeEffects.Rule.Models;
using Xunit;
namespace ReproSteps
{
public class ReproTests
{
[Fact]
public void Should_succeed_but_fails()
{
// Arrange
var rule = RuleModel.Create(ExecutionRuleXml, typeof(ReproType));
rule.IsValid();
// Act
var ruleXml = rule.GetRuleXml();
// Assert
// Expected XML should contain: <method name="MyAction">
// Actual XML contains: <method name="326589FDEC894FF5693EC37EB78FC387">
Assert.Contains("MyAction", ruleXml);
}
[Fact]
public void Should_succeed_with_rebind()
{
// Arrange
var rule = RuleModel.Create(ExecutionRuleXml, typeof(ReproType));
rule.BindSource(typeof(ReproType)); // this forces the correct method name in the XML
rule.IsValid();
// Act
var ruleXml = rule.GetRuleXml();
// Assert
Assert.Contains("MyAction", ruleXml);
}
private const string ExecutionRuleXml = @"<?xml version=""1.0"" encoding=""utf-8""?><codeeffects xmlns=""http://codeeffects.com/schemas/rule/41"" xmlns:ui=""http://codeeffects.com/schemas/ui/4""><rule id=""__ruleid__"" webrule=""5.0.10.2"" utc=""2020-04-24T20:09:50.5568"" type=""ReproSteps.ReproType, ReproSteps.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" eval=""false""><name>__rule_name__</name><definition><if><clause><condition type=""equal""><property name=""MyProperty"" /><value type=""string"">A</value></condition></clause><then><method name=""MyAction""><value type=""System.Int32"">1</value></method></then></if></definition><format><lines/></format></rule></codeeffects>";
}
public class ReproType
{
public string MyProperty { get; set; }
[Action]
public void MyAction(int p)
{
Console.WriteLine(p);
}
}
}
此问题已在最新的次要版本中修复。更新您的 NuGet 引用。