1

I manipulate the rule XML dynamically. Unfortunately, after I create the rule from the XML (RuleModel.Create) the resulting XML (RuleModel.GetRuleXml()) loses the action method name. I am able to workaround the issue by rebinding the rule to the type, but that seems redundant since the type is already a parameter to the Create method.

Here are a couple XUnit tests that illustrate the issue: (CodeEffects Version 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);
        }
    }
}

Wagner DosAnjos
  • 6,304
  • 1
  • 15
  • 29

1 Answers1

0

This issue has been fixed in the latest minor version. Update your NuGet references.

Alex
  • 566
  • 1
  • 6
  • 14
  • The latest version fixed the original issue. Thanks! I noticed a breaking change in the XML namespace though. In the latest version the default namespace changed from `http://codeeffects.com/schemas/rule/41` (http) to `https://codeeffects.com/schemas/rule/41` (https), which broke my code. Is that intentional? – Wagner DosAnjos May 15 '20 at 21:35
  • Yes, it is intentional. How did that change brake your code? – Alex May 17 '20 at 18:32
  • My code needs to know the namespace to generate and read the CodeEffects XML document. It's not a big deal. I just wanted to confirm. Thanks. – Wagner DosAnjos May 18 '20 at 18:30