Compartilhar via


Bookmark Collection: Adding and Removing a Bookmark - Does the Count keep up?

I have given up apologizing for the not so weekly updates to solving this problem - just too much going on. That said; where was I? In the previous step I had refactored out the common initialization code out of each test and put this in the [SetUp] method, named BeforeTest. If I had NUnit to do over again I would call the [SetUp] attribute [BeforeTest] because I think it is more descriptive. I also moved the explicit strings from the tests into static read only member variables. The next tests to implement are the following:

  • Add a Bookmark, remove a Bookmark, Count == 0
  • Add 2 Bookmarks, remove a Bookmark, Count == 1

These two tests are similar, let's write the first one:

[Test]
public void RemoveBookmarkCountIsDecrmented()
{
collection.Add(exampleDotComLabel, exampleDotComUri);
collection.Remove(exampleDotComLabel);
Assert.AreEqual(0, collection.Count);
}

When I compile this I get the expected result indicating that I have not implemented the Remove method. Here is the implementation needed to pass the test:

public void Remove(string label)
{
count--;
}

I spared you the implementation that throws the NotImplementedException this time. Now when I run the test it passes so we can move on to implement the next test.

[Test]
public void Add2BookmarksRemoveBookmarkCountIsDecrmented()
{
collection.Add(exampleDotComLabel, exampleDotComUri);
collection.Add(exampleDotNetLabel, exampleDotNetUri);
collection.Remove(exampleDotNetLabel);
Assert.AreEqual(1, collection.Count);
}

When I compile and run this test, it passes without changing the implementation. Clearly we have stopped learning anything new about the solution with these types of tests. It looks like it's time to choose a different type of test so we can continue learning about the problem. The next test I want to tackle is the following:

  • Add a Bookmark, Retrieve using the label

It looks like this test will force me to show how the Bookmarks are stored which is something that I have not done up to this point. Until next time...

Comments

  • Anonymous
    December 04, 2004
    that's the beauty of an Rss feed. doesn't matter if you post once a week or once a quarter. As long as the content is good, we'll read it. It's good.
  • Anonymous
    December 05, 2004
    James Newkirk blogs again