C# problem
Posted on June 19, 2007
I have Microsoft and their bastard child C#.
I really want to start using test triven developement and have unit test.
Their proved to be invaluable when I modify code.
In one of my classes I use System.Net.WebClient.
public WebCamera(WebClient client, Uri uri)
{
this.client = client;
this.uri = uri;
}
public string CaptureFrame()
{
string location = Path.GetTempFileName();
client.DownloadFile(uri, location);
return location;
}
WebClient is a concrete class, it implements IComponent, but IComponents does not have DownloadFile mathod.
At first I tried to use Rhino Mocks, to mock the Webclient. I’m probably not familliar enougth with
this tool but it was calling GetWebResource(uri) i.e concrete implementation, instead of just returning.
So, next I deciced that I can just pass my impementation of WebClient
class StubWebClient : WebClient
{
public Uri m_uri;
public string m_path;
override public void DownloadFile(Uri uri, string path)
{
m_uri = uri;
m_path = path;
}
}
I got this nice message:
Error Cannot override inherited member ‘System.Net.WebClient.DownloadFile(System.Uri, string)’ because
it is not marked virtual, abstract, or override
Allrighty then, we will provide new DownloadFile mathod.
override public void DownloadFile(Uri uri, string path)
{
m_uri = uri;
m_path = path;
Consle.Write
}
Well I would not write this post if it worked. C# ignored my method and called the one from the base class.
I can do
StubWebClient webClient = new StubWebClient();
webClient.DownloadFile(uri, “file.tmp”);
but I don’t want my camera to care what type of webclient i pass.
Now I’m just started programming in C# this mounth, and I probably don’t know what I am supposed to do. But so
far it look like C# is broken.
Anyone knows how to fix this?
Filed Under Uncategorized |
Leave a Comment
If you would like to make a comment, please fill out the form below.