hi,
i'm very new to the world of .net..i have given a task to unit test the methods. some methods i did successfully..here is the method where i'm stuck..can u help me in unit testing the method.
Method goes some thing like the bellow.
public FreeTimeFrame[] GetAllAvailableAppointments(DateTime startDate, DateTime endDate)
{
FreeTimeFrame [] availableAppointments;
GlossyWebService.GlossyWebService service = new GlossyWebService.GlossyWebService();
service.Url = ServiceDetails.Url;
AppointmentServiceRequestMessage appointmentServiceRequestMessage = new AppointmentServiceRequestMessage();
appointmentServiceRequestMessage.StartDate = startDate ;
appointmentServiceRequestMessage.EndDate = endDate ;
AppointmentServiceResponseMessage appointmentServiceResponseMessage = service.GetAvailableAppointments(appointmentServiceRequestMessage);
//TODO refactor to proper error handeling of service errors.
if (appointmentServiceResponseMessage.ServiceError.ToString() == "no service error")
{
availableAppointments = appointmentServiceResponseMessage.FreeTimeFrames;
}
else
{
throw ExceptionFactory.RaiseSystemException(new CustomException("Service error: ", appointmentServiceResponseMessage.ServiceError));
}
return availableAppointments;
}
EricPosted Jul 11, 2008, 12:53 PM
Not exactly sure as to where you're stuck with your testing of the method. What assumptions are to be made about this method? I mean you could create unit tests to validate that exceptions are thrown properly...however it looks like this method needs refactoring in order to implement better error handling.
Much of what's needed to test this probably revolves around the the class itself and how the class gets messages sent to it (poor grammar, I know! :)).
But yeah the type of contract that the class has with it's clients/peers is important to know as well as exactly what is the usage model for this class? I would usually focus on the realm of cases that are more likely to occur (invocation based on the contract, error handling as implemented, etc.). Often times you can look at a class and see where the bugs will occur (what if the dates in the method's parameter list are null? Is this handled in another part of the application or is it assumed that the methods are to handle this error condition?
Sorry for rambling. Basically, more info is needed as to the nature of the help you need.
Regards,
Eric