Ensures a default member/user type is assigned on membership provider initialize, adds more unit tests

This commit is contained in:
Shannon
2014-01-06 16:18:25 +11:00
parent cd82bc6d21
commit f3f7aa70d1
8 changed files with 166 additions and 37 deletions

View File

@@ -25,8 +25,14 @@ namespace Umbraco.Core.Services
/// Idea is to have this is an isolated interface so that it can be easily 'replaced' in the membership provider impl.
/// </remarks>
public interface IMembershipMemberService<T> : IService
where T : IMembershipUser
where T : class, IMembershipUser
{
/// <summary>
/// Returns the default member type alias
/// </summary>
/// <returns></returns>
string GetDefaultMemberType();
/// <summary>
/// Checks if a member with the username exists
/// </summary>

View File

@@ -42,6 +42,30 @@ namespace Umbraco.Core.Services
#region IMemberService Implementation
/// <summary>
/// Get the default member type from the database - first check if the type "Member" is there, if not choose the first one found
/// </summary>
/// <returns></returns>
public string GetDefaultMemberType()
{
using (var repository = _repositoryFactory.CreateMemberTypeRepository(_uowProvider.GetUnitOfWork()))
{
var types = repository.GetAll().Select(x => x.Alias).ToArray();
if (types.Any() == false)
{
throw new InvalidOperationException("No member types could be resolved");
}
if (types.InvariantContains("Member"))
{
return types.First(x => x.InvariantEquals("Member"));
}
return types.First();
}
}
/// <summary>
/// Checks if a member with the username exists
/// </summary>

View File

@@ -37,6 +37,37 @@ namespace Umbraco.Core.Services
#region Implementation of IMembershipUserService
/// <summary>
/// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll return the first type that is not an admin, otherwise if there's only one
/// we will return that one.
/// </summary>
/// <returns></returns>
public string GetDefaultMemberType()
{
using (var repository = _repositoryFactory.CreateUserTypeRepository(_uowProvider.GetUnitOfWork()))
{
var types = repository.GetAll().Select(x => x.Alias).ToArray();
if (types.Any() == false)
{
throw new InvalidOperationException("No member types could be resolved");
}
if (types.InvariantContains("writer"))
{
return types.First(x => x.InvariantEquals("writer"));
}
if (types.Length == 1)
{
return types.First();
}
//first that is not admin
return types.First(x => x.InvariantEquals("admin") == false);
}
}
public bool Exists(string username)
{
using (var repository = _repositoryFactory.CreateUserRepository(_uowProvider.GetUnitOfWork()))