Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs

1390 lines
53 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
2020-10-11 09:46:48 +02:00
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Persistence.Querying;
using Umbraco.Cms.Core.Services;
V15: Remove Nucache (#17166) * Remove nucache reference from Web.Common * Get tests building-ish * Move ReservedFieldNamesService to the right project * Remove IPublishedSnapshotStatus * Added functionality to the INavigationQueryService to get root keys * Fixed issue with navigation * Remove IPublishedSnapshot from UmbracoContext * Begin removing usage of IPublishedSnapshot from PublishedContentExtensions * Fix PublishedContentExtensions.cs * Don't use snapshots in delivery media api * Use IPublishedMediaCache in QueryMediaApiController * Remove more usages of IPublishedSnapshotAccessor * Comment out tests * Remove more usages of PublishedSnapshotAccessor * Remove PublishedSnapshot from property * Fixed test build * Fix errors * Fix some tests * Delete NuCache 🎉 * Implement DatabaseCacheRebuilder * Remove usage of IPublishedSnapshotService * Remove IPublishedSnapshotService * Remove TestPublishedSnapshotAccessor and make tests build * Don't test Snapshot cachelevel It's no longer supported * Fix BlockEditorConverter Element != Element document type * Remember to set cachemanager * Fix RichTextParserTests * Implement TryGetLevel on INavigationQueryService * Fake level and obsolete it in PublishedContent * Remove ChildrenForAllCultures * Hack Path property on PublishedContent * Remove usages of IPublishedSnapshot in tests * More ConvertersTests * Add hybrid cache to integration tests We can actually do this now because we no longer save files on disk * Rename IPublishedSnapshotRebuilder to ICacheRebuilder * Comment out tests * V15: Replacing the usages of Parent (navigation data) from IPublishedContent (#17125) * Fix .Parent references in PublishedContentExtensions * Add missing methods to FriendlyPublishedContentExtensions (ones that you were able to call on the content directly as they now require extra params) * Fix references from the extension methods * Fix dependencies in tests * Replace IPublishedSnapshotAccessor with the content cache in tests * Resolving more .Parent references * Fix unit tests * Obsolete and use extension methods * Remove private method and use extension instead * Moving code around * Fix tests * Fix more references * Cleanup * Fix more usages * Resolve merge conflict * Fix tests * Cleanup * Fix more tests * Fixed unit tests * Cleanup * Replace last usages --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove usage of IPublishedSnapshotAccessor from IRequestItemProvider * Post merge fixup * Remo IPublishedSnapshot * Add HasAny to IDocumentUrlService * Fix TextBuilder * Fix modelsbuilder tests * Use explicit types * Implement GetByContentType * Support element types in PublishedContentTypeCache * Run enlistments before publishing notifications * Fix elements cache refreshing * Implement GetByUdi * Implement GetAtRoot * Implement GetByRoute * Reimplement GetRouteById * Fix blocks unit tests * Initialize domain cache on boot * Only return routes with domains on non default lanauges * V15: Replacing the usages of `Children` (navigation data) from `IPublishedContent` (#17159) * Update params in PublishedContentExtensions to the general interfaces for the published cache and navigation service, so that we can use the extension methods on both documents and media * Introduce GetParent() which uses the right services * Fix obsolete message on .Parent * Obsolete .Children * Fix usages of Children for ApiMediaQueryService * Fix usage in internal * Fix usages in views * Fix indentation * Fix issue with delete language * Update nuget pacakges * Clear elements cache when content is deleted instead of trying to update it * Reset publishedModelFactory * Fixed publishing --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: kjac <kja@umbraco.dk>
2024-10-01 15:03:02 +02:00
using Umbraco.Cms.Infrastructure.HybridCache.Factories;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
2020-10-11 09:46:48 +02:00
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
[TestFixture]
[Category("Slow")]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true,
WithApplication = true)]
public class MemberServiceTests : UmbracoIntegrationTest
2020-10-11 09:46:48 +02:00
{
private IMemberTypeService MemberTypeService => GetRequiredService<IMemberTypeService>();
private IMemberService MemberService => GetRequiredService<IMemberService>();
2020-10-11 09:46:48 +02:00
V15: Remove Nucache (#17166) * Remove nucache reference from Web.Common * Get tests building-ish * Move ReservedFieldNamesService to the right project * Remove IPublishedSnapshotStatus * Added functionality to the INavigationQueryService to get root keys * Fixed issue with navigation * Remove IPublishedSnapshot from UmbracoContext * Begin removing usage of IPublishedSnapshot from PublishedContentExtensions * Fix PublishedContentExtensions.cs * Don't use snapshots in delivery media api * Use IPublishedMediaCache in QueryMediaApiController * Remove more usages of IPublishedSnapshotAccessor * Comment out tests * Remove more usages of PublishedSnapshotAccessor * Remove PublishedSnapshot from property * Fixed test build * Fix errors * Fix some tests * Delete NuCache 🎉 * Implement DatabaseCacheRebuilder * Remove usage of IPublishedSnapshotService * Remove IPublishedSnapshotService * Remove TestPublishedSnapshotAccessor and make tests build * Don't test Snapshot cachelevel It's no longer supported * Fix BlockEditorConverter Element != Element document type * Remember to set cachemanager * Fix RichTextParserTests * Implement TryGetLevel on INavigationQueryService * Fake level and obsolete it in PublishedContent * Remove ChildrenForAllCultures * Hack Path property on PublishedContent * Remove usages of IPublishedSnapshot in tests * More ConvertersTests * Add hybrid cache to integration tests We can actually do this now because we no longer save files on disk * Rename IPublishedSnapshotRebuilder to ICacheRebuilder * Comment out tests * V15: Replacing the usages of Parent (navigation data) from IPublishedContent (#17125) * Fix .Parent references in PublishedContentExtensions * Add missing methods to FriendlyPublishedContentExtensions (ones that you were able to call on the content directly as they now require extra params) * Fix references from the extension methods * Fix dependencies in tests * Replace IPublishedSnapshotAccessor with the content cache in tests * Resolving more .Parent references * Fix unit tests * Obsolete and use extension methods * Remove private method and use extension instead * Moving code around * Fix tests * Fix more references * Cleanup * Fix more usages * Resolve merge conflict * Fix tests * Cleanup * Fix more tests * Fixed unit tests * Cleanup * Replace last usages --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove usage of IPublishedSnapshotAccessor from IRequestItemProvider * Post merge fixup * Remo IPublishedSnapshot * Add HasAny to IDocumentUrlService * Fix TextBuilder * Fix modelsbuilder tests * Use explicit types * Implement GetByContentType * Support element types in PublishedContentTypeCache * Run enlistments before publishing notifications * Fix elements cache refreshing * Implement GetByUdi * Implement GetAtRoot * Implement GetByRoute * Reimplement GetRouteById * Fix blocks unit tests * Initialize domain cache on boot * Only return routes with domains on non default lanauges * V15: Replacing the usages of `Children` (navigation data) from `IPublishedContent` (#17159) * Update params in PublishedContentExtensions to the general interfaces for the published cache and navigation service, so that we can use the extension methods on both documents and media * Introduce GetParent() which uses the right services * Fix obsolete message on .Parent * Obsolete .Children * Fix usages of Children for ApiMediaQueryService * Fix usage in internal * Fix usages in views * Fix indentation * Fix issue with delete language * Update nuget pacakges * Clear elements cache when content is deleted instead of trying to update it * Reset publishedModelFactory * Fixed publishing --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: kjac <kja@umbraco.dk>
2024-10-01 15:03:02 +02:00
private IPublishedContentFactory PublishedContentFactory => GetRequiredService<IPublishedContentFactory>();
[Test]
public void Can_Update_Member_Property_Values()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member =
MemberBuilder.CreateSimpleMember(memberType, "hello", "helloworld@test123.com", "hello", "hello");
member.SetValue("title", "title of mine");
member.SetValue("bodyText", "hello world");
MemberService.Save(member);
// re-get
member = MemberService.GetById(member.Id);
member.SetValue("title", "another title of mine"); // Change a value
member.SetValue("bodyText", null); // Clear a value
member.SetValue("author", "new author"); // Add a value
MemberService.Save(member);
// re-get
member = MemberService.GetById(member.Id);
Assert.AreEqual("another title of mine", member.GetValue("title"));
Assert.IsNull(member.GetValue("bodyText"));
Assert.AreEqual("new author", member.GetValue("author"));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Get_By_Username()
{
var memberType = MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true);
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
var member2 = MemberService.GetByUsername(member.Username);
2020-10-11 09:46:48 +02:00
Assert.IsNotNull(member2);
Assert.AreEqual(member.Email, member2.Email);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Set_Last_Login_Date()
{
var now = DateTime.Now;
var memberType = MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true)
2020-10-11 09:46:48 +02:00
{
LastLoginDate = now,
UpdateDate = now
};
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
var newDate = now.AddDays(10);
member.LastLoginDate = newDate;
member.UpdateDate = newDate;
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
// re-get
member = MemberService.GetById(member.Id);
2020-10-11 09:46:48 +02:00
Assert.That(member.LastLoginDate, Is.EqualTo(newDate).Within(1).Seconds);
Assert.That(member.UpdateDate, Is.EqualTo(newDate).Within(1).Seconds);
}
2020-10-11 09:46:48 +02:00
// These might seem like some somewhat pointless tests, but there's some funky things going on in MemberRepository when saving.
[Test]
public void Can_Set_Failed_Password_Attempts()
{
var memberType = MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true)
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
{
FailedPasswordAttempts = 1
};
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
member.FailedPasswordAttempts = 2;
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
member = MemberService.GetById(member.Id);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
Assert.AreEqual(2, member.FailedPasswordAttempts);
}
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
[Test]
public void Can_Set_Is_Approved()
{
var memberType = MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true);
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
member.IsApproved = false;
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
member = MemberService.GetById(member.Id);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
Assert.IsFalse(member.IsApproved);
}
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
[Test]
public void Can_Set_Is_Locked_Out()
{
var memberType = MemberTypeService.Get("member");
IMember member =
new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true) { IsLockedOut = false };
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
member.IsLockedOut = true;
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
member = MemberService.GetById(member.Id);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
Assert.IsTrue(member.IsLockedOut);
}
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
[Test]
public void Can_Set_Last_Lockout_Date()
{
var now = DateTime.Now;
var memberType = MemberTypeService.Get("member");
IMember member =
new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true) { LastLockoutDate = now };
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
var newDate = now.AddDays(10);
member.LastLockoutDate = newDate;
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
// re-get
member = MemberService.GetById(member.Id);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
Assert.That(member.LastLockoutDate, Is.EqualTo(newDate).Within(1).Seconds);
}
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
[Test]
public void Can_set_Last_Login_Date()
{
var now = DateTime.Now;
var memberType = MemberTypeService.Get("member");
IMember member =
new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true) { LastLoginDate = now };
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
var newDate = now.AddDays(10);
member.LastLoginDate = newDate;
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
// re-get
member = MemberService.GetById(member.Id);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
Assert.That(member.LastLoginDate, Is.EqualTo(newDate).Within(1).Seconds);
}
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
[Test]
public void Can_Set_Last_Password_Change_Date()
{
var now = DateTime.Now;
var memberType = MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true)
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
{
LastPasswordChangeDate = now
};
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
var newDate = now.AddDays(10);
member.LastPasswordChangeDate = newDate;
MemberService.Save(member);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
// re-get
member = MemberService.GetById(member.Id);
V10: Migrate member properties to columns on the member table (#12205) * Add new columns to the member table * Add missing IsApproved column * Add joins with nested query * Add query for selecting new column values from existing members * Update the member data from the same query * Make escapes work for sqlite * Use GetFieldNameForUpdate instead of GetFieldName * Left join on memberDto * Remove the now unused property types and data * Don't create member columns as properties anymore * Store old properties in fields on member Also switch the dates to nullable since they can be null * Map columns when mapping from DTO to Member object * Display columns in the member content app * Fix null exception when creating new user * Hide value if user doesn't have access to sensitive data * Remove hardcoded member properties * Obsolete old member alias constants * Map and persist member properties * Correctly update LastLogin when member logs in * Map IsApproved and IsLockedOut when saving member in backoffice * Update the query mappers for members * Fix member service tracks dirty changes test * Remove no longer existing property types from member type builder * Fix null error in UpdateMemberProperties * Fix builder tests * Fix SetupMemberTestData in MemberControllerUnitTests * Let LastLoginDate be null and handle check in controller There's no reason to default a perfectly nullable property to default(DateTime) * Add translation key for is approved and use that instead of constant * Obsolete old label constants * Fix whitespace post merge * Fix up test comments * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Fix member properties always being sensitive Co-authored-by: Elitsa Marinovska <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
2022-04-21 14:47:27 +02:00
Assert.That(member.LastPasswordChangeDate, Is.EqualTo(newDate).Within(1).Seconds);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Create_Member_With_Properties()
{
var memberType = MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true);
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
member = MemberService.GetById(member.Id);
Assert.AreEqual("xemail", member.Email);
2020-10-11 09:46:48 +02:00
V15: Remove Nucache (#17166) * Remove nucache reference from Web.Common * Get tests building-ish * Move ReservedFieldNamesService to the right project * Remove IPublishedSnapshotStatus * Added functionality to the INavigationQueryService to get root keys * Fixed issue with navigation * Remove IPublishedSnapshot from UmbracoContext * Begin removing usage of IPublishedSnapshot from PublishedContentExtensions * Fix PublishedContentExtensions.cs * Don't use snapshots in delivery media api * Use IPublishedMediaCache in QueryMediaApiController * Remove more usages of IPublishedSnapshotAccessor * Comment out tests * Remove more usages of PublishedSnapshotAccessor * Remove PublishedSnapshot from property * Fixed test build * Fix errors * Fix some tests * Delete NuCache 🎉 * Implement DatabaseCacheRebuilder * Remove usage of IPublishedSnapshotService * Remove IPublishedSnapshotService * Remove TestPublishedSnapshotAccessor and make tests build * Don't test Snapshot cachelevel It's no longer supported * Fix BlockEditorConverter Element != Element document type * Remember to set cachemanager * Fix RichTextParserTests * Implement TryGetLevel on INavigationQueryService * Fake level and obsolete it in PublishedContent * Remove ChildrenForAllCultures * Hack Path property on PublishedContent * Remove usages of IPublishedSnapshot in tests * More ConvertersTests * Add hybrid cache to integration tests We can actually do this now because we no longer save files on disk * Rename IPublishedSnapshotRebuilder to ICacheRebuilder * Comment out tests * V15: Replacing the usages of Parent (navigation data) from IPublishedContent (#17125) * Fix .Parent references in PublishedContentExtensions * Add missing methods to FriendlyPublishedContentExtensions (ones that you were able to call on the content directly as they now require extra params) * Fix references from the extension methods * Fix dependencies in tests * Replace IPublishedSnapshotAccessor with the content cache in tests * Resolving more .Parent references * Fix unit tests * Obsolete and use extension methods * Remove private method and use extension instead * Moving code around * Fix tests * Fix more references * Cleanup * Fix more usages * Resolve merge conflict * Fix tests * Cleanup * Fix more tests * Fixed unit tests * Cleanup * Replace last usages --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Remove usage of IPublishedSnapshotAccessor from IRequestItemProvider * Post merge fixup * Remo IPublishedSnapshot * Add HasAny to IDocumentUrlService * Fix TextBuilder * Fix modelsbuilder tests * Use explicit types * Implement GetByContentType * Support element types in PublishedContentTypeCache * Run enlistments before publishing notifications * Fix elements cache refreshing * Implement GetByUdi * Implement GetAtRoot * Implement GetByRoute * Reimplement GetRouteById * Fix blocks unit tests * Initialize domain cache on boot * Only return routes with domains on non default lanauges * V15: Replacing the usages of `Children` (navigation data) from `IPublishedContent` (#17159) * Update params in PublishedContentExtensions to the general interfaces for the published cache and navigation service, so that we can use the extension methods on both documents and media * Introduce GetParent() which uses the right services * Fix obsolete message on .Parent * Obsolete .Children * Fix usages of Children for ApiMediaQueryService * Fix usage in internal * Fix usages in views * Fix indentation * Fix issue with delete language * Update nuget pacakges * Clear elements cache when content is deleted instead of trying to update it * Reset publishedModelFactory * Fixed publishing --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Co-authored-by: kjac <kja@umbraco.dk>
2024-10-01 15:03:02 +02:00
var pmember = PublishedContentFactory.ToPublishedMember(member);
2020-10-11 09:46:48 +02:00
// contains the umbracoMember... properties created when installing, on the member type
// contains the other properties, that PublishedContentType adds (BuiltinMemberProperties)
string[] aliases =
2020-10-11 09:46:48 +02:00
{
Constants.Conventions.Member.Comments, nameof(IMember.Email), nameof(IMember.Username),
nameof(IMember.Comments), nameof(IMember.IsApproved), nameof(IMember.IsLockedOut),
nameof(IMember.LastLockoutDate), nameof(IMember.CreateDate), nameof(IMember.LastLoginDate),
nameof(IMember.LastPasswordChangeDate)
};
2020-10-11 09:46:48 +02:00
var properties = pmember.Properties.ToList();
2020-10-11 09:46:48 +02:00
Assert.IsTrue(properties.Select(x => x.Alias).ContainsAll(aliases));
2020-10-11 09:46:48 +02:00
var email = properties[aliases.IndexOf(nameof(IMember.Email))];
Assert.AreEqual("xemail", email.GetSourceValue());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Create_Member()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
Assert.AreNotEqual(0, member.Id);
var foundMember = MemberService.GetById(member.Id);
Assert.IsNotNull(foundMember);
Assert.AreEqual("test@test.com", foundMember.Email);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Create_Member_With_Long_TLD_In_Email()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.marketing", "pass", "test");
MemberService.Save(member);
Assert.AreNotEqual(0, member.Id);
var foundMember = MemberService.GetById(member.Id);
Assert.IsNotNull(foundMember);
Assert.AreEqual("test@test.marketing", foundMember.Email);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Create_Role()
{
MemberService.AddRole("MyTestRole");
2020-10-11 09:46:48 +02:00
var found = MemberService.GetAllRoles();
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
Assert.AreEqual("MyTestRole", found.Single().Name);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Create_Duplicate_Role()
{
MemberService.AddRole("MyTestRole");
MemberService.AddRole("MyTestRole");
2020-10-11 09:46:48 +02:00
var found = MemberService.GetAllRoles();
Assert.AreEqual(1, found.Count());
Assert.AreEqual("MyTestRole", found.Single().Name);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Get_All_Roles()
{
MemberService.AddRole("MyTestRole1");
MemberService.AddRole("MyTestRole2");
MemberService.AddRole("MyTestRole3");
2020-10-11 09:46:48 +02:00
var found = MemberService.GetAllRoles();
Assert.AreEqual(3, found.Count());
}
Security stamp implementation for members (#10140) * Getting new netcore PublicAccessChecker in place * Adds full test coverage for PublicAccessChecker * remove PublicAccessComposer * adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller * Implements the required methods on IMemberManager, removes old migrated code * Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops * adds note * adds note * Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling. * Changes name to IUmbracoEndpointBuilder * adds note * Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect * fixing build * Updates user manager to correctly validate password hashing and injects the IBackOfficeUserPasswordChecker * Merges PR * Fixes up build and notes * Implements security stamp and email confirmed for members, cleans up a bunch of repo/service level member groups stuff, shares user store code between members and users and fixes the user identity object so we arent' tracking both groups and roles. * Security stamp for members is now working * Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware. * adds note * removes unused filter, fixes build * fixes WebPath and tests * Looks up entities in one query * remove usings * Fix test, remove stylesheet * Set status code before we write to response to avoid error * Ensures that users and members are validated when logging in. Shares more code between users and members. * merge changes * oops * Fixes RepositoryCacheKeys to ensure the keys are normalized * oops didn't mean to commit this * Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy * oops didn't mean to comit this * bah, far out this keeps getting recommitted. sorry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 17:13:40 +10:00
[Test]
public void Can_Get_All_Roles_IDs()
{
MemberService.AddRole("MyTestRole1");
MemberService.AddRole("MyTestRole2");
MemberService.AddRole("MyTestRole3");
2020-10-11 09:46:48 +02:00
var found = MemberService.GetAllRolesIds();
2020-10-11 09:46:48 +02:00
Assert.AreEqual(3, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Replace_Roles()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
string[] roleNames1 = { "TR1", "TR2" };
MemberService.AssignRoles(new[] { member.Id }, roleNames1);
var memberRoles = MemberService.GetAllRoles(member.Id);
CollectionAssert.AreEquivalent(roleNames1, memberRoles);
string[] roleNames2 = { "TR3", "TR4" };
MemberService.ReplaceRoles(new[] { member.Id }, roleNames2);
memberRoles = MemberService.GetAllRoles(member.Id);
CollectionAssert.AreEquivalent(roleNames2, memberRoles);
}
[Test]
public void Can_Get_All_Roles_By_Member_Id()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
MemberService.AddRole("MyTestRole1");
MemberService.AddRole("MyTestRole2");
MemberService.AddRole("MyTestRole3");
MemberService.AssignRoles(new[] { member.Id }, new[] { "MyTestRole1", "MyTestRole2" });
2020-10-11 09:46:48 +02:00
var memberRoles = MemberService.GetAllRoles(member.Id);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, memberRoles.Count());
}
[Test]
public void Can_Get_All_Roles_Ids_By_Member_Id()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
MemberService.AddRole("MyTestRole1");
MemberService.AddRole("MyTestRole2");
MemberService.AddRole("MyTestRole3");
MemberService.AssignRoles(new[] { member.Id }, new[] { "MyTestRole1", "MyTestRole2" });
2020-10-11 09:46:48 +02:00
var memberRoles = MemberService.GetAllRolesIds(member.Id);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, memberRoles.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Get_All_Roles_By_Member_Username()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
// need to test with '@' symbol in the lookup
IMember member2 =
MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2@test.com");
MemberService.Save(member2);
MemberService.AddRole("MyTestRole1");
MemberService.AddRole("MyTestRole2");
MemberService.AddRole("MyTestRole3");
MemberService.AssignRoles(new[] { member.Id, member2.Id }, new[] { "MyTestRole1", "MyTestRole2" });
var memberRoles = MemberService.GetAllRoles("test");
Assert.AreEqual(2, memberRoles.Count());
var memberRoles2 = MemberService.GetAllRoles("test2@test.com");
Assert.AreEqual(2, memberRoles2.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Delete_Role()
{
MemberService.AddRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
MemberService.DeleteRole("MyTestRole1", false);
2020-10-11 09:46:48 +02:00
var memberRoles = MemberService.GetAllRoles();
2020-10-11 09:46:48 +02:00
Assert.AreEqual(0, memberRoles.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Throws_When_Deleting_Assigned_Role()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
MemberService.AddRole("MyTestRole1");
MemberService.AssignRoles(new[] { member.Id }, new[] { "MyTestRole1", "MyTestRole2" });
2020-10-11 09:46:48 +02:00
Assert.Throws<InvalidOperationException>(() => MemberService.DeleteRole("MyTestRole1", true));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Get_Members_In_Role()
{
MemberService.AddRole("MyTestRole1");
int roleId;
using (var scope = ScopeProvider.CreateScope())
{
roleId = ScopeAccessor.AmbientScope.Database.ExecuteScalar<int>(
"SELECT id from umbracoNode where [text] = 'MyTestRole1'");
scope.Complete();
2020-10-11 09:46:48 +02:00
}
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
using (var scope = ScopeProvider.CreateScope())
2020-10-11 09:46:48 +02:00
{
ScopeAccessor.AmbientScope.Database.Insert(new Member2MemberGroupDto
2020-10-11 09:46:48 +02:00
{
MemberGroup = roleId,
Member = member1.Id
});
ScopeAccessor.AmbientScope.Database.Insert(new Member2MemberGroupDto
2020-10-11 09:46:48 +02:00
{
MemberGroup = roleId,
Member = member2.Id
});
scope.Complete();
2020-10-11 09:46:48 +02:00
}
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
Assert.AreEqual(2, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Cannot_Save_Member_With_Empty_Name()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, string.Empty, "test@test.com", "pass", "test");
2020-10-11 09:46:48 +02:00
// Act & Assert
Assert.Throws<ArgumentException>(() => MemberService.Save(member));
}
2020-10-11 09:46:48 +02:00
[TestCase("MyTestRole1", "test1", StringPropertyMatchType.StartsWith, 1)]
[TestCase("MyTestRole1", "test", StringPropertyMatchType.StartsWith, 3)]
[TestCase("MyTestRole1", "test1", StringPropertyMatchType.Exact, 1)]
[TestCase("MyTestRole1", "test", StringPropertyMatchType.Exact, 0)]
[TestCase("MyTestRole1", "st2", StringPropertyMatchType.EndsWith, 1)]
[TestCase("MyTestRole1", "test%", StringPropertyMatchType.Wildcard, 3)]
public void Find_Members_In_Role(string roleName1, string usernameToMatch, StringPropertyMatchType matchType,
int resultCount)
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
var member3 = MemberBuilder.CreateSimpleMember(memberType, "test3", "test3@test.com", "pass", "test3");
MemberService.Save(member3);
MemberService.AssignRoles(new[] { member1.Id, member2.Id, member3.Id }, new[] { roleName1 });
var result = MemberService.FindMembersInRole(roleName1, usernameToMatch, matchType);
Assert.AreEqual(resultCount, result.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Associate_Members_To_Roles_With_Member_Id()
{
MemberService.AddRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
2020-10-11 09:46:48 +02:00
// temp make sure they exist
Assert.IsNotNull(MemberService.GetById(member1.Id));
Assert.IsNotNull(MemberService.GetById(member2.Id));
2020-10-11 09:46:48 +02:00
MemberService.AssignRoles(new[] { member1.Id, member2.Id }, new[] { "MyTestRole1" });
2020-10-11 09:46:48 +02:00
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Associate_Members_To_Roles_With_Member_Id_Casing()
{
MemberService.AddRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
2020-10-11 09:46:48 +02:00
// temp make sure they exist
Assert.IsNotNull(MemberService.GetById(member1.Id));
Assert.IsNotNull(MemberService.GetById(member2.Id));
2020-10-11 09:46:48 +02:00
MemberService.AssignRoles(new[] { member1.Id, member2.Id }, new[] { "mytestrole1" });
2020-10-11 09:46:48 +02:00
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Associate_Members_To_Roles_With_Member_Username()
{
MemberService.AddRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
2020-10-11 09:46:48 +02:00
MemberService.AssignRoles(new[] { member1.Username, member2.Username }, new[] { "MyTestRole1" });
2020-10-11 09:46:48 +02:00
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Associate_Members_To_Roles_With_Member_Username_Containing_At_Symbols()
{
MemberService.AddRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1@test.com");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2@test.com");
MemberService.Save(member2);
2020-10-11 09:46:48 +02:00
MemberService.AssignRoles(new[] { member1.Username, member2.Username }, new[] { "MyTestRole1" });
2020-10-11 09:46:48 +02:00
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Associate_Members_To_Roles_With_New_Role()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
2020-10-11 09:46:48 +02:00
// implicitly create the role
MemberService.AssignRoles(new[] { member1.Username, member2.Username }, new[] { "MyTestRole1" });
2020-10-11 09:46:48 +02:00
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Remove_Members_From_Roles_With_Member_Id()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
MemberService.AssignRoles(new[] { member1.Id, member2.Id }, new[] { "MyTestRole1", "MyTestRole2" });
MemberService.DissociateRoles(new[] { member1.Id }, new[] { "MyTestRole1" });
MemberService.DissociateRoles(new[] { member1.Id, member2.Id }, new[] { "MyTestRole2" });
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
Assert.AreEqual(1, membersInRole.Count());
membersInRole = MemberService.GetMembersInRole("MyTestRole2");
Assert.AreEqual(0, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Remove_Members_From_Roles_With_Member_Username()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var member1 = MemberBuilder.CreateSimpleMember(memberType, "test1", "test1@test.com", "pass", "test1");
MemberService.Save(member1);
var member2 = MemberBuilder.CreateSimpleMember(memberType, "test2", "test2@test.com", "pass", "test2");
MemberService.Save(member2);
MemberService.AssignRoles(new[] { member1.Username, member2.Username }, new[] { "MyTestRole1", "MyTestRole2" });
MemberService.DissociateRoles(new[] { member1.Username }, new[] { "MyTestRole1" });
MemberService.DissociateRoles(new[] { member1.Username, member2.Username }, new[] { "MyTestRole2" });
var membersInRole = MemberService.GetMembersInRole("MyTestRole1");
Assert.AreEqual(1, membersInRole.Count());
membersInRole = MemberService.GetMembersInRole("MyTestRole2");
Assert.AreEqual(0, membersInRole.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Can_Delete_member()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
MemberService.Delete(member);
var deleted = MemberService.GetById(member.Id);
2020-10-11 09:46:48 +02:00
// Assert
Assert.That(deleted, Is.Null);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Exists_By_Username()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
IMember member2 =
MemberBuilder.CreateSimpleMember(memberType, "test", "test2@test.com", "pass", "test2@test.com");
MemberService.Save(member2);
Assert.IsTrue(MemberService.Exists("test"));
Assert.IsFalse(MemberService.Exists("notFound"));
Assert.IsTrue(MemberService.Exists("test2@test.com"));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Exists_By_Id()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
Assert.IsTrue(MemberService.Exists(member.Id));
Assert.IsFalse(MemberService.Exists(9876));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Tracks_Dirty_Changes()
{
// This test was initially deleted but that broke the build as it was marked as a breaking change
// https://github.com/umbraco/Umbraco-CMS/pull/14060
// Easiest fix for now is to leave the test and just don't do anything
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Email()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
Assert.IsNotNull(MemberService.GetByEmail(member.Email));
Assert.IsNull(MemberService.GetByEmail("do@not.find"));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_Member_Name()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member =
MemberBuilder.CreateSimpleMember(memberType, "Test Real Name", "test@test.com", "pass", "testUsername");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
Assert.AreEqual("Test Real Name", member.Name);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Username()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
Assert.IsNotNull(MemberService.GetByUsername(member.Username));
Assert.IsNull(MemberService.GetByUsername("notFound"));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Object_Id()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
IMember member = MemberBuilder.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
MemberService.Save(member);
2020-10-11 09:46:48 +02:00
Assert.IsNotNull(MemberService.GetById(member.Id));
Assert.IsNull(MemberService.GetById(9876));
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_All_Paged_Members()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetAll(0, 2, out var totalRecs);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, found.Count());
Assert.AreEqual(10, totalRecs);
Assert.AreEqual("test0", found.First().Username);
Assert.AreEqual("test1", found.Last().Username);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_All_Paged_Members_With_Filter()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, true, null,
"Member No-");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(2, found.Count());
Assert.AreEqual(10, totalRecs);
Assert.AreEqual("test0", found.First().Username);
Assert.AreEqual("test1", found.Last().Username);
2020-10-11 09:46:48 +02:00
found = MemberService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, true, null, "Member No-5");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
Assert.AreEqual(1, totalRecs);
Assert.AreEqual("test5", found.First().Username);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Find_By_Name_Starts_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
var customMember = MemberBuilder.CreateSimpleMember(memberType, "Bob", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindMembersByDisplayName("B", 0, 100, out var totalRecs);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
}
[Test]
public void Find_By_Email_Starts_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// don't find this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByEmail("tes", 0, 100, out var totalRecs);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(10, found.Count());
}
[Test]
public void Find_By_Email_Ends_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// include this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByEmail("test.com", 0, 100, out var totalRecs, StringPropertyMatchType.EndsWith);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(11, found.Count());
}
[Test]
public void Find_By_Email_Contains()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// include this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByEmail("test", 0, 100, out var totalRecs, StringPropertyMatchType.Contains);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(11, found.Count());
}
[Test]
public void Find_By_Email_Exact()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// include this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByEmail("hello@test.com", 0, 100, out var totalRecs,
StringPropertyMatchType.Exact);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
}
[Test]
public void Find_By_Login_Starts_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// don't find this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByUsername("tes", 0, 100, out var totalRecs);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(10, found.Count());
}
[Test]
public void Find_By_Login_Ends_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// include this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByUsername("llo", 0, 100, out var totalRecs, StringPropertyMatchType.EndsWith);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
}
[Test]
public void Find_By_Login_Contains()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// include this
var customMember =
MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hellotest");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByUsername("test", 0, 100, out var totalRecs, StringPropertyMatchType.Contains);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(11, found.Count());
}
[Test]
public void Find_By_Login_Exact()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
// include this
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.FindByUsername("hello", 0, 100, out var totalRecs, StringPropertyMatchType.Exact);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_String_Value_Exact()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetMembersByPropertyValue(
"title", "hello member");
2020-10-11 09:46:48 +02:00
Assert.AreEqual(1, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_String_Value_Contains()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetMembersByPropertyValue(
"title", " member", StringPropertyMatchType.Contains);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(11, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_String_Value_Starts_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetMembersByPropertyValue(
"title", "Member No", StringPropertyMatchType.StartsWith);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(10, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_String_Value_Ends_With()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("title", "title of mine");
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"title", "mine", StringPropertyMatchType.EndsWith);
Assert.AreEqual(1, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Int_Value_Exact()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"number")
{
Name = "Number",
DataTypeId =
-51 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.SetValue("number", i));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("number", 2);
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"number", 2);
Assert.AreEqual(2, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Int_Value_Greater_Than()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"number")
{
Name = "Number",
DataTypeId =
-51 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.SetValue("number", i));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("number", 10);
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"number", 3, ValuePropertyMatchType.GreaterThan);
Assert.AreEqual(7, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Int_Value_Greater_Than_Equal_To()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"number")
{
Name = "Number",
DataTypeId =
-51 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.SetValue("number", i));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("number", 10);
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"number", 3, ValuePropertyMatchType.GreaterThanOrEqualTo);
Assert.AreEqual(8, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Int_Value_Less_Than()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.DateTime,
ValueStorageType.Date,
"number")
{
Name = "Number",
DataTypeId =
-51 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.SetValue("number", i));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("number", 1);
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"number", 5, ValuePropertyMatchType.LessThan);
Assert.AreEqual(6, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Int_Value_Less_Than_Or_Equal()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"number")
{
Name = "Number",
DataTypeId =
-51 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.SetValue("number", i));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("number", 1);
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"number", 5, ValuePropertyMatchType.LessThanOrEqualTo);
Assert.AreEqual(7, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Date_Value_Exact()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"date")
{
Name = "Date",
DataTypeId =
-36 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10,
(i, member) => member.SetValue("date", new DateTime(2013, 12, 20, 1, i, 0)));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("date", new DateTime(2013, 12, 20, 1, 2, 0));
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"date", new DateTime(2013, 12, 20, 1, 2, 0));
Assert.AreEqual(2, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Date_Value_Greater_Than()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"date")
{
Name = "Date",
DataTypeId =
-36 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10,
(i, member) => member.SetValue("date", new DateTime(2013, 12, 20, 1, i, 0)));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("date", new DateTime(2013, 12, 20, 1, 10, 0));
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"date", new DateTime(2013, 12, 20, 1, 3, 0), ValuePropertyMatchType.GreaterThan);
Assert.AreEqual(7, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Date_Value_Greater_Than_Equal_To()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"date")
{
Name = "Date",
DataTypeId =
-36 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10,
(i, member) => member.SetValue("date", new DateTime(2013, 12, 20, 1, i, 0)));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("date", new DateTime(2013, 12, 20, 1, 10, 0));
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"date", new DateTime(2013, 12, 20, 1, 3, 0), ValuePropertyMatchType.GreaterThanOrEqualTo);
Assert.AreEqual(8, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Date_Value_Less_Than()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"date")
{
Name = "Date",
DataTypeId =
-36 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10,
(i, member) => member.SetValue("date", new DateTime(2013, 12, 20, 1, i, 0)));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("date", new DateTime(2013, 12, 20, 1, 1, 0));
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"date", new DateTime(2013, 12, 20, 1, 5, 0), ValuePropertyMatchType.LessThan);
Assert.AreEqual(6, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Get_By_Property_Date_Value_Less_Than_Or_Equal()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
memberType.AddPropertyType(
new PropertyType(
ShortStringHelper,
Constants.PropertyEditors.Aliases.Integer,
ValueStorageType.Integer,
"date")
{
Name = "Date",
DataTypeId =
-36 // NOTE: This is what really determines the db type - the above definition doesn't really do anything
}, "content", "Content");
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10,
(i, member) => member.SetValue("date", new DateTime(2013, 12, 20, 1, i, 0)));
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.SetValue("date", new DateTime(2013, 12, 20, 1, 1, 0));
MemberService.Save(customMember);
var found = MemberService.GetMembersByPropertyValue(
"date", new DateTime(2013, 12, 20, 1, 5, 0), ValuePropertyMatchType.LessThanOrEqualTo);
Assert.AreEqual(7, found.Count());
}
2020-10-11 09:46:48 +02:00
[Test]
public void Count_All_Members()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10);
MemberService.Save(members);
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetCount(MemberCountType.All);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(11, found);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Count_All_Locked_Members()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.IsLockedOut = i % 2 == 0);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.IsLockedOut = true;
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetCount(MemberCountType.LockedOut);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(6, found);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Count_All_Approved_Members()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var members =
MemberBuilder.CreateMultipleSimpleMembers(memberType, 10, (i, member) => member.IsApproved = i % 2 == 0);
MemberService.Save(members);
2020-10-11 09:46:48 +02:00
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
customMember.IsApproved = false;
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetCount(MemberCountType.Approved);
2020-10-11 09:46:48 +02:00
Assert.AreEqual(5, found);
}
2020-10-11 09:46:48 +02:00
[Test]
public void Setting_Property_On_Built_In_Member_Property_When_Property_Doesnt_Exist_On_Type_Is_Ok()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
memberType.RemovePropertyType(Constants.Conventions.Member.Comments);
MemberTypeService.Save(memberType);
Assert.IsFalse(memberType.PropertyTypes.Any(x => x.Alias == Constants.Conventions.Member.Comments));
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
2020-10-11 09:46:48 +02:00
// this should not throw an exception
customMember.Comments = "hello world";
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetById(customMember.Id);
2020-10-11 09:46:48 +02:00
Assert.IsTrue(found.Comments.IsNullOrWhiteSpace());
}
2020-10-11 09:46:48 +02:00
[Test]
public void New_Member_Approved_By_Default()
{
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
2020-10-11 09:46:48 +02:00
var customMember = MemberBuilder.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
MemberService.Save(customMember);
2020-10-11 09:46:48 +02:00
var found = MemberService.GetById(customMember.Id);
Assert.IsTrue(found.IsApproved);
}
[Test]
public void Can_CreateWithIdentity()
{
// Arrange
IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();
MemberTypeService.Save(memberType);
var username = Path.GetRandomFileName();
// Act
var member = MemberService.CreateMemberWithIdentity(username, $"{username}@domain.email",
Path.GetFileNameWithoutExtension(username), memberType);
var found = MemberService.GetById(member.Id);
// Assert
Assert.IsNotNull(member, "Verifying a member instance has been created");
Assert.IsNotNull(found, "Verifying the created member instance has been retrieved");
Assert.IsTrue(found?.Name == member?.Name, "Verifying the retrieved member instance has the expected name");
2020-10-11 09:46:48 +02:00
}
}