2020-03-30 21:53:30 +11:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Umbraco.Core.Models.Membership;
|
|
|
|
|
using Umbraco.Tests.Common.Builders.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Common.Builders
|
|
|
|
|
{
|
2020-04-01 12:07:54 +02:00
|
|
|
public class UserGroupBuilder : UserGroupBuilder<object>
|
|
|
|
|
{
|
|
|
|
|
public UserGroupBuilder() : base(null)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UserGroupBuilder<TParent>
|
|
|
|
|
: ChildBuilderBase<TParent, IUserGroup>,
|
|
|
|
|
IWithIdBuilder,
|
|
|
|
|
IWithIconBuilder,
|
|
|
|
|
IWithAliasBuilder,
|
|
|
|
|
IWithNameBuilder
|
2020-03-30 21:53:30 +11:00
|
|
|
{
|
|
|
|
|
private int? _startContentId;
|
|
|
|
|
private int? _startMediaId;
|
|
|
|
|
private string _alias;
|
|
|
|
|
private string _icon;
|
|
|
|
|
private string _name;
|
|
|
|
|
private IEnumerable<string> _permissions = Enumerable.Empty<string>();
|
|
|
|
|
private IEnumerable<string> _sectionCollection = Enumerable.Empty<string>();
|
|
|
|
|
private string _suffix;
|
|
|
|
|
private int? _id;
|
|
|
|
|
|
2020-04-01 12:07:54 +02:00
|
|
|
public UserGroupBuilder(TParent parentBuilder) : base(parentBuilder)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 21:53:30 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Will suffix the name and alias for testing
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="suffix"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-04-01 12:07:54 +02:00
|
|
|
public UserGroupBuilder<TParent> WithSuffix(string suffix)
|
2020-03-30 21:53:30 +11:00
|
|
|
{
|
|
|
|
|
_suffix = suffix;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IReadOnlyUserGroup BuildReadOnly(IUserGroup userGroup)
|
|
|
|
|
{
|
|
|
|
|
return Mock.Of<IReadOnlyUserGroup>(x =>
|
|
|
|
|
x.Permissions == userGroup.Permissions &&
|
|
|
|
|
x.Alias == userGroup.Alias &&
|
|
|
|
|
x.Icon == userGroup.Icon &&
|
|
|
|
|
x.Name == userGroup.Name &&
|
|
|
|
|
x.StartContentId == userGroup.StartContentId &&
|
|
|
|
|
x.StartMediaId == userGroup.StartMediaId &&
|
|
|
|
|
x.AllowedSections == userGroup.AllowedSections &&
|
|
|
|
|
x.Id == userGroup.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IUserGroup Build()
|
|
|
|
|
{
|
2020-04-12 09:47:44 +02:00
|
|
|
var userGroup = Mock.Of<IUserGroup>(x =>
|
2020-03-30 21:53:30 +11:00
|
|
|
x.StartContentId == _startContentId &&
|
|
|
|
|
x.StartMediaId == _startMediaId &&
|
|
|
|
|
x.Name == (_name ?? ("TestUserGroup" + _suffix)) &&
|
|
|
|
|
x.Alias == (_alias ?? ("testUserGroup" + _suffix)) &&
|
|
|
|
|
x.Icon == _icon &&
|
|
|
|
|
x.Permissions == _permissions &&
|
|
|
|
|
x.AllowedSections == _sectionCollection);
|
2020-04-12 09:47:44 +02:00
|
|
|
return userGroup;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:39:30 +02:00
|
|
|
int? IWithIdBuilder.Id
|
2020-03-30 21:53:30 +11:00
|
|
|
{
|
|
|
|
|
get => _id;
|
|
|
|
|
set => _id = value;
|
|
|
|
|
}
|
2020-04-01 12:07:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
string IWithIconBuilder.Icon
|
|
|
|
|
{
|
|
|
|
|
get => _icon;
|
|
|
|
|
set => _icon = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string IWithAliasBuilder.Alias
|
|
|
|
|
{
|
|
|
|
|
get => _alias;
|
|
|
|
|
set => _alias = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string IWithNameBuilder.Name
|
|
|
|
|
{
|
|
|
|
|
get => _name;
|
|
|
|
|
set => _name = value;
|
|
|
|
|
}
|
2020-03-30 21:53:30 +11:00
|
|
|
}
|
|
|
|
|
}
|