From dfa937322388632cd2ef8a1e9921e426cdf45c87 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 3 Feb 2014 22:58:22 +0100 Subject: [PATCH] add account registration --- UptimeSharp.Tests/AccountTest.cs | 43 +++++++++++++++++++++++---- UptimeSharp/Components/Account.cs | 48 +++++++++++++++++++++++++++++++ UptimeSharp/IUptimeClient.cs | 18 ++++++++++++ 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/UptimeSharp.Tests/AccountTest.cs b/UptimeSharp.Tests/AccountTest.cs index b03687b..ef74690 100644 --- a/UptimeSharp.Tests/AccountTest.cs +++ b/UptimeSharp.Tests/AccountTest.cs @@ -20,15 +20,48 @@ namespace UptimeSharp.Tests await client.IsEmailAvailable(""); }); - await ThrowsAsync(async () => - { - await client.IsEmailAvailable(""); - }); - await ThrowsAsync(async () => { await client.IsEmailAvailable("opiu@opiuast"); }); } + + + [Fact] + public async Task IsAccountRegistrationWorking() + { + Assert.True(await client.RegisterAccount("my name", Guid.NewGuid().ToString() + "@live.at", "123456")); + Assert.False(await client.RegisterAccount("my name", "cee@live.at", "123456")); + + await ThrowsAsync(async () => + { + await client.RegisterAccount("", "cee@live.at", "poiuadfafo"); + }); + + await ThrowsAsync(async () => + { + await client.RegisterAccount("my name", "", "poiuadfafo"); + }); + + await ThrowsAsync(async () => + { + await client.RegisterAccount("my name", "cee@live.at", ""); + }); + + await ThrowsAsync(async () => + { + await client.RegisterAccount("my name", "opiu@opiuast", "password"); + }); + + await ThrowsAsync(async () => + { + await client.RegisterAccount("my", "cee@live.at", "password"); + }); + + await ThrowsAsync(async () => + { + await client.RegisterAccount("my name", "cee@live.at", "pass"); + }); + } } } diff --git a/UptimeSharp/Components/Account.cs b/UptimeSharp/Components/Account.cs index 0824d2c..fe27f80 100644 --- a/UptimeSharp/Components/Account.cs +++ b/UptimeSharp/Components/Account.cs @@ -39,5 +39,53 @@ namespace UptimeSharp { "userEmail", email } })).Success; } + + + + /// + /// Registers the account. + /// + /// The full name (min. 3 chars). + /// The email address. + /// The password (min. 6 chars). + /// The cancellation token. + /// + /// Please provide all parameters (username, email and password) + /// + /// Please provide a valid e-mail address + /// or + /// Name must be at least 3 characters + /// or + /// Username must be at least 6 characters + /// + public async Task RegisterAccount(string fullName, string email, string password, CancellationToken cancellationToken = default(CancellationToken)) + { + if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(fullName) || String.IsNullOrEmpty(password)) + { + throw new ArgumentNullException("Please provide all parameters (username, email and password)"); + } + + if (!isEmailRegex.IsMatch(email)) + { + throw new ArgumentException("Please provide a valid e-mail address"); + } + + if (fullName.Length < 3) + { + throw new ArgumentException("Name must be at least 3 characters"); + } + + if (password.Length < 6) + { + throw new ArgumentException("Username must be at least 6 characters"); + } + + return (await AccountRequest("newUser", cancellationToken, new Dictionary() + { + { "userFirstLastName", fullName }, + { "userEmail", email }, + { "userPassword", password } + }, true)).Success; + } } } \ No newline at end of file diff --git a/UptimeSharp/IUptimeClient.cs b/UptimeSharp/IUptimeClient.cs index 0436c21..ae94834 100644 --- a/UptimeSharp/IUptimeClient.cs +++ b/UptimeSharp/IUptimeClient.cs @@ -199,6 +199,24 @@ namespace UptimeSharp /// Please provide an e-mail address /// Please provide a valid e-mail address Task IsEmailAvailable(string email, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Registers the account. + /// + /// The full name (min. 3 chars). + /// The email address. + /// The password (min. 6 chars). + /// The cancellation token. + /// + /// Please provide all parameters (username, email and password) + /// + /// Please provide a valid e-mail address + /// or + /// Name must be at least 3 characters + /// or + /// Username must be at least 6 characters + /// + Task RegisterAccount(string fullName, string email, string password, CancellationToken cancellationToken = default(CancellationToken)); #endregion } }