I´m using MSpec-Framework to implement BDD to our new project. I´m new to the concept of BDD and therefore MSpec as well and have problems to adress the object of interest (_obj2 in the example), at least Visual Studio intellisense doesn't propose it in Behavior-Class
, especially inside the should_do_some_fancy_magic
-context.
namespace exampleSpace{
public partial class ExampleClass{
private ObjectOfAnotherClass _obj2
private void Test(ObjectOfAnotherClass _co)
...
}
}
namespace exampleSpace.Test{
[Behaviors]
class ExampleClassBehavior{
Establish context =()=>{...};
It should_do_some_fancy_magic() =()=>
ShouldBeEqual(ExampleValue, _ex.Test(_ex._obj2);
private static ExampleClass _ex;
}
}
Any ideas how to get intellisense working inside the Behavior-Class
?
You don't need to set [Behaviors]
for the context. Behaviors are used to reuse the It
s between contexts. That's a use-case that comes up very infrequently.
This should work, despite being untested:
namespace exampleSpace{
public partial class ExampleClass {
public void Test(ObjectOfAnotherClass _co)
_co.Foobar = 42;
}
}
namespace exampleSpace.Test {
[Subject(typeof(ExampleClass))] // This is optional.
class When_something_happens
{
static ObjectOfAnotherClass Other;
static ExampleClassOther SystemUnderTest ;
Establish context = () => {
Other = new ObjectOfAnotherClass();
SystemUnderTest = new ExampleClass();
}
Because of = () => {
SystemUnderTest.Test(Other);
}
It should_do_some_fancy_magic() =
() => Other.Foobar.ShouldEqual(42);
}
}
You can have a look at some MSpec samples here.