add Tests for UptimeClient initialization and Alerts

This commit is contained in:
2013-08-25 14:17:03 +02:00
parent b560a2a5b5
commit d68c04eae0
8 changed files with 264 additions and 13 deletions
@@ -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")]
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7AB536B7-1A99-44A7-B5AA-E36E9C7F09F4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UptimeSharp.Tests</RootNamespace>
<AssemblyName>UptimeSharp.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=104.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text, Version=3.9.58.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ServiceStack.Text.3.9.58\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="UptimeSharpTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UptimeSharp\UptimeSharp.csproj">
<Project>{af900acf-dc2a-40ac-9614-b7c8c12e114c}</Project>
<Name>UptimeSharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+141
View File
@@ -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<Alert> 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<Alert> 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<Alert> alerts = client.RetrieveAlerts();
Assert.GreaterOrEqual(alerts.ToArray().Length, 2, "Alerts length should be at least 2", alerts);
List<Alert> 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<Monitor> monitors = client.Retrieve(showLog: true);
//List<Alert> 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));
}
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="RestSharp" version="104.1" targetFramework="net40" />
<package id="ServiceStack.Text" version="3.9.58" targetFramework="net40" />
</packages>
+5 -5
View File
@@ -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
+2 -2
View File
@@ -32,9 +32,9 @@ namespace UptimeSharp
/// <returns></returns>
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<DefaultResponse>("newAlertContact",
+1 -1
View File
@@ -15,7 +15,7 @@ namespace UptimeSharp.Models
/// The ID.
/// </value>
[DataMember(Name = "id")]
public int? ID { get; set; }
public int ID { get; set; }
/// <summary>
/// Gets or sets the alert type.
-5
View File
@@ -20,11 +20,6 @@ namespace UptimeSharp
/// </summary>
protected static Uri baseUri = new Uri("http://api.uptimerobot.com/");
/// <summary>
/// callback URL for API calls
/// </summary>
protected string CallbackUri { get; set; }
/// <summary>
/// Accessor for the UptimeRebot API key
/// see: http://http://www.uptimerobot.com/api.asp