diff --git a/UptimeSharp.Tests/AlertsTest.cs b/UptimeSharp.Tests/AlertsTest.cs new file mode 100644 index 0000000..d806a9a --- /dev/null +++ b/UptimeSharp.Tests/AlertsTest.cs @@ -0,0 +1,106 @@ +using NUnit.Framework; +using System.Collections.Generic; +using UptimeSharp.Models; + +namespace UptimeSharp.Tests +{ + [TestFixture] + public class AlertsTest + { + UptimeClient client; + + // this API key is associated with the test account uptimesharp@outlook.com + // please don't abuse it and create your own if you want to test the project! + string APIKey = "u97240-a24c634b3b84f1af602628e8"; + + + [SetUp] + public void Setup() + { + client = new UptimeClient(APIKey); + } + + + [TearDown] + public void Teardown() + { + List alerts = client.RetrieveAlerts(); + alerts.ForEach(alert => client.DeleteAlert(alert)); + } + + + [Test] + [ExpectedException(typeof(APIException))] + public void AddInvalidAlertWithTypeSms() + { + client.AddAlert(Models.AlertType.SMS, "+436601289172"); + } + + + [Test] + [ExpectedException(typeof(APIException))] + public void AddInvalidAlertWithTypeTwitter() + { + client.AddAlert(Models.AlertType.Twitter, "artistandsocial"); + } + + + [Test] + public void AddAndRemoveAlerts() + { + string email = "example@ceecore.com"; + + Assert.IsTrue(client.AddAlert(AlertType.Email, email), "Response should be true for adding a new alert"); + + Alert origin = GetOriginAlert(email); + + Assert.AreEqual(email, origin.Value, "Retrieved alert should have the value (example@ceecore.com) which was submitted"); + Assert.AreEqual(AlertType.Email, origin.Type, "Retrieved alert should have the type (email) which was submitted"); + + client.DeleteAlert(origin); + + origin = GetOriginAlert(email); + + Assert.IsNull(origin, "Alert should have been deleted"); + } + + + [Test] + public void AddAndRetrieveSpecificAlerts() + { + Assert.IsTrue( + client.AddAlert(AlertType.Email, "example1@ceecore.com"), + "Response should be true for adding a new alert (email 1)" + ); + Assert.IsTrue( + client.AddAlert(AlertType.Boxcar, "example@ceecore.com"), + "Response should be true for adding a new alert (bocar 4)" + ); + + List alerts = client.RetrieveAlerts(); + + Assert.GreaterOrEqual(alerts.ToArray().Length, 2, "Alerts length should be at least 2", alerts); + + List specificAlerts = client.RetrieveAlerts(new int[] { alerts[0].ID, alerts[1].ID }); + + Assert.AreEqual(2, specificAlerts.ToArray().Length, "Specific alerts length should be 2", specificAlerts); + } + + + private Alert GetOriginAlert(string value) + { + List alerts = client.RetrieveAlerts(); + Alert origin = null; + + alerts.ForEach(alert => + { + if (alert.Value == value) + { + origin = alert; + } + }); + + return origin; + } + } +} diff --git a/UptimeSharp.Tests/ClientTest.cs b/UptimeSharp.Tests/ClientTest.cs new file mode 100644 index 0000000..9dc9c00 --- /dev/null +++ b/UptimeSharp.Tests/ClientTest.cs @@ -0,0 +1,32 @@ +using NUnit.Framework; +using System.Collections.Generic; +using UptimeSharp.Models; + +namespace UptimeSharp.Tests +{ + [TestFixture] + public class ClientTest + { + UptimeClient client; + + // this API key is associated with the test account uptimesharp@outlook.com + // please don't abuse it and create your own if you want to test the project! + string APIKey = "u97240-a24c634b3b84f1af602628e8"; + + + [SetUp] + public void Setup() + { + client = new UptimeClient(APIKey); + } + + + [Test] + public void Initialize() + { + Assert.IsNull(client.LastRequestData, "LastRequestData should be null on init"); + + Assert.AreEqual(APIKey, client.ApiKey, "API Key should be correctly assigned"); + } + } +} diff --git a/UptimeSharp.Tests/MonitorsTest.cs b/UptimeSharp.Tests/MonitorsTest.cs new file mode 100644 index 0000000..6051d90 --- /dev/null +++ b/UptimeSharp.Tests/MonitorsTest.cs @@ -0,0 +1,57 @@ +using NUnit.Framework; +using System.Collections.Generic; +using UptimeSharp.Models; + +namespace UptimeSharp.Tests +{ + [TestFixture] + public class MonitorsTest + { + UptimeClient client; + + // this API key is associated with the test account uptimesharp@outlook.com + // please don't abuse it and create your own if you want to test the project! + string APIKey = "u97240-a24c634b3b84f1af602628e8"; + + + [SetUp] + public void Setup() + { + //client = new UptimeClient(APIKey); + } + + + [TearDown] + public void Teardown() + { + //List alerts = client.RetrieveAlerts(); + //alerts.ForEach(alert => client.DeleteAlert(alert)); + } + + + //bool result = client.Delete(775853599); + + //bool result = client.Create("apitest", "http://pocketsharp.com", Models.Type.HTTP); + //client.Add("apiKeywordTest", "http://frontendplay.com", "frontendplay", KeywordType.NotExists); + + //client.DeleteAlert(2014599); + //bool result = client.AddAlert(AlertType.Email, "klika@live.at"); + + //bool x = client.Add( + // name: "testx", + // uri: "http://google.at", + // type: Models.Type.Keyword, + // keywordType: KeywordType.Exists, + // keywordValue: "goog" + //); + //List monitors = client.Retrieve(showLog: true); + //List alerts = client.RetrieveAlerts(); + //System.Console.WriteLine(monitor.ID + " " + monitor.Name); + //alerts.ForEach(item => System.Console.WriteLine(item.ID + " " + item.Type.ToString() + " " + item.Value)); + + //monitor.Name = "HALLOOO"; + //bool result = client.Modify(monitor); + + //monitors.ForEach(item => System.Console.WriteLine(item.ID + " " + item.Name + " " + item.Status)); + } +} diff --git a/UptimeSharp.Tests/UptimeSharp.Tests.csproj b/UptimeSharp.Tests/UptimeSharp.Tests.csproj index 1a96fc3..7b2b8e3 100644 --- a/UptimeSharp.Tests/UptimeSharp.Tests.csproj +++ b/UptimeSharp.Tests/UptimeSharp.Tests.csproj @@ -50,7 +50,9 @@ - + + +