Writing test for my application. Would like to test connection with exeption handling, for now I have created method which works and looks like :
[Test]
public void TestCreateConnection()
{
Connection testConnection = new Connection();
connection.CreateConnection(correctURL, IDName + connection.ApiKey, connection.ContentType, connection.MediaType, connection.Get, false, "name");
testConnection.CreateConnection(correctURL, IDName + connection.ApiKey, connection.ContentType, connection.MediaType, connection.Get, false, "name");
}
In the finall version working on smth which will catch exception - WebExeption
. Already have it in try / catch block inside my method which is about to create connection, it works ofc. But need it in my test as well. I was thinking it should looks like :
[Test]
[ExpectedException(typeof(WebException))]
public void TestCreateConnection()
{
Connection testConnection = new Connection();
connection.CreateConnection(correctURL, IDName + connection.ApiKey, connection.ContentType, connection.MediaType, connection.Get, false, "name");
testCconnection.CreateConnection(correctURL, IDName + connection.ApiKey, connection.ContentType, connection.MediaType, connection.Get, false, "name");
Assert.Catch<WebException>(() => connection.CreateConnection("test", IDName + connection.ApiKey, connection.ContentType, connection.MediaType, connection.Get, false, "name"););
}
Like we can see i changed first arg of the method which is URL address, it will couse the web exeption. How can i write it in correct way ?