add Tests for UptimeClient initialization and Alerts
This commit is contained in:
@@ -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>
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user