Coding with Protection In the next two exercises, I want you to use a third-party library and protect yourself against changes that might occur in future versions of the library.
Exercise 8-14: Protecting Yourself Against the Change We are building an application for tourists. This application will provide tourists with information about locations they may want to visit. We are going to use a class library (called WhereIs.dll) that is being written by another team. The first version they give us supports two methods in a Search class: FindCity, which returns the capital city if we give it a country name FindAttraction, which returns a popular tourist attraction for a capital city We know that the library is still in development, but we need to start our project now so that we can show something to the customer as soon as possible. You can download the library from http://eXtreme.NET.Roodyn.com/BookExercises.aspx.The countries currently supported are Australia, Canada, Denmark, England, France, Japan, and the United States.We need to create a set of tests to validate the behavior of this library and that will protect us against any changes in future versions breaking our code without us knowing about it. Then use the library to create a simple Windows Forms application to return capital cities and attractions when a user enters a country. I'll help you get started.
1. | Create a new C# application called WhereIsClient. | 2. | Add a class called WhereIsTests and add the TestFixture attribute to the class. | 3. | Create a new Test method in the class called TestFindCapital. [Test] public void TestFindCapital() { Search whereis = new Search(); string city = string.Empty; city = whereis.FindCapital("England"); //fill in the rest here }
|
I'll leave the rest to you.Hint: You might need to run the functions to see what they output before completing the tests.
Exercise 8-15: Plugging In the New Changed Library The team building the WhereIs.dll class library have just released a new version that supports a method to get the next two days of weather for a capital city. The method is called FindWeather and takes a city name. It returns a string containing XML for the next two days' weather. The team tells us that the XML returned looks like this. <Weather> <Today> Sunny </Today> <Tomorrow> Rain </ Tomorrow > </Weather>
You can download the new version of the library from  |