-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from nkot/httpendpoint-does-not-throw
HttpListener.Stop() will not throw if it is not initialized
- Loading branch information
Showing
3 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Metrics; | ||
using System.Net.NetworkInformation; | ||
using System.Collections; | ||
using System.Net; | ||
|
||
namespace Metrics.Tests.MetricsConfigTests | ||
{ | ||
public class HttpEndpointTests | ||
{ | ||
|
||
[Fact] | ||
public void HttpEndpointCanBeDisposed() | ||
{ | ||
var config = Metric.Config.WithHttpEndpoint("http:https://localhost:58888/metricstest/HttpListenerTests/HttpEndpointCanBeDisposed/"); | ||
config.Dispose(); | ||
} | ||
|
||
[Fact] | ||
public void HttpEndpointDoesNotThrowIfPortIsOccupied() | ||
{ | ||
using (var listener = new HttpListener()) | ||
{ | ||
listener.Prefixes.Add("http:https://localhost:58888/metricstest/HttpListenerTests/OccupiedPort/"); | ||
listener.Start(); | ||
|
||
Metric.Config.WithHttpEndpoint("http:https://localhost:58888/metricstest/HttpListenerTests/OccupiedPort/"); | ||
listener.Close(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void HttpEndportLogsAnErrorIfPortIsOccupied() | ||
{ | ||
using (var listener = new HttpListener()) | ||
{ | ||
listener.Prefixes.Add("http:https://localhost:58888/metricstest/HttpListenerTests/OccupiedPort/"); | ||
listener.Start(); | ||
|
||
var loggedAnError = false; | ||
var config = Metric.Config; | ||
config.WithErrorHandler((exception, s) => { loggedAnError = true; }, true); | ||
config.WithErrorHandler((exception) => { loggedAnError = true; }, true); | ||
|
||
config.WithHttpEndpoint("http:https://localhost:58888/metricstest/HttpListenerTests/OccupiedPort/"); | ||
Assert.True(loggedAnError); | ||
listener.Close(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SecondCallToWithHttpEndportDoesNotThrow() | ||
{ | ||
var config = Metric.Config.WithHttpEndpoint("http:https://localhost:58888/metricstest/HttpListenerTests/sameendpoint/"); | ||
config.WithHttpEndpoint("http:https://localhost:58888/metricstest/HttpListenerTests/sameendpoint/"); | ||
} | ||
|
||
[Fact] | ||
public void HttpEndpointDoesNotThrowOnDispose() | ||
{ | ||
using (var listener = new HttpListener()) | ||
{ | ||
listener.Prefixes.Add("http:https://localhost:58888/metricstest/HttpListenerTests/OccupiedPort/"); | ||
listener.Start(); | ||
|
||
var config = Metric.Config.WithHttpEndpoint("http:https://localhost:58888/metricstest/HttpListenerTests/OccupiedPort/"); | ||
config.Dispose(); | ||
listener.Close(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters