More code and tests written for deep cloning.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
namespace Umbraco.Core.Models.EntityBase
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IDeepCloneable
|
||||
{
|
||||
@@ -194,7 +194,7 @@
|
||||
<Compile Include="Models\ContentTypeCompositionBase.cs" />
|
||||
<Compile Include="Models\ContentTypeExtensions.cs" />
|
||||
<Compile Include="Models\ContentTypeSort.cs" />
|
||||
<Compile Include="Models\EntityBase\IDeepCloneable.cs" />
|
||||
<Compile Include="Models\IDeepCloneable.cs" />
|
||||
<Compile Include="Models\EntityExtensions.cs" />
|
||||
<Compile Include="Models\Folder.cs" />
|
||||
<Compile Include="Models\IMemberGroup.cs" />
|
||||
|
||||
@@ -1,92 +1,9 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserTypeTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new UserType()
|
||||
{
|
||||
Id = 3,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
CreateDate = DateTime.Now,
|
||||
Name = "Test",
|
||||
Alias = "test",
|
||||
Permissions = new[] {"a", "b", "c"}
|
||||
};
|
||||
|
||||
var clone = (User)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
|
||||
//Verify normal properties with reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class UserTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new User(new UserType(){Id = 3})
|
||||
{
|
||||
Id = 3,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
CreateDate = DateTime.Now,
|
||||
Name = "Test",
|
||||
Comments = "comments",
|
||||
DefaultPermissions = new[]{"a","b","c"},
|
||||
DefaultToLiveEditing = false,
|
||||
Email = "test@test.com",
|
||||
Language = "en",
|
||||
FailedPasswordAttempts = 3,
|
||||
IsApproved = true,
|
||||
IsLockedOut = true,
|
||||
LastLockoutDate = DateTime.Now,
|
||||
LastLoginDate = DateTime.Now,
|
||||
LastPasswordChangeDate = DateTime.Now,
|
||||
Password = "test pass",
|
||||
PasswordAnswer = "answer",
|
||||
PasswordQuestion = "question",
|
||||
//ProviderUserKey = "user key",
|
||||
SessionTimeout = 5,
|
||||
StartContentId = 3,
|
||||
StartMediaId = 8,
|
||||
Username = "username"
|
||||
};
|
||||
|
||||
var clone = (User)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
|
||||
Assert.AreNotSame(clone.UserType, item.UserType);
|
||||
Assert.AreEqual(clone.UserType, item.UserType);
|
||||
|
||||
//Verify normal properties with reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class UmbracoEntityTests
|
||||
{
|
||||
|
||||
57
src/Umbraco.Tests/Models/UserTests.cs
Normal file
57
src/Umbraco.Tests/Models/UserTests.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new User(new UserType(){Id = 3})
|
||||
{
|
||||
Id = 3,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
CreateDate = DateTime.Now,
|
||||
Name = "Test",
|
||||
Comments = "comments",
|
||||
DefaultPermissions = new[]{"a","b","c"},
|
||||
DefaultToLiveEditing = false,
|
||||
Email = "test@test.com",
|
||||
Language = "en",
|
||||
FailedPasswordAttempts = 3,
|
||||
IsApproved = true,
|
||||
IsLockedOut = true,
|
||||
LastLockoutDate = DateTime.Now,
|
||||
LastLoginDate = DateTime.Now,
|
||||
LastPasswordChangeDate = DateTime.Now,
|
||||
Password = "test pass",
|
||||
PasswordAnswer = "answer",
|
||||
PasswordQuestion = "question",
|
||||
//ProviderUserKey = "user key",
|
||||
SessionTimeout = 5,
|
||||
StartContentId = 3,
|
||||
StartMediaId = 8,
|
||||
Username = "username"
|
||||
};
|
||||
|
||||
var clone = (User)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
|
||||
Assert.AreNotSame(clone.UserType, item.UserType);
|
||||
Assert.AreEqual(clone.UserType, item.UserType);
|
||||
|
||||
//Verify normal properties with reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Umbraco.Tests/Models/UserTypeTests.cs
Normal file
37
src/Umbraco.Tests/Models/UserTypeTests.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class UserTypeTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new UserType()
|
||||
{
|
||||
Id = 3,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
CreateDate = DateTime.Now,
|
||||
Name = "Test",
|
||||
Alias = "test",
|
||||
Permissions = new[] {"a", "b", "c"}
|
||||
};
|
||||
|
||||
var clone = (UserType)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
|
||||
//Verify normal properties with reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,6 +173,8 @@
|
||||
<Compile Include="Models\TaskTypeTests.cs" />
|
||||
<Compile Include="Models\TemplateTests.cs" />
|
||||
<Compile Include="Models\UmbracoEntityTests.cs" />
|
||||
<Compile Include="Models\UserTests.cs" />
|
||||
<Compile Include="Models\UserTypeTests.cs" />
|
||||
<Compile Include="Mvc\UmbracoViewPageTests.cs" />
|
||||
<Compile Include="Persistence\Auditing\AuditTests.cs" />
|
||||
<Compile Include="BootManagers\CoreBootManagerTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user