0

Please note that I've already went through these answers: 1, 2.

those answers helped implementing a WebClientSimulator successfully (by the help of: WebClient interface example).

I need to test an automatic web page notification based on url and some parameters, But I don't know how to use the WebClientSimulator correctly:

public void NotifyWebPage(string url, NameValueCollection parameters)
{
    using (WebClient client = new WebClient())
    {
        client.UploadValuesAsync(new Uri(url), parameters);
    }
}

[TestMethod]
public void Validate_My_NotifyWebPage()
{
    string url = "https://www.someurl.com/";
    NameValueCollection parameters = new NameValueCollection();

    NotifyWebPage(url, parameters);
}

How do i verify that the web page was notified? with the given parameters?

Shahar Shokrani
  • 7,598
  • 9
  • 48
  • 91
  • So you'd like to implement the WebClient interface example, as it looks like the right solution here, but you don't know how? – felix-b Oct 29 '17 at 07:07
  • Iv'e already implemented the WebClient interface (its the same as in the link so i didn't copied it to my question), now my problem is to implement the TestMethod. – Shahar Shokrani Oct 29 '17 at 07:09
  • You cannot **unit**-test this method. You can only do an **integration**-test on that. If you want to have a **unit**-test, then you have to redesign the class/method. – Sir Rufo Oct 29 '17 at 07:44
  • @Sir Rufo what do you mean by integration-test – Shahar Shokrani Oct 29 '17 at 07:46
  • 2
    There is a huge difference between **unit**- and **integration**-test. They both looks equal but have different impacts. **integration**-tests need a special environment, where **unit**-tests work without any. Thats why it is called **unit**-test, you test only a small unit – Sir Rufo Oct 29 '17 at 07:49
  • @Sir Rufo you are right, i need the integration-test (updated the question) – Shahar Shokrani Oct 29 '17 at 07:59
  • As a suggestion, I would inject a WebClient instance (or an interface) into the class to make the class ready for unit-testing, but you should know that already from the WebClient interface example link – Sir Rufo Oct 29 '17 at 08:06

0 Answers0