I store an instance in a slim symbol ($IT) but when I later try to use the instance in a function call I receive a fitSharp.Machine.Exception.ParseException.
I think the problem is that FitSharp tries to parse the argument instead of casting the object up to its interface.
I have the following class and interface (name space is MySlimTest)
public interface IObject {}
public class ConcreteObject: IObject
{
public string Name { get; set; }
public string Description { get; set; }
}
which I use in my slim fixture which includes the following method and the returned instance I store in a slim symbol.
public IObject CreateConcreteObjectWithNameAndDescription(string name, string description)
{
return new ConcreteObject() {Name = name, Description = description};
}
I call this method from a script table. When rendered after the test has run it looks like this:
$IT<-[MySlimTest.ConcreteObject] | create concrete object | with name | The initial name of the concrete object | and description | empty |
When I try to later use the instance stored in the slim symbol IT, the ParseException is thrown.
the method in the fixture is
public bool SetNameForInstance(string name, IObject obj)
{
return SetAttribute<ConcreteObject>(obj, concreteObject => concreteObject.Name = name);
}
this is used in the test table as
ensure | set name | John Cleese | for instance | $IT->[MySlimTest.ConcreteObject]
Interestingly, if I change the method signature to use the implementation (ConcreteObject) instead of the interface then it works.
public bool SetNameForInstance(string name, ConcreteObject obj)
The complete example with fixture code follows as a fitnesse plain text wiki page:
!*> Environment
Linux 3.2.0-3-amd64 #1 SMP Mon Jul 23 02:45:17 UTC 2012 x86_64 GNU/Linux
Mono 2.10.8.1 (Debian 2.10.8.1-7) (64-bit)
glib-sharp 2.12.0.0
FitNesse (v20121220)
FitSharp release 2.2 for .net 4.0
*!
!*> Fixture Code
{{{
using System;
namespace MySlimTest
{
public interface IObject {}
public class ConcreteObject: IObject
{
public string Name { get; set; }
public string Description { get; set; }
}
public class SymbolTestFixture
{
public SymbolTestFixture ()
{
// Initialisation code here...
// Currently just a mock.
}
public IObject CreateConcreteObjectWithNameAndDescription(string name, string description)
{
return new ConcreteObject() {Name = name, Description = description};
}
public bool SetNameForInstance(string name, IObject obj)
{
return SetAttribute<ConcreteObject>(obj, concreteObject => concreteObject.Name = name);
}
public bool SetDescriptionForInstance(string description, ConcreteObject obj)
{
return SetAttribute<ConcreteObject>(obj, concreteObject => concreteObject.Description = description);
}
private bool SetAttribute<T>(IObject obj, Action<T> fun)
{
if (obj is T)
{
fun((T)obj);
return true;
}
return false;
}
}
}
}}}
*!
!3 Set-up of the test system
!***> Test system set-up
!define TEST_SYSTEM {slim}
!path /path/to/fixture/DLL/SlimTest.dll
!define COMMAND_PATTERN {%m -r fitSharp.Slim.Service.Runner,/path/to/fitSharp.dll %p}
!define TEST_RUNNER {/path/to/Runner.exe}
***!
!**> Usings
!|import |
|MySlimTest|
**!
!2 Scenarios
!|scenario|given concrete object |name |and |description |
|$IT= |create concrete object with name|@name|and description|@description|
!|scenario |given concrete object|name |
|given concrete object|@name |and|empty|
!|scenario|edit concrete object|instance |name to |name|and description to|description|
|ensure |set name |@name |for instance|$IT |
|ensure |set description |@description|for instance|$@instance |
!3 Test the ''slim symbol can hold object as parameter'' feature
!|script|symbol test fixture|
!|script |
|given concrete object|The initial name of the concrete object |
|edit concrete object |IT |name to |John Cleese |and description to|Yes, I am still indeed alive, contrary to rumour, and I am touring my one Cleese show. London.|
It's a bug. I forked, fixed and made a pull request on GitHub