jediwhale / fitsharp

Functional testing tools for .NET
http://fitsharp.github.io
Other
152 stars 73 forks source link

Allow for translation of FlowKeywords #168

Closed LodewijkSioen closed 4 years ago

LodewijkSioen commented 4 years ago

We write our specifications in Dutch (since that's what we use). In an older version of fitsharp (2.3.5248), we were able to translate the flowkeywords by making a DoFixture with methods like this;

public void Controleer(Parse theCells)
{
    new FlowKeywords(this, Processor).Check(theCells);
}

In fitsharp 2.7.1, these methods are missing and I can't really find a way to emulate this behaviour. I see that those keyword are pretty locked down in InvokeFlowKeyword.

jediwhale commented 4 years ago

You can write a translator something like this (I haven't tested this code):

using System.Collections.Generic;
using fitSharp.Fit.Engine;
using fitSharp.Fit.Operators;
using fitSharp.Machine.Model;

namespace My.Operators {
    public class KeywordTranslator: CellOperator, InvokeSpecialOperator {
        public bool CanInvokeSpecial(TypedValue instance, MemberName memberName, Tree<Cell> parameters) {
            return translations.ContainsKey(memberName.Name);
        }

        public TypedValue InvokeSpecial(TypedValue instance, MemberName memberName, Tree<Cell> parameters) {
            return new InvokeFlowKeyword {Processor = Processor}
                .InvokeSpecial(instance, new MemberName(translations[memberName.Name]), parameters);
        }

        readonly Dictionary<string, string> translations = new Dictionary<string, string> {
            {"vérifier", "check"}
        };
    }
}

Then add it in suite.config.xml:

<suiteConfig>
   ...
    <Fit.Operators>
        <Add>My.Operators.KeywordTranslator</Add>
    </Fit.Operators>
</suiteConfig>
LodewijkSioen commented 4 years ago

AH, brilliant! We'll try it out and let you know if it worked.

LodewijkSioen commented 4 years ago

Just to let you know that this worked brilliantly. Only the Ignore keyword couldn't work this way, so we kept that in an custom dofixture.

Thanks for the help!