Migrated user tests into new project and builder pattern.
This commit is contained in:
@@ -116,5 +116,60 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
builder.Thumbnail = thumbnail;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithLogin<T>(this T builder, string username, string rawPasswordValue)
|
||||
where T : IWithLoginBuilder
|
||||
{
|
||||
builder.Username = username;
|
||||
builder.RawPasswordValue = rawPasswordValue;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithEmail<T>(this T builder, string email)
|
||||
where T : IWithEmailBuilder
|
||||
{
|
||||
builder.Email = email;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithFailedPasswordAttempts<T>(this T builder, int failedPasswordAttempts)
|
||||
where T : IWithFailedPasswordAttemptsBuilder
|
||||
{
|
||||
builder.FailedPasswordAttempts = failedPasswordAttempts;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithIsApproved<T>(this T builder, bool isApproved)
|
||||
where T : IWithIsApprovedBuilder
|
||||
{
|
||||
builder.IsApproved = isApproved;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithIsLockedOut<T>(this T builder, bool isLockedOut, DateTime? lastLockoutDate = null)
|
||||
where T : IWithIsLockedOutBuilder
|
||||
{
|
||||
builder.IsLockedOut = isLockedOut;
|
||||
if (lastLockoutDate.HasValue)
|
||||
{
|
||||
builder.LastLockoutDate = lastLockoutDate.Value;
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithLastLoginDate<T>(this T builder, DateTime lastLoginDate)
|
||||
where T : IWithLastLoginDateBuilder
|
||||
{
|
||||
builder.LastLoginDate = lastLoginDate;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithLastPasswordChangeDate<T>(this T builder, DateTime lastPasswordChangeDate)
|
||||
where T : IWithLastPasswordChangeDateBuilder
|
||||
{
|
||||
builder.LastPasswordChangeDate = lastPasswordChangeDate;
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IAccountBuilder : IWithLoginBuilder,
|
||||
IWithEmailBuilder,
|
||||
IWithFailedPasswordAttemptsBuilder,
|
||||
IWithIsApprovedBuilder,
|
||||
IWithIsLockedOutBuilder,
|
||||
IWithLastLoginDateBuilder,
|
||||
IWithLastPasswordChangeDateBuilder
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithApprovedBuilder
|
||||
{
|
||||
bool? Approved { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithEmailBuilder
|
||||
{
|
||||
string Email { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithFailedPasswordAttemptsBuilder
|
||||
{
|
||||
int? FailedPasswordAttempts { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithIsApprovedBuilder
|
||||
{
|
||||
bool? IsApproved { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithIsLockedOutBuilder
|
||||
{
|
||||
bool? IsLockedOut { get; set; }
|
||||
|
||||
DateTime? LastLockoutDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithLastLoginDateBuilder
|
||||
{
|
||||
DateTime? LastLoginDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithLastPasswordChangeDateBuilder
|
||||
{
|
||||
DateTime? LastPasswordChangeDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Umbraco.Tests.Common.Builders.Interfaces
|
||||
{
|
||||
public interface IWithLoginBuilder
|
||||
{
|
||||
string Username { get; set; }
|
||||
|
||||
string RawPasswordValue { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ namespace Umbraco.Tests.Common.Builders
|
||||
IWithTrashedBuilder,
|
||||
IWithLevelBuilder,
|
||||
IWithPathBuilder,
|
||||
IWithSortOrderBuilder
|
||||
IWithSortOrderBuilder,
|
||||
IAccountBuilder
|
||||
{
|
||||
private MemberTypeBuilder _memberTypeBuilder;
|
||||
private GenericCollectionBuilder<MemberBuilder, string> _memberGroupsBuilder;
|
||||
@@ -28,12 +29,12 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private DateTime? _updateDate;
|
||||
private string _name;
|
||||
private int? _creatorId;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private string _username;
|
||||
private string _rawPasswordValue;
|
||||
private string _email;
|
||||
private int? _failedPasswordAttempts;
|
||||
private int? _level;
|
||||
private string _path;
|
||||
private bool? _isApproved;
|
||||
private bool? _isLockedOut;
|
||||
private DateTime? _lastLockoutDate;
|
||||
@@ -43,60 +44,6 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private bool? _trashed;
|
||||
private int? _propertyIdsIncrementingFrom;
|
||||
|
||||
public MemberBuilder WithUserName(string username)
|
||||
{
|
||||
_username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithEmail(string email)
|
||||
{
|
||||
_email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithRawPasswordValue(string rawPasswordValue)
|
||||
{
|
||||
_rawPasswordValue = rawPasswordValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithFailedPasswordAttempts(int failedPasswordAttempts)
|
||||
{
|
||||
_failedPasswordAttempts = failedPasswordAttempts;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithIsApproved(bool isApproved)
|
||||
{
|
||||
_isApproved = isApproved;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithIsLockedOut(bool isLockedOut)
|
||||
{
|
||||
_isLockedOut = isLockedOut;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithLastLockoutDate(DateTime lastLockoutDate)
|
||||
{
|
||||
_lastLockoutDate = lastLockoutDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithLastLoginDate(DateTime lastLoginDate)
|
||||
{
|
||||
_lastLoginDate = lastLoginDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithLastPasswordChangeDate(DateTime lastPasswordChangeDate)
|
||||
{
|
||||
_lastPasswordChangeDate = lastPasswordChangeDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MemberBuilder WithPropertyIdsIncrementingFrom(int propertyIdsIncrementingFrom)
|
||||
{
|
||||
_propertyIdsIncrementingFrom = propertyIdsIncrementingFrom;
|
||||
@@ -139,19 +86,19 @@ namespace Umbraco.Tests.Common.Builders
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var creatorId = _creatorId ?? 1;
|
||||
var level = _level ?? 1;
|
||||
var path = _path ?? "-1";
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
var username = _username ?? string.Empty;
|
||||
var email = _email ?? string.Empty;
|
||||
var rawPasswordValue = _rawPasswordValue ?? string.Empty;
|
||||
var failedPasswordAttempts = _failedPasswordAttempts ?? 0;
|
||||
var level = _level ?? 1;
|
||||
var path = _path ?? "-1";
|
||||
var isApproved = _isApproved ?? false;
|
||||
var isLockedOut = _isLockedOut ?? false;
|
||||
var lastLockoutDate = _lastLockoutDate ?? DateTime.Now;
|
||||
var lastLoginDate = _lastLoginDate ?? DateTime.Now;
|
||||
var lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now;
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var trashed = _trashed ?? false;
|
||||
|
||||
if (_memberTypeBuilder == null)
|
||||
{
|
||||
@@ -276,5 +223,59 @@ namespace Umbraco.Tests.Common.Builders
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
string IWithLoginBuilder.Username
|
||||
{
|
||||
get => _username;
|
||||
set => _username = value;
|
||||
}
|
||||
|
||||
string IWithLoginBuilder.RawPasswordValue
|
||||
{
|
||||
get => _rawPasswordValue;
|
||||
set => _rawPasswordValue = value;
|
||||
}
|
||||
|
||||
string IWithEmailBuilder.Email
|
||||
{
|
||||
get => _email;
|
||||
set => _email = value;
|
||||
}
|
||||
|
||||
int? IWithFailedPasswordAttemptsBuilder.FailedPasswordAttempts
|
||||
{
|
||||
get => _failedPasswordAttempts;
|
||||
set => _failedPasswordAttempts = value;
|
||||
}
|
||||
|
||||
bool? IWithIsApprovedBuilder.IsApproved
|
||||
{
|
||||
get => _isApproved;
|
||||
set => _isApproved = value;
|
||||
}
|
||||
|
||||
bool? IWithIsLockedOutBuilder.IsLockedOut
|
||||
{
|
||||
get => _isLockedOut;
|
||||
set => _isLockedOut = value;
|
||||
}
|
||||
|
||||
DateTime? IWithIsLockedOutBuilder.LastLockoutDate
|
||||
{
|
||||
get => _lastLockoutDate;
|
||||
set => _lastLockoutDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithLastLoginDateBuilder.LastLoginDate
|
||||
{
|
||||
get => _lastLoginDate;
|
||||
set => _lastLoginDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithLastPasswordChangeDateBuilder.LastPasswordChangeDate
|
||||
{
|
||||
get => _lastPasswordChangeDate;
|
||||
set => _lastPasswordChangeDate = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Umbraco.Configuration.Models;
|
||||
using System;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
|
||||
public class UserBuilder : UserBuilder<object>
|
||||
{
|
||||
public UserBuilder() : base(null)
|
||||
@@ -15,27 +14,57 @@ namespace Umbraco.Tests.Common.Builders
|
||||
public class UserBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, User>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithApprovedBuilder
|
||||
IAccountBuilder
|
||||
{
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private string _language;
|
||||
private bool? _approved;
|
||||
private string _name;
|
||||
private string _rawPassword;
|
||||
private bool? _isLockedOut;
|
||||
private string _email;
|
||||
private string _username;
|
||||
private string _rawPasswordValue;
|
||||
private string _email;
|
||||
private int? _failedPasswordAttempts;
|
||||
private bool? _isApproved;
|
||||
private bool? _isLockedOut;
|
||||
private DateTime? _lastLockoutDate;
|
||||
private DateTime? _lastLoginDate;
|
||||
private DateTime? _lastPasswordChangeDate;
|
||||
private string _suffix = string.Empty;
|
||||
private string _defaultLang;
|
||||
|
||||
private string _comments;
|
||||
private int? _sessionTimeout;
|
||||
private int[] _startContentIds;
|
||||
private int[] _startMediaIds;
|
||||
|
||||
public UserBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithDefaultUILanguage(string defaultLang)
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithDefaultUILanguage(string defaultLang)
|
||||
{
|
||||
_defaultLang = defaultLang;
|
||||
return this;
|
||||
@@ -47,27 +76,27 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithRawPassword(string rawPassword)
|
||||
public UserBuilder<TParent> WithComments(string comments)
|
||||
{
|
||||
_rawPassword = rawPassword;
|
||||
_comments = comments;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithEmail(string email)
|
||||
public UserBuilder<TParent> WithSessionTimeout(int sessionTimeout)
|
||||
{
|
||||
_email = email;
|
||||
_sessionTimeout = sessionTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithUsername(string username)
|
||||
public UserBuilder<TParent> WithStartContentIds(int[] startContentIds)
|
||||
{
|
||||
_username = username;
|
||||
_startContentIds = startContentIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserBuilder<TParent> WithLockedOut(bool isLockedOut)
|
||||
public UserBuilder<TParent> WithStartMediaIds(int[] startMediaIds)
|
||||
{
|
||||
_isLockedOut = isLockedOut;
|
||||
_startMediaIds = startMediaIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -84,25 +113,50 @@ namespace Umbraco.Tests.Common.Builders
|
||||
|
||||
public override User Build()
|
||||
{
|
||||
var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage(_defaultLang).Build();
|
||||
var id = _id ?? 1;
|
||||
var defaultLang = _defaultLang ?? "en";
|
||||
var globalSettings = new GlobalSettingsBuilder().WithDefaultUiLanguage(defaultLang).Build();
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var name = _name ?? "TestUser" + _suffix;
|
||||
var email = _email ?? "test" + _suffix + "@test.com";
|
||||
var username = _username ?? "TestUser" + _suffix;
|
||||
var rawPassword = _rawPassword ?? "abcdefghijklmnopqrstuvwxyz";
|
||||
var language = _language ?? globalSettings.DefaultUILanguage;
|
||||
var username = _username ?? "TestUser" + _suffix;
|
||||
var email = _email ?? "test" + _suffix + "@test.com";
|
||||
var rawPasswordValue = _rawPasswordValue ?? "abcdefghijklmnopqrstuvwxyz";
|
||||
var failedPasswordAttempts = _failedPasswordAttempts ?? 0;
|
||||
var isApproved = _isApproved ?? false;
|
||||
var isLockedOut = _isLockedOut ?? false;
|
||||
var approved = _approved ?? true;
|
||||
var lastLockoutDate = _lastLockoutDate ?? DateTime.Now;
|
||||
var lastLoginDate = _lastLoginDate ?? DateTime.Now;
|
||||
var lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now;
|
||||
var comments = _comments ?? string.Empty;
|
||||
var sessionTimeout = _sessionTimeout ?? 0;
|
||||
var startContentIds = _startContentIds ?? new int[0];
|
||||
var startMediaIds = _startMediaIds ?? new int[0];
|
||||
|
||||
return new User(
|
||||
globalSettings,
|
||||
name,
|
||||
email,
|
||||
username,
|
||||
rawPassword)
|
||||
rawPasswordValue)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
Language = language,
|
||||
FailedPasswordAttempts = failedPasswordAttempts,
|
||||
IsApproved = isApproved,
|
||||
IsLockedOut = isLockedOut,
|
||||
IsApproved = approved
|
||||
LastLockoutDate = lastLockoutDate,
|
||||
LastLoginDate = lastLoginDate,
|
||||
LastPasswordChangeDate = lastPasswordChangeDate,
|
||||
Comments = comments,
|
||||
SessionTimeout = sessionTimeout,
|
||||
StartContentIds = startContentIds,
|
||||
StartMediaIds = startMediaIds,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -118,10 +172,58 @@ namespace Umbraco.Tests.Common.Builders
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
bool? IWithApprovedBuilder.Approved
|
||||
string IWithLoginBuilder.Username
|
||||
{
|
||||
get => _approved;
|
||||
set => _approved = value;
|
||||
get => _username;
|
||||
set => _username = value;
|
||||
}
|
||||
|
||||
string IWithLoginBuilder.RawPasswordValue
|
||||
{
|
||||
get => _rawPasswordValue;
|
||||
set => _rawPasswordValue = value;
|
||||
}
|
||||
|
||||
string IWithEmailBuilder.Email
|
||||
{
|
||||
get => _email;
|
||||
set => _email = value;
|
||||
}
|
||||
|
||||
int? IWithFailedPasswordAttemptsBuilder.FailedPasswordAttempts
|
||||
{
|
||||
get => _failedPasswordAttempts;
|
||||
set => _failedPasswordAttempts = value;
|
||||
}
|
||||
|
||||
bool? IWithIsApprovedBuilder.IsApproved
|
||||
{
|
||||
get => _isApproved;
|
||||
set => _isApproved = value;
|
||||
}
|
||||
|
||||
bool? IWithIsLockedOutBuilder.IsLockedOut
|
||||
{
|
||||
get => _isLockedOut;
|
||||
set => _isLockedOut = value;
|
||||
}
|
||||
|
||||
DateTime? IWithIsLockedOutBuilder.LastLockoutDate
|
||||
{
|
||||
get => _lastLockoutDate;
|
||||
set => _lastLockoutDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithLastLoginDateBuilder.LastLoginDate
|
||||
{
|
||||
get => _lastLoginDate;
|
||||
set => _lastLoginDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithLastPasswordChangeDateBuilder.LastPasswordChangeDate
|
||||
{
|
||||
get => _lastPasswordChangeDate;
|
||||
set => _lastPasswordChangeDate = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,14 +116,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
.Done()
|
||||
.Done()
|
||||
.WithId(10)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithName("Fred")
|
||||
.WithUserName("fred")
|
||||
.WithRawPasswordValue("raw pass")
|
||||
.WithLogin("fred", "raw pass")
|
||||
.WithEmail("email@email.com")
|
||||
.WithCreatorId(22)
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithFailedPasswordAttempts(22)
|
||||
.WithLevel(3)
|
||||
.WithPath("-1, 4, 10")
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserTests
|
||||
{
|
||||
private readonly UserBuilder _builder = new UserBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = BuildUser();
|
||||
|
||||
var clone = (User)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
|
||||
Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count());
|
||||
|
||||
//Verify normal properties with reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var item = BuildUser();
|
||||
|
||||
var json = JsonConvert.SerializeObject(item);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private User BuildUser()
|
||||
{
|
||||
return _builder
|
||||
.WithId(3)
|
||||
.WithLogin("username", "test pass")
|
||||
.WithName("Test")
|
||||
.WithEmail("test@test.com")
|
||||
.WithFailedPasswordAttempts(3)
|
||||
.WithIsApproved(true)
|
||||
.WithIsLockedOut(true)
|
||||
.WithComments("comments")
|
||||
.WithSessionTimeout(5)
|
||||
.WithStartContentIds(new[] { 3 })
|
||||
.WithStartMediaIds(new[] { 8 })
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
var testKey = Guid.NewGuid();
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
const int testFailedPasswordAttempts = 22;
|
||||
var testLastLockoutDate = DateTime.Now.AddHours(-2);
|
||||
var testLastLoginDate = DateTime.Now.AddHours(-3);
|
||||
var testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
|
||||
@@ -104,18 +105,16 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithName(testName)
|
||||
.WithUserName(testUsername)
|
||||
.WithRawPasswordValue(testRawPasswordValue)
|
||||
.WithLogin(testUsername, testRawPasswordValue)
|
||||
.WithEmail(testEmail)
|
||||
.WithCreatorId(testCreatorId)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.WithFailedPasswordAttempts(22)
|
||||
.WithLevel(testLevel)
|
||||
.WithPath(testPath)
|
||||
.WithFailedPasswordAttempts(testFailedPasswordAttempts)
|
||||
.WithIsApproved(testIsApproved)
|
||||
.WithIsLockedOut(testIsLockedOut)
|
||||
.WithLastLockoutDate(testLastLockoutDate)
|
||||
.WithIsLockedOut(testIsLockedOut, testLastLockoutDate)
|
||||
.WithLastLoginDate(testLastLoginDate)
|
||||
.WithLastPasswordChangeDate(testLastPasswordChangeDate)
|
||||
.WithSortOrder(testSortOrder)
|
||||
@@ -146,6 +145,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
Assert.AreEqual(testCreateDate, member.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, member.UpdateDate);
|
||||
Assert.AreEqual(testCreatorId, member.CreatorId);
|
||||
Assert.AreEqual(testFailedPasswordAttempts, member.FailedPasswordAttempts);
|
||||
Assert.AreEqual(testIsApproved, member.IsApproved);
|
||||
Assert.AreEqual(testIsLockedOut, member.IsLockedOut);
|
||||
Assert.AreEqual(testLastLockoutDate, member.LastLockoutDate);
|
||||
Assert.AreEqual(testLastLoginDate, member.LastLoginDate);
|
||||
Assert.AreEqual(testLastPasswordChangeDate, member.LastPasswordChangeDate);
|
||||
Assert.AreEqual(testGroups, member.Groups.ToArray());
|
||||
Assert.AreEqual(10, member.Properties.Count); // 7 from membership properties group, 3 custom
|
||||
Assert.AreEqual(testPropertyData1.Value, member.GetValue<string>(testPropertyData1.Key));
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int testId = 10;
|
||||
const string testName = "Fred";
|
||||
const string testUsername = "fred";
|
||||
const string testRawPasswordValue = "raw pass";
|
||||
const string testEmail = "email@email.com";
|
||||
const bool testIsApproved = true;
|
||||
const bool testIsLockedOut = true;
|
||||
var testKey = Guid.NewGuid();
|
||||
var testCreateDate = DateTime.Now.AddHours(-1);
|
||||
var testUpdateDate = DateTime.Now;
|
||||
const int testFailedPasswordAttempts = 22;
|
||||
var testLastLockoutDate = DateTime.Now.AddHours(-2);
|
||||
var testLastLoginDate = DateTime.Now.AddHours(-3);
|
||||
var testLastPasswordChangeDate = DateTime.Now.AddHours(-4);
|
||||
var testComments = "comments";
|
||||
var testSessionTimeout = 5;
|
||||
var testStartContentIds = new[] { 3 };
|
||||
var testStartMediaIds = new[] { 8 };
|
||||
|
||||
var builder = new UserBuilder();
|
||||
|
||||
// Act
|
||||
var user = builder
|
||||
.WithId(testId)
|
||||
.WithKey(testKey)
|
||||
.WithName(testName)
|
||||
.WithLogin(testUsername, testRawPasswordValue)
|
||||
.WithEmail(testEmail)
|
||||
.WithCreateDate(testCreateDate)
|
||||
.WithUpdateDate(testUpdateDate)
|
||||
.WithFailedPasswordAttempts(testFailedPasswordAttempts)
|
||||
.WithIsApproved(testIsApproved)
|
||||
.WithIsLockedOut(testIsLockedOut, testLastLockoutDate)
|
||||
.WithLastLoginDate(testLastLoginDate)
|
||||
.WithLastPasswordChangeDate(testLastPasswordChangeDate)
|
||||
.WithComments(testComments)
|
||||
.WithSessionTimeout(5)
|
||||
.WithStartContentIds(new[] { 3 })
|
||||
.WithStartMediaIds(new[] { 8 })
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testId, user.Id);
|
||||
Assert.AreEqual(testKey, user.Key);
|
||||
Assert.AreEqual(testName, user.Name);
|
||||
Assert.AreEqual(testCreateDate, user.CreateDate);
|
||||
Assert.AreEqual(testUpdateDate, user.UpdateDate);
|
||||
Assert.AreEqual(testFailedPasswordAttempts, user.FailedPasswordAttempts);
|
||||
Assert.AreEqual(testIsApproved, user.IsApproved);
|
||||
Assert.AreEqual(testIsLockedOut, user.IsLockedOut);
|
||||
Assert.AreEqual(testLastLockoutDate, user.LastLockoutDate);
|
||||
Assert.AreEqual(testLastLoginDate, user.LastLoginDate);
|
||||
Assert.AreEqual(testLastPasswordChangeDate, user.LastPasswordChangeDate);
|
||||
Assert.AreEqual(testComments, user.Comments);
|
||||
Assert.AreEqual(testSessionTimeout, user.SessionTimeout);
|
||||
Assert.AreEqual(testStartContentIds, user.StartContentIds);
|
||||
Assert.AreEqual(testStartMediaIds, user.StartMediaIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserTests
|
||||
{
|
||||
private IGlobalSettings GlobalSettings { get; } = SettingsForTests.DefaultGlobalSettings;
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new User(GlobalSettings)
|
||||
{
|
||||
Id = 3,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
CreateDate = DateTime.Now,
|
||||
Name = "Test",
|
||||
Comments = "comments",
|
||||
Email = "test@test.com",
|
||||
Language = "en",
|
||||
FailedPasswordAttempts = 3,
|
||||
IsApproved = true,
|
||||
IsLockedOut = true,
|
||||
LastLockoutDate = DateTime.Now,
|
||||
LastLoginDate = DateTime.Now,
|
||||
LastPasswordChangeDate = DateTime.Now,
|
||||
//Password = "test pass",
|
||||
SessionTimeout = 5,
|
||||
StartContentIds = new[] { 3 },
|
||||
StartMediaIds = new[] { 8 },
|
||||
Username = "username"
|
||||
};
|
||||
|
||||
var clone = (User)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
|
||||
Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count());
|
||||
|
||||
//Verify normal properties with reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var item = new User(GlobalSettings)
|
||||
{
|
||||
Id = 3,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
CreateDate = DateTime.Now,
|
||||
Name = "Test",
|
||||
Comments = "comments",
|
||||
Email = "test@test.com",
|
||||
Language = "en",
|
||||
FailedPasswordAttempts = 3,
|
||||
IsApproved = true,
|
||||
IsLockedOut = true,
|
||||
LastLockoutDate = DateTime.Now,
|
||||
LastLoginDate = DateTime.Now,
|
||||
LastPasswordChangeDate = DateTime.Now,
|
||||
//Password = "test pass",
|
||||
SessionTimeout = 5,
|
||||
StartContentIds = new[] { 3 },
|
||||
StartMediaIds = new[] { 8 },
|
||||
Username = "username"
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(item);
|
||||
Debug.Print(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,7 +297,6 @@
|
||||
<Compile Include="Models\DeepCloneHelperTests.cs" />
|
||||
<Compile Include="Models\DictionaryTranslationTests.cs" />
|
||||
<Compile Include="Models\LightEntityTest.cs" />
|
||||
<Compile Include="Models\UserTests.cs" />
|
||||
<Compile Include="Web\Mvc\RenderModelBinderTests.cs" />
|
||||
<Compile Include="Web\Mvc\SurfaceControllerTests.cs" />
|
||||
<Compile Include="Web\Mvc\UmbracoViewPageTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user