Object Oriented Programming using C#

(backadmin) #1

Object Oriented Programming using C#
Case Study


The code for this is shown below....


namespace MessageManagerTests
{
[TestClass]
public class TestFixture_ClientBookTests
{
public TestFixture_ClientBookTests()
{
}
private MessageManagerSystem.Clients.ClientBook cb;

[TestInitialize]
public void TestInitialize()
{
cb = new MessageManagerSystem.Clients.ClientBook();
}
[TestCleanup]
public void TestCleanup()
{
cb = null;
}
[TestMethod]
public void GetClient_TestDeleteClient
_ShouldNotGenerateException()
{
MessageManagerSystem.Clients.Client c = new
MessageManagerSystem.Clients.Client
(“Simon”, “Room 1234”, “x200”, 10);
try
{
cb.AddClient(1, c);
cb.DeleteClient(1);
}
catch
(MessageManagerSystem.Clients.UnknownClientException)
{
Assert.Fail(“UnknownClient exception should not be
thrown if client exists”);
}
}

One test we should perform on the DeleteClient() method is to test that it can delete a client ... or at least not generate
an exception. The test above proves and exception is not thrown inappropriately but it does not demonstrate that the
client has been successfully deleted nor does it test what happens if we try to delete a client thqat does not exist... clearly
we need to define some more tests.


Having created appropriate test cases our code will generate complier errors as the methods IncreaseCredit() and
DeleteClient() do not exist.

Free download pdf