Files
UptimeSharp/UptimeSharp.Tests/AlertsTest.cs
T

80 lines
1.8 KiB
C#
Raw Normal View History

2014-02-02 11:50:28 +01:00
using System.Linq;
using System.Threading.Tasks;
2014-02-02 11:23:27 +01:00
using UptimeSharp.Models;
using Xunit;
2013-08-25 14:25:21 +02:00
namespace UptimeSharp.Tests
{
public class AlertsTest : TestsBase
2013-08-25 14:25:21 +02:00
{
public AlertsTest() : base() { }
2013-08-25 14:25:21 +02:00
[Fact]
public async Task AddInvalidAlertWithTypeSms()
2013-08-25 14:25:21 +02:00
{
await ThrowsAsync<UptimeSharpException>(async () =>
{
await client.AddAlert(Models.AlertType.SMS, "+436601289172");
});
2013-08-25 14:25:21 +02:00
}
2013-08-26 01:07:19 +02:00
[Fact]
public async Task AddInvalidAlertWithTypeTwitter()
2013-08-25 14:25:21 +02:00
{
await ThrowsAsync<UptimeSharpException>(async () =>
2013-08-26 01:07:19 +02:00
{
await client.AddAlert(Models.AlertType.Twitter, "artistandsocial");
2013-08-26 01:07:19 +02:00
});
2013-08-25 14:25:21 +02:00
}
2013-08-26 01:07:19 +02:00
[Fact]
public async Task AddAndRemoveAlerts()
2013-08-25 14:25:21 +02:00
{
string email = "example@ceecore.com";
2014-02-02 11:27:44 +01:00
Assert.NotNull(await client.AddAlert(AlertType.Email, email));
2013-08-25 14:25:21 +02:00
Alert origin = await GetOriginAlert(email);
2013-08-25 14:25:21 +02:00
2013-08-26 01:07:19 +02:00
Assert.Equal(email, origin.Value);
Assert.Equal(AlertType.Email, origin.Type);
2013-08-25 14:25:21 +02:00
await client.DeleteAlert(origin);
2013-08-25 14:25:21 +02:00
origin = await GetOriginAlert(email);
2013-08-25 14:25:21 +02:00
2013-08-26 01:07:19 +02:00
Assert.Null(origin);
2013-08-25 14:25:21 +02:00
}
2013-08-26 01:07:19 +02:00
[Fact]
public async Task AddAndRetrieveSpecificAlerts()
2013-08-25 14:25:21 +02:00
{
2014-02-02 11:50:28 +01:00
Alert alert1;
Alert alert2;
2014-02-28 10:35:47 +01:00
Alert alert3;
2013-08-25 14:25:21 +02:00
2014-02-02 11:50:28 +01:00
Assert.NotNull(alert1 = await client.AddAlert(AlertType.Email, "example1@ceecore.com"));
Assert.NotNull(alert2 = await client.AddAlert(AlertType.Boxcar, "example2@ceecore.com"));
2014-02-28 10:35:47 +01:00
Assert.NotNull(alert3 = await client.AddAlert(AlertType.WebHook, "http://ceecore.com?"));
2013-08-25 14:25:21 +02:00
2014-02-02 11:50:28 +01:00
try
{
await client.DeleteAlert(alert1);
await client.DeleteAlert(alert2);
2014-02-28 10:35:47 +01:00
await client.DeleteAlert(alert3);
2014-02-02 11:50:28 +01:00
}
catch { }
2013-08-25 14:25:21 +02:00
}
private async Task<Alert> GetOriginAlert(string value)
2013-08-25 14:25:21 +02:00
{
2014-02-02 11:50:28 +01:00
return (await client.GetAlerts()).FirstOrDefault(item => item.Value == value);
2014-02-02 11:33:46 +01:00
}
2013-08-25 14:25:21 +02:00
}
}