I am using RhinoMocks for mocking/stubbing, and Nunit framework for unit testing.
I have following class
class A
{
private int data = -1;
public void Initialize (int data)
{
this.data = data;
}
public void CallA()
{
if (data == -1) throw new InvalidArgumentException("data has invalid value -1");
try
{
A1("a1");
A2("a2");
}
catch (AException e)
{
throw;
}
catch (Exception e)
{
throw new AException(ErrorCode.UnknownException, e);
}
}
private void A1(string item)
{
}
private void A2(string item)
{
}
}
I am struggling to following test cases:
InvalidAgrumentException : It will raised if either
Initialized
method is not called or -1 is passed as argument toInitialized
. data is private So cannot be mocked (until libraries such as TypeMock isolater are used that do IL Weaving). To raise this exception, One option is to callInitialized
Method which I am not sure is the correct approach? (because data can be set as -1 from other places also. Though that is not an issue it requires extra function call.)To verify that A1 is called with "a1" parameter, and A2 is called with "a2" parameter.