From 0758af689506be64fbdadeb33ae6456369eadc24 Mon Sep 17 00:00:00 2001 From: Sik Date: Fri, 2 Aug 2024 14:00:07 +0200 Subject: [PATCH] feat(test): added tests for isonline class --- System.Test/IsOnlineTest.cs | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 System.Test/IsOnlineTest.cs diff --git a/System.Test/IsOnlineTest.cs b/System.Test/IsOnlineTest.cs new file mode 100644 index 0000000..d59fbbb --- /dev/null +++ b/System.Test/IsOnlineTest.cs @@ -0,0 +1,64 @@ +using FrApp42.System.Net; +using System.Net; + +namespace System.Test +{ + [TestClass] + public class IsOnlineTest + { + private readonly string _googleHostname = "google.com"; + private readonly IPAddress _googleIpAddress = IPAddress.Parse("8.8.8.8"); + + [TestMethod] + public void ConstructorWithHostnameAndDefaultTimeout() + { + IsOnline isOnline = new(_googleHostname); + Assert.AreEqual(5, isOnline.TimeOut, "Default timeout should be 5."); + } + + [TestMethod] + public void ConstructorWithHostnameAndCustomTimeout() + { + int customTimeout = 10; + + IsOnline isOnline = new(_googleHostname, customTimeout); + Assert.AreEqual(customTimeout, isOnline.TimeOut, $"Timeout should be {customTimeout}."); + } + + [TestMethod] + public void ConstructorWithIpAddressAndDefaultTimeout() + { + IsOnline isOnline = new(_googleIpAddress); + Assert.AreEqual(5, isOnline.TimeOut, "Default timeout should be 5."); + } + + [TestMethod] + public void ConstructorWithIpAddressAndCustomTimeout() + { + int customTimeout = 10; + + IsOnline isOnline = new(_googleIpAddress, customTimeout); + Assert.AreEqual(customTimeout, isOnline.TimeOut, $"Timeout should be {customTimeout}."); + } + + [TestMethod] + public void CheckWithHostname() + { + IsOnline isOnline = new(_googleHostname); + + bool result = isOnline.Check(); + + Assert.IsTrue(result, "Google hostname should be reachable."); + } + + [TestMethod] + public void CheckWithIpAddress() + { + IsOnline isOnline = new(_googleIpAddress); + + bool result = isOnline.Check(); + + Assert.IsTrue(result, "Google IP address should be reachable."); + } + } +}