I am writing a unit test for when my computer receives/makes a phone call.
The methods being tested are the events that handle the incoming/outgoing call. If the caller is not an approved caller then the call is rejected.
The code works fine, but I can't really find anything to test against for my unit test. The problem is that the actual state of "if my computer is in a call or not" is not controlled my by class. Only the computer knows if a call is currently connected or not.
I am hoping that there are some Unit Test Guru's out there than can tell me what to do to test this scenario. I do not want to create a dummy var that has no relation to my code just to make my unit test pass.
To make this a bit more concrete here is my unit test:
private DeviceMediator deviceMediator;
private IDeviceControlForm deviceControlForm;
private IDataAccess data;
private ICallMonitor callMonitor;
// Use TestInitialize to run code before running each test
[TestInitialize()]
public void MyTestInitialize()
{
deviceControlForm = MockRepository.GenerateStub<IDeviceControlForm>();
data = MockRepository.GenerateStub<IDataAccess>();
callMonitor = MockRepository.GenerateStub<ICallMonitor>();
deviceMediator = new DeviceMediator(deviceControlForm, data)
{CallMonitor = callMonitor};
}
[TestMethod]
public void TestHandleIncomingCall()
{
//Arrange
//Act
deviceMediator.OnIncomingCall(null, new CallState(),
new CallInfoState());
//Assert
// I could not find anything to feasably test on this.
Assert.IsTrue(true);
}
and here is the method it is calling:
public void OnIncomingCall(Call call, CallState callState,
CallInfoState callInfoState)
{
// See if this call is on our list of approved callers
bool callApproved = false;
foreach (PhoneContact phoneContact in Whitelist)
{
if (phoneContact.PhoneNumber == call.CallerID)
callApproved = true;
}
// If this is not an approved call then
if (!callApproved)
CallMonitor.Hangup();
}