Skip to content

Commit bb22f5a

Browse files
committed
More code and tests written for deep cloning.
1 parent dcac5d4 commit bb22f5a

File tree

6 files changed

+98
-85
lines changed

6 files changed

+98
-85
lines changed

src/Umbraco.Core/Models/EntityBase/IDeepCloneable.cs renamed to src/Umbraco.Core/Models/IDeepCloneable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Umbraco.Core.Models.EntityBase
1+
namespace Umbraco.Core.Models
22
{
33
public interface IDeepCloneable
44
{

src/Umbraco.Core/Umbraco.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<Compile Include="Models\ContentTypeCompositionBase.cs" />
195195
<Compile Include="Models\ContentTypeExtensions.cs" />
196196
<Compile Include="Models\ContentTypeSort.cs" />
197-
<Compile Include="Models\EntityBase\IDeepCloneable.cs" />
197+
<Compile Include="Models\IDeepCloneable.cs" />
198198
<Compile Include="Models\EntityExtensions.cs" />
199199
<Compile Include="Models\Folder.cs" />
200200
<Compile Include="Models\IMemberGroup.cs" />

src/Umbraco.Tests/Models/UmbracoEntityTests.cs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,9 @@
11
using System;
22
using NUnit.Framework;
33
using Umbraco.Core.Models;
4-
using Umbraco.Core.Models.Membership;
54

65
namespace Umbraco.Tests.Models
76
{
8-
[TestFixture]
9-
public class UserTypeTests
10-
{
11-
[Test]
12-
public void Can_Deep_Clone()
13-
{
14-
var item = new UserType()
15-
{
16-
Id = 3,
17-
Key = Guid.NewGuid(),
18-
UpdateDate = DateTime.Now,
19-
CreateDate = DateTime.Now,
20-
Name = "Test",
21-
Alias = "test",
22-
Permissions = new[] {"a", "b", "c"}
23-
};
24-
25-
var clone = (User)item.DeepClone();
26-
27-
Assert.AreNotSame(clone, item);
28-
Assert.AreEqual(clone, item);
29-
30-
//Verify normal properties with reflection
31-
var allProps = clone.GetType().GetProperties();
32-
foreach (var propertyInfo in allProps)
33-
{
34-
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
35-
}
36-
}
37-
}
38-
39-
[TestFixture]
40-
public class UserTests
41-
{
42-
[Test]
43-
public void Can_Deep_Clone()
44-
{
45-
var item = new User(new UserType(){Id = 3})
46-
{
47-
Id = 3,
48-
Key = Guid.NewGuid(),
49-
UpdateDate = DateTime.Now,
50-
CreateDate = DateTime.Now,
51-
Name = "Test",
52-
Comments = "comments",
53-
DefaultPermissions = new[]{"a","b","c"},
54-
DefaultToLiveEditing = false,
55-
Email = "test@test.com",
56-
Language = "en",
57-
FailedPasswordAttempts = 3,
58-
IsApproved = true,
59-
IsLockedOut = true,
60-
LastLockoutDate = DateTime.Now,
61-
LastLoginDate = DateTime.Now,
62-
LastPasswordChangeDate = DateTime.Now,
63-
Password = "test pass",
64-
PasswordAnswer = "answer",
65-
PasswordQuestion = "question",
66-
//ProviderUserKey = "user key",
67-
SessionTimeout = 5,
68-
StartContentId = 3,
69-
StartMediaId = 8,
70-
Username = "username"
71-
};
72-
73-
var clone = (User)item.DeepClone();
74-
75-
Assert.AreNotSame(clone, item);
76-
Assert.AreEqual(clone, item);
77-
78-
Assert.AreNotSame(clone.UserType, item.UserType);
79-
Assert.AreEqual(clone.UserType, item.UserType);
80-
81-
//Verify normal properties with reflection
82-
var allProps = clone.GetType().GetProperties();
83-
foreach (var propertyInfo in allProps)
84-
{
85-
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
86-
}
87-
}
88-
}
89-
907
[TestFixture]
918
public class UmbracoEntityTests
929
{

src/Umbraco.Tests/Models/UserTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using NUnit.Framework;
3+
using Umbraco.Core.Models.Membership;
4+
5+
namespace Umbraco.Tests.Models
6+
{
7+
[TestFixture]
8+
public class UserTests
9+
{
10+
[Test]
11+
public void Can_Deep_Clone()
12+
{
13+
var item = new User(new UserType(){Id = 3})
14+
{
15+
Id = 3,
16+
Key = Guid.NewGuid(),
17+
UpdateDate = DateTime.Now,
18+
CreateDate = DateTime.Now,
19+
Name = "Test",
20+
Comments = "comments",
21+
DefaultPermissions = new[]{"a","b","c"},
22+
DefaultToLiveEditing = false,
23+
Email = "test@test.com",
24+
Language = "en",
25+
FailedPasswordAttempts = 3,
26+
IsApproved = true,
27+
IsLockedOut = true,
28+
LastLockoutDate = DateTime.Now,
29+
LastLoginDate = DateTime.Now,
30+
LastPasswordChangeDate = DateTime.Now,
31+
Password = "test pass",
32+
PasswordAnswer = "answer",
33+
PasswordQuestion = "question",
34+
//ProviderUserKey = "user key",
35+
SessionTimeout = 5,
36+
StartContentId = 3,
37+
StartMediaId = 8,
38+
Username = "username"
39+
};
40+
41+
var clone = (User)item.DeepClone();
42+
43+
Assert.AreNotSame(clone, item);
44+
Assert.AreEqual(clone, item);
45+
46+
Assert.AreNotSame(clone.UserType, item.UserType);
47+
Assert.AreEqual(clone.UserType, item.UserType);
48+
49+
//Verify normal properties with reflection
50+
var allProps = clone.GetType().GetProperties();
51+
foreach (var propertyInfo in allProps)
52+
{
53+
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
54+
}
55+
}
56+
}
57+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using NUnit.Framework;
3+
using Umbraco.Core.Models.Membership;
4+
5+
namespace Umbraco.Tests.Models
6+
{
7+
[TestFixture]
8+
public class UserTypeTests
9+
{
10+
[Test]
11+
public void Can_Deep_Clone()
12+
{
13+
var item = new UserType()
14+
{
15+
Id = 3,
16+
Key = Guid.NewGuid(),
17+
UpdateDate = DateTime.Now,
18+
CreateDate = DateTime.Now,
19+
Name = "Test",
20+
Alias = "test",
21+
Permissions = new[] {"a", "b", "c"}
22+
};
23+
24+
var clone = (UserType)item.DeepClone();
25+
26+
Assert.AreNotSame(clone, item);
27+
Assert.AreEqual(clone, item);
28+
29+
//Verify normal properties with reflection
30+
var allProps = clone.GetType().GetProperties();
31+
foreach (var propertyInfo in allProps)
32+
{
33+
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
34+
}
35+
}
36+
}
37+
}

src/Umbraco.Tests/Umbraco.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@
173173
<Compile Include="Models\TaskTypeTests.cs" />
174174
<Compile Include="Models\TemplateTests.cs" />
175175
<Compile Include="Models\UmbracoEntityTests.cs" />
176+
<Compile Include="Models\UserTests.cs" />
177+
<Compile Include="Models\UserTypeTests.cs" />
176178
<Compile Include="Mvc\UmbracoViewPageTests.cs" />
177179
<Compile Include="Persistence\Auditing\AuditTests.cs" />
178180
<Compile Include="BootManagers\CoreBootManagerTests.cs" />

0 commit comments

Comments
 (0)