Given this code, I expected an exception to occur, but System.Net.WebClient.UploadString returns an empty string in result.
I'm obviously missing something, but what?
using System.Net;
using System.Text;
[TestClass()]
public class WebClientTests
{
[TestMethod()]
public void WebClientUploadStringToInvalidUrlTest()
{
var webClient = new WebClient { Encoding = Encoding.UTF8 };
var result = webClient.UploadString("{{foo-bar}}", "snafu");
Assert.IsTrue(string.IsNullOrEmpty(result));
}
[TestMethod()]
[ExpectedException(typeof(ArgumentNullException))]
public void WebClientUploadStringToNullUrlTest()
{
var webClient = new WebClient { Encoding = Encoding.UTF8 };
string url = null;
var result = webClient.UploadString(url, "snafu");
Assert.IsTrue(string.IsNullOrEmpty(result));
}
}
edit: how a test was added for a suggestion from hannonull , and it also throws a ArgumentNullException, which I expect.
source
share