diff --git a/UptimeSharp.Tests/AlertsTest.cs b/UptimeSharp.Tests/AlertsTest.cs index ca9bb6e..4aef099 100644 --- a/UptimeSharp.Tests/AlertsTest.cs +++ b/UptimeSharp.Tests/AlertsTest.cs @@ -35,7 +35,7 @@ namespace UptimeSharp.Tests { string email = "example@ceecore.com"; - Assert.True(await client.AddAlert(AlertType.Email, email)); + Assert.NotNull(await client.AddAlert(AlertType.Email, email)); Alert origin = await GetOriginAlert(email); @@ -53,8 +53,8 @@ namespace UptimeSharp.Tests [Fact] public async Task AddAndRetrieveSpecificAlerts() { - Assert.True(await client.AddAlert(AlertType.Email, "example1@ceecore.com")); - Assert.True(await client.AddAlert(AlertType.Boxcar, "example2@ceecore.com")); + Assert.NotNull(await client.AddAlert(AlertType.Email, "example1@ceecore.com")); + Assert.NotNull(await client.AddAlert(AlertType.Boxcar, "example2@ceecore.com")); List alerts = await client.GetAlerts(); diff --git a/UptimeSharp/Components/Alert.cs b/UptimeSharp/Components/Alert.cs index 375bc73..cddb60e 100644 --- a/UptimeSharp/Components/Alert.cs +++ b/UptimeSharp/Components/Alert.cs @@ -51,19 +51,29 @@ namespace UptimeSharp /// The value. /// The cancellation token. /// - /// - public async Task AddAlert(AlertType type, string value, CancellationToken cancellationToken = default(CancellationToken)) + /// AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API + public async Task AddAlert(AlertType type, string value, CancellationToken cancellationToken = default(CancellationToken)) { if (type == AlertType.SMS || type == AlertType.Twitter) { throw new UptimeSharpException("AlertType.SMS and AlertType.Twitter are not supported by the UptimeRobot API"); } - return (await Request("newAlertContact", cancellationToken, new Dictionary() + AddAlertResponse response = await Request("newAlertContact", cancellationToken, new Dictionary() { { "alertContactType", ((int)type).ToString() }, { "alertContactValue", value } - })).Success; + }); + + Alert alert = response.Alert; + + if (alert != null) + { + alert.Type = type; + alert.Value = value; + } + + return alert; } @@ -75,7 +85,7 @@ namespace UptimeSharp /// The cancellation token. /// /// - public async Task AddAlert(Alert alert, CancellationToken cancellationToken = default(CancellationToken)) + public async Task AddAlert(Alert alert, CancellationToken cancellationToken = default(CancellationToken)) { return await AddAlert(alert.Type, alert.Value, cancellationToken); }