kurozakura
kurozakura

Reputation: 2359

How to handle or detect Network Failure in VB.NET?

How to handle the Network failure error message,and how to simulate it?

Upvotes: 1

Views: 1433

Answers (3)

ChrisF
ChrisF

Reputation: 137158

The way to simulate a network failure (or any sub-system failure) is to replace the real network with a mock object. Then in your mock network object you can set up the method calls to return what ever you require for your testing purposes, be it a successful connection or a failure at any point along the way.

Your code can then be tested against this to ensure that it gracefully fails and reports sensible error messages.

If you look into mocking frameworks you'll get a lot more information.

Upvotes: 2

Josh Weatherly
Josh Weatherly

Reputation: 1740

While I think ChrisF has the better solution, in the past I've usually only cared whether the network is "up" or not. So my test is a bit more simple. I yank the ethernet cable out while the app is running and see if my app responds as I expect.

Upvotes: 1

stacked
stacked

Reputation: 68

Do you mean you want the boolean expression

 My.Computer.Network.IsAvailable

You can then just set up some kind of GUI thread to periodically check its value.

Upvotes: 1

Related Questions