Hello,
could you help me with the following newbie problem. My code under test may or may not call a specific function one or more times with different parameters.
I need to check that the function was called only once with specific paramaeter set and I need to fail the test if the function was called with different params or if it was called more than once. I used Recieved and Recieved(1) to check the function was called but a second call to the function did not trigger exception so the test passed. See the code below please
using System;
using NSubstitute;
namespace ConsoleApplication1
{
public interface ICallbacks
{
void GetData(int a, int b);
}
public class TestClass
{
public static void DoSomething(ICallbacks callbacks)
{
callbacks.GetData(1, 2);
callbacks.GetData(1, 3);
}
}
class Program
{
static void Main(string[] args)
{
var c = Substitute.For<ICallbacks>();
TestClass.DoSomething(c);
c.Received().GetData(1, 2);
// TODO GetData called twice how do I check for the second call? if GetData is called more than once make if fail....how?
Console.Read();
}
}
}
Should I use RecievedCalls and check number of calls and if it is different than one then throw an exception or is there more obvious way of doing the check I have missed?
Thanks,
Libor