diff --git a/UptimeSharp.Tests/Properties/AssemblyInfo.cs b/UptimeSharp.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5d4e7ed --- /dev/null +++ b/UptimeSharp.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UptimeSharp.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UptimeSharp.Tests")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3c28f0ef-6284-4842-ac5e-7f6ce9a4ddef")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UptimeSharp.Tests/UptimeSharp.Tests.csproj b/UptimeSharp.Tests/UptimeSharp.Tests.csproj new file mode 100644 index 0000000..1a96fc3 --- /dev/null +++ b/UptimeSharp.Tests/UptimeSharp.Tests.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4} + Library + Properties + UptimeSharp.Tests + UptimeSharp.Tests + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + + False + ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll + + + False + ..\packages\ServiceStack.Text.3.9.58\lib\net35\ServiceStack.Text.dll + + + + + + + + + + + + + + + + + + + {af900acf-dc2a-40ac-9614-b7c8c12e114c} + UptimeSharp + + + + + \ No newline at end of file diff --git a/UptimeSharp.Tests/UptimeSharpTest.cs b/UptimeSharp.Tests/UptimeSharpTest.cs new file mode 100644 index 0000000..9d80660 --- /dev/null +++ b/UptimeSharp.Tests/UptimeSharpTest.cs @@ -0,0 +1,141 @@ +using NUnit.Framework; +using System.Collections.Generic; +using UptimeSharp.Models; + +namespace UptimeSharp.Tests +{ + [TestFixture] + public class UptimeSharpTest + { + 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] + public void Initialize() + { + Assert.IsNull(client.LastRequestData, "LastRequestData should be null on init"); + + Assert.AreEqual(APIKey, client.ApiKey, "API Key should be correctly assigned"); + } + + + [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"); + } + + private Alert GetOriginAlert( string value ) + { + List alerts = client.RetrieveAlerts(); + Alert origin = null; + + alerts.ForEach(alert => + { + if (alert.Value == value) + { + origin = alert; + } + }); + + return origin; + } + + + [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); + } + + + //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/packages.config b/UptimeSharp.Tests/packages.config new file mode 100644 index 0000000..f2c2994 --- /dev/null +++ b/UptimeSharp.Tests/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/UptimeSharp.sln b/UptimeSharp.sln index ede18fa..e0e41a6 100644 --- a/UptimeSharp.sln +++ b/UptimeSharp.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeSharp", "UptimeSharp\UptimeSharp.csproj", "{AF900ACF-DC2A-40AC-9614-B7C8C12E114C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeSharp.Console", "UptimeSharp.Console\UptimeSharp.Console.csproj", "{CDA2493E-AF18-4D75-84B6-CDA4CCBE733F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UptimeSharp.Tests", "UptimeSharp.Tests\UptimeSharp.Tests.csproj", "{7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,10 +15,10 @@ Global {AF900ACF-DC2A-40AC-9614-B7C8C12E114C}.Debug|Any CPU.Build.0 = Debug|Any CPU {AF900ACF-DC2A-40AC-9614-B7C8C12E114C}.Release|Any CPU.ActiveCfg = Release|Any CPU {AF900ACF-DC2A-40AC-9614-B7C8C12E114C}.Release|Any CPU.Build.0 = Release|Any CPU - {CDA2493E-AF18-4D75-84B6-CDA4CCBE733F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CDA2493E-AF18-4D75-84B6-CDA4CCBE733F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CDA2493E-AF18-4D75-84B6-CDA4CCBE733F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CDA2493E-AF18-4D75-84B6-CDA4CCBE733F}.Release|Any CPU.Build.0 = Release|Any CPU + {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/UptimeSharp/Components/Alert.cs b/UptimeSharp/Components/Alert.cs index 20bfc77..b13ffdd 100644 --- a/UptimeSharp/Components/Alert.cs +++ b/UptimeSharp/Components/Alert.cs @@ -32,9 +32,9 @@ namespace UptimeSharp /// public bool AddAlert(AlertType type, string value) { - if (type == AlertType.SMS) + if (type == AlertType.SMS || type == AlertType.Twitter) { - throw new APIException("AlertType.SMS is not supported by the UptimeRobot API"); + throw new APIException("AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API"); } return Get("newAlertContact", diff --git a/UptimeSharp/Models/Alert.cs b/UptimeSharp/Models/Alert.cs index 1f790b1..72a7032 100644 --- a/UptimeSharp/Models/Alert.cs +++ b/UptimeSharp/Models/Alert.cs @@ -15,7 +15,7 @@ namespace UptimeSharp.Models /// The ID. /// [DataMember(Name = "id")] - public int? ID { get; set; } + public int ID { get; set; } /// /// Gets or sets the alert type. diff --git a/UptimeSharp/UptimeClient.cs b/UptimeSharp/UptimeClient.cs index 873950a..8d236e5 100644 --- a/UptimeSharp/UptimeClient.cs +++ b/UptimeSharp/UptimeClient.cs @@ -20,11 +20,6 @@ namespace UptimeSharp /// protected static Uri baseUri = new Uri("http://api.uptimerobot.com/"); - /// - /// callback URL for API calls - /// - protected string CallbackUri { get; set; } - /// /// Accessor for the UptimeRebot API key /// see: http://http://www.uptimerobot.com/api.asp