add account registration

This commit is contained in:
2014-02-03 22:58:22 +01:00
parent 83e4cb5767
commit dfa9373223
3 changed files with 104 additions and 5 deletions
+38 -5
View File
@@ -20,15 +20,48 @@ namespace UptimeSharp.Tests
await client.IsEmailAvailable("");
});
await ThrowsAsync<ArgumentNullException>(async () =>
{
await client.IsEmailAvailable("");
});
await ThrowsAsync<ArgumentException>(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<ArgumentNullException>(async () =>
{
await client.RegisterAccount("", "cee@live.at", "poiuadfafo");
});
await ThrowsAsync<ArgumentNullException>(async () =>
{
await client.RegisterAccount("my name", "", "poiuadfafo");
});
await ThrowsAsync<ArgumentNullException>(async () =>
{
await client.RegisterAccount("my name", "cee@live.at", "");
});
await ThrowsAsync<ArgumentException>(async () =>
{
await client.RegisterAccount("my name", "opiu@opiuast", "password");
});
await ThrowsAsync<ArgumentException>(async () =>
{
await client.RegisterAccount("my", "cee@live.at", "password");
});
await ThrowsAsync<ArgumentException>(async () =>
{
await client.RegisterAccount("my name", "cee@live.at", "pass");
});
}
}
}
+48
View File
@@ -39,5 +39,53 @@ namespace UptimeSharp
{ "userEmail", email }
})).Success;
}
/// <summary>
/// Registers the account.
/// </summary>
/// <param name="fullName">The full name (min. 3 chars).</param>
/// <param name="email">The email address.</param>
/// <param name="password">The password (min. 6 chars).</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">Please provide all parameters (username, email and password)</exception>
/// <exception cref="System.ArgumentException">
/// Please provide a valid e-mail address
/// or
/// Name must be at least 3 characters
/// or
/// Username must be at least 6 characters
/// </exception>
public async Task<bool> 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<string, string>()
{
{ "userFirstLastName", fullName },
{ "userEmail", email },
{ "userPassword", password }
}, true)).Success;
}
}
}
+18
View File
@@ -199,6 +199,24 @@ namespace UptimeSharp
/// <exception cref="System.ArgumentNullException">Please provide an e-mail address</exception>
/// <exception cref="System.ArgumentException">Please provide a valid e-mail address</exception>
Task<bool> IsEmailAvailable(string email, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Registers the account.
/// </summary>
/// <param name="fullName">The full name (min. 3 chars).</param>
/// <param name="email">The email address.</param>
/// <param name="password">The password (min. 6 chars).</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">Please provide all parameters (username, email and password)</exception>
/// <exception cref="System.ArgumentException">
/// Please provide a valid e-mail address
/// or
/// Name must be at least 3 characters
/// or
/// Username must be at least 6 characters
/// </exception>
Task<bool> RegisterAccount(string fullName, string email, string password, CancellationToken cancellationToken = default(CancellationToken));
#endregion
}
}