jediwhale / fitsharp

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

Unable to access Symbols from the fixture #123

Closed sergebug closed 9 years ago

sergebug commented 10 years ago

According to the SymbolValues.html Following code could be used to access Symbols:

if (Symbols.HasValue("stuff")) {
        var mySymbol = Symbols.GetValue("stuff);
    }
    Symbols.Save("another") = "one";

However when I try to use code from above inside my fixture I get exceptions in the test response.

System.InvalidOperationException: Method may only be called on a Type for which Type.IsGenericParameter is true.
   at System.RuntimeType.get_GenericParameterPosition()
   --- End of inner exception stack trace ---
   at fitSharp.Machine.Model.TypedValue.ThrowExceptionIfNotValid() in c:\Projects\3rdparty.src\fitsharp-master\source\fitSharp\Machine\Model\TypedValue.cs:line 66
   at fitSharp.Slim.Operators.InvokeInstructionBase.InvokeMember(Tree`1 parameters, Int32 memberIndex) in c:\Projects\3rdparty.src\fitsharp-master\source\fitSharp\Slim\Operators\InvokeInstructionBase.cs:line 65
   at fitSharp.Slim.Operators.ExecuteCall.ExecuteOperation(Tree`1 parameters) in c:\Projects\3rdparty.src\fitsharp-master\source\fitSharp\Slim\Operators\ExecuteCall.cs:line 13
   at fitSharp.Slim.Operators.InvokeInstructionBase.Invoke(TypedValue instance, MemberName memberName, Tree`1 parameters) in c:\Projects\3rdparty.src\fitsharp-master\source\fitSharp\Slim\Operators\InvokeInstructionBase.cs:line 23

My Fixture class looks as following:

    public class SymbolEvaluatorFixture : DoFixture
    {
        private Regex symbolPattern;

        public SymbolEvaluatorFixture()
        {
            this.setPattern(@"\$\{(\w*)\}");
        }
        public void setPattern(string pattern)
        {
            this.symbolPattern = new Regex(pattern);
        }
        public string EvaluateSymbols(string input)
        {
            var result = input;
            while (symbolPattern.IsMatch(result))
                {
                    Match match = symbolPattern.Match(result);
                    string symbol = match.Groups[1].Value;
                    string symbolValue = !Symbols.HasValue(symbol) ? "Unknown symbol:"+symbol : Symbols.GetValue(symbol).ToString();
                    //object recalledObject = Fixture.Recall(symbol);
                    //string symbolValue = recalledObject == null ? "Unknown symbol:"+symbol : recalledObject.ToString();
                    result = result.Replace(match.Groups[0].Value, symbolValue);
                };
            return result;
        }
    }

FitNesse table to call the fixture looks as following:

!|Script                     |
|start|SymbolEvaluatorFixture|
|show |EvaluateSymbols |$HL7 |

$HL7 value at the execution time contains following:
MSH|^~\&|QC|SS|STEMSOFT|SS|${MSH7}||${MSH9}|${MSH10}|${MSH11}|2.3.1

Initially I tried to use Recall method (commented out) but that resulted in null reference exception. AFAIK the processor value is null. Tried both slim and fit and nothing worked so far.

jediwhale commented 10 years ago

This is a SLIM test. DoFixture and Symbols are part of the Fit test system.

sergebug commented 10 years ago

Ok. Is there any way to access symbols in SLIM? We just started moving from fit to slim. That is why we continue using do fixtures. Slim had been great so far as it can easily work with fit fixtures. This Symbol weird case was the only exception. The reason I don't want to use cell handlers is because I need make conversion on demand.

jediwhale commented 10 years ago

I don't know of a way to access symbols via code with Slim.

sergebug commented 10 years ago

Consider this work item to be change request then ;) In the meantime ... any suggestions for an alternative are wellcome.

jediwhale commented 10 years ago

Don't use Slim?! :)

vlaquest commented 9 years ago

Hi,

I'm very much confused between Fit and Slim. I read everywhere people saying new users should go for slim, but many times themselves say they've not switched yet. I fear that slim is not yet fully ready.

For example, I've been looking for this exact feature => how do I programmatically access to the symbols with slim? => here the answer is clearly not possible. The ClearSymbols fixture is only available in the fit implementation.

The good thing with slim is that it is "active" and easy to port, but why should it be better for me ? I have the feeling fit is easy enough with fitSharp (and thanks for it by the way!).

jediwhale commented 9 years ago

Slim has a simplified execution model, intended to make it easy to port, but it means it is less powerful than native Fit implementations. Slim is intended to be language-independent, but the core Slim engine is written in Java and it tends to work better with Java than other platforms. Slim is popular with Java users but not widely used outside of Java.

vlaquest commented 9 years ago

Hi, thanks a lot for this answer, it is very useful to me and confirms that I should stick with fit for my needs. I'll keep an eye on slim anyway. Thanks again for your work.