Object Oriented Programming using C#
Case Study
}
catch(MessageManagerSystem.Clients.UnknownClientException)
{
}
}
[TestMethod]
public void GetClient_TestGettingClient_ShouldNotGenerateException()
{
MessageManagerSystem.Clients.Client c = new
MessageManagerSystem.Clients.Client(“Simon”,
“Room 1234”, “x200”, 10);
MessageManagerSystem.Clients.Client c2 = null;
try
{
cb.AddClient(1, c);
c2=cb.GetClient(1);
}
catch(MessageManagerSystem.Clients.UnknownClientException)
{
Assert.Fail(“UnknownClient exception should not be thrown if
client exists”);
}
}
[TestMethod]
public void GetClient_TestGettingClient_AttributesShouldNotChange()
{
MessageManagerSystem.Clients.Client c = new
MessageManagerSystem.Clients.Client(“Simon”,
“Room 1234”, “x200”, 10);
MessageManagerSystem.Clients.Client c2 = null;
try
{
cb.AddClient(1, c);
c2 = cb.GetClient(1);
Assert.AreEqual(c2.Credit,10,”Value of returned credit not as
expected”);
}
catch (MessageManagerSystem.Clients.UnknownClientException)
{
}
}
[TestMethod]
public void GetClient_TestDeleteUnknownClient_ShouldGenerateException()
{
try
{
cb.DeleteClient(1);
Assert.Fail(“UnknownClient exception should be thrown if
client does not exist”);
}
Catch (MessageManagerSystem.Clients.UnknownClientException)
{
}
}
The tests above show numerous tests with an empty client book. They demonstrate that clients can be added, but not
twice. They also demonstrate that clients can be deleted and that exceptions are generated appropriately.