2020-12-23 11:35:49 +01:00
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic ;
2020-06-29 10:44:46 +02:00
using Microsoft.Extensions.DependencyInjection ;
2017-09-14 19:29:12 +02:00
using Newtonsoft.Json ;
using NUnit.Framework ;
2021-02-18 11:06:02 +01:00
using Umbraco.Cms.Core.Mapping ;
using Umbraco.Cms.Core.Models.ContentEditing ;
using Umbraco.Cms.Core.Models.Membership ;
using Umbraco.Cms.Tests.Common.Testing ;
using Umbraco.Cms.Tests.Integration.Testing ;
2017-09-14 19:29:12 +02:00
2022-06-21 08:09:38 +02:00
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Mapping ;
[TestFixture]
[UmbracoTest(Mapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class UserModelMapperTests : UmbracoIntegrationTest
2017-09-14 19:29:12 +02:00
{
2022-06-21 08:09:38 +02:00
[SetUp]
public void Setup ( ) = > _sut = Services . GetRequiredService < IUmbracoMapper > ( ) ;
private IUmbracoMapper _sut ;
[Test]
public void Map_UserGroupSave_To_IUserGroup ( )
2017-09-14 19:29:12 +02:00
{
2022-06-21 08:09:38 +02:00
IUserGroup userGroup =
new UserGroup ( ShortStringHelper , 0 , "alias" , "name" , new List < string > { "c" } , "icon" ) { Id = 42 } ;
// userGroup.permissions is List`1[System.String]
// userGroup.permissions is System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Char, System.String]
// fixed: now List`1[System.String]
const string json =
"{\"id\":@@@ID@@@,\"alias\":\"perm1\",\"name\":\"Perm1\",\"icon\":\"icon-users\",\"sections\":[\"content\"],\"users\":[],\"defaultPermissions\":[\"F\",\"C\",\"A\"],\"assignedPermissions\":{},\"startContentId\":-1,\"startMediaId\":-1,\"action\":\"save\",\"parentId\":-1}" ;
var userGroupSave =
JsonConvert . DeserializeObject < UserGroupSave > ( json . Replace ( "@@@ID@@@" , userGroup . Id . ToString ( ) ) ) ;
// failed, AutoMapper complained, "Unable to cast object of type 'WhereSelectArrayIterator`2[System.Char,System.String]' to type 'System.Collections.IList'".
// FIXME: added ToList() in UserGroupFactory
_sut . Map ( userGroupSave , userGroup ) ;
2017-09-14 19:29:12 +02:00
}
}