Files
UptimeSharp/UptimeSharp.Tests/MonitorsTest.cs
T

127 lines
2.7 KiB
C#
Raw Normal View History

2013-12-10 22:32:27 +01:00
using System.Collections.Generic;
2014-02-01 12:21:06 +01:00
using System.Linq;
using System.Threading.Tasks;
2013-12-10 22:32:27 +01:00
using UptimeSharp.Models;
using Xunit;
2013-08-25 14:25:21 +02:00
namespace UptimeSharp.Tests
{
public class MonitorsTest : TestsBase
2013-08-25 14:25:21 +02:00
{
public MonitorsTest() : base() { }
2013-08-25 14:25:21 +02:00
[Fact]
2014-02-01 23:49:05 +01:00
public async void AddHTTPMonitor()
{
2014-02-02 12:51:10 +01:00
Monitor monitor;
Assert.NotNull(monitor = await client.AddMonitor(
name: "test_1",
2014-02-01 23:49:05 +01:00
target: "http://test1.com"
));
2014-02-02 12:51:10 +01:00
await client.DeleteMonitor(monitor);
}
2013-08-25 14:25:21 +02:00
[Fact]
public async Task AddKeywordMonitor()
{
2014-02-02 12:51:10 +01:00
Monitor monitor;
Assert.NotNull(monitor = await client.AddMonitor(
name: "test_2",
2014-02-01 23:49:05 +01:00
target: "http://test2.com",
type: Models.Type.Keyword,
keywordType: KeywordType.Exists,
keywordValue: "test"
));
2014-02-02 12:51:10 +01:00
await client.DeleteMonitor(monitor);
}
2013-08-25 14:25:21 +02:00
[Fact]
public async Task AddPingMonitor()
{
2014-02-02 12:51:10 +01:00
Monitor monitor;
Assert.NotNull(monitor = await client.AddMonitor(
name: "test_3",
2014-02-01 23:49:05 +01:00
target: "http://test3.com",
type: Models.Type.Ping
));
2014-02-02 12:51:10 +01:00
await client.DeleteMonitor(monitor);
}
2013-08-25 14:25:21 +02:00
[Fact]
public async Task AddPortMonitor()
{
2014-02-02 12:51:10 +01:00
Monitor monitor;
Assert.NotNull(monitor = await client.AddMonitor(
name: "test_4",
2014-02-01 23:49:05 +01:00
target: "127.0.0.1",
type: Models.Type.Port,
subtype: Subtype.Custom,
port: 50004
));
2014-02-02 12:51:10 +01:00
await client.DeleteMonitor(monitor);
}
[Fact]
public async Task GetMonitors()
{
2014-02-02 12:51:10 +01:00
Monitor monitor;
Assert.NotNull(monitor = await client.AddMonitor(
name: "test_5",
target: "255.0.0.1",
type: Models.Type.Port,
subtype: Subtype.HTTP
));
Assert.True(
2013-12-10 22:32:27 +01:00
monitor != null
2014-02-01 12:27:10 +01:00
&& monitor.Target == "255.0.0.1"
&& monitor.Type == Models.Type.Port
&& monitor.Subtype == Subtype.HTTP);
2014-02-02 12:51:10 +01:00
monitor = await client.GetMonitor(monitor.ID);
Assert.True(
monitor != null
&& monitor.Target == "255.0.0.1"
&& monitor.Type == Models.Type.Port
&& monitor.Subtype == Subtype.HTTP);
await client.DeleteMonitor(monitor);
}
[Fact]
public async Task ModifyAMonitor()
{
2014-02-02 12:51:10 +01:00
Assert.NotNull(await client.AddMonitor(
name: "test_6",
target: "http://test6.com"
));
List<Monitor> items = await client.GetMonitors();
2014-02-02 00:06:06 +01:00
Monitor monitor = items.SingleOrDefault(item => item.Name == "test_6");
Assert.NotNull(monitor);
monitor.Name = "updated_test_6";
Assert.True(await client.ModifyMonitor(monitor));
monitor = await client.GetMonitor(monitor.ID);
Assert.Equal(monitor.Name, "updated_test_6");
2014-02-02 12:51:10 +01:00
await client.DeleteMonitor(monitor);
}
2013-08-25 14:25:21 +02:00
}
}