Merge branch 'netcore/dev' into feature/netcore-model-unit-tests-2
# Conflicts: # src/Umbraco.Tests.Common/Builders/MemberTypeBuilder.cs
This commit is contained in:
@@ -31,8 +31,6 @@ namespace Umbraco.Core.Models
|
||||
_childObjectType = childObjectType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Name of the RelationType
|
||||
/// </summary>
|
||||
|
||||
@@ -76,6 +76,9 @@
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Umbraco.Tests.Integration</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>Umbraco.Tests.Common</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -33,6 +33,13 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithDeleteDate<T>(this T builder, DateTime deleteDate)
|
||||
where T : IWithDeleteDateBuilder
|
||||
{
|
||||
builder.DeleteDate = deleteDate;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithAlias<T>(this T builder, string alias)
|
||||
where T : IWithAliasBuilder
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class MemberTypeBuilder
|
||||
: ChildBuilderBase<MemberBuilder, MemberType>,
|
||||
: ChildBuilderBase<MemberBuilder, IMemberType>,
|
||||
IBuildPropertyGroups,
|
||||
IWithIdBuilder,
|
||||
IWithAliasBuilder,
|
||||
@@ -99,7 +99,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override MemberType Build()
|
||||
public override IMemberType Build()
|
||||
{
|
||||
var id = _id ?? 1;
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class RelationBuilder
|
||||
: BuilderBase<Relation>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder
|
||||
{
|
||||
private RelationTypeBuilder _relationTypeBuilder;
|
||||
|
||||
private int? _id;
|
||||
private int? _parentId;
|
||||
private int? _childId;
|
||||
private Guid? _key;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private string _comment;
|
||||
|
||||
public RelationBuilder WithComment(string comment)
|
||||
{
|
||||
_comment = comment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationBuilder BetweenIds(int parentId, int childId)
|
||||
{
|
||||
_parentId = parentId;
|
||||
_childId = childId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationTypeBuilder AddRelationType()
|
||||
{
|
||||
var builder = new RelationTypeBuilder(this);
|
||||
_relationTypeBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public override Relation Build()
|
||||
{
|
||||
var id = _id ?? 0;
|
||||
var parentId = _parentId ?? 0;
|
||||
var childId = _childId ?? 0;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var comment = _comment ?? string.Empty;
|
||||
|
||||
if (_relationTypeBuilder == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot construct a Relation without a RelationType. Use AddRelationType().");
|
||||
}
|
||||
|
||||
var relationType = _relationTypeBuilder.Build();
|
||||
|
||||
return new Relation(parentId, childId, relationType)
|
||||
{
|
||||
Comment = comment,
|
||||
CreateDate = createDate,
|
||||
Id = id,
|
||||
Key = key,
|
||||
UpdateDate = updateDate
|
||||
};
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,8 @@ using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class RelationTypeBuilder : RelationTypeBuilder<object>
|
||||
{
|
||||
public RelationTypeBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class RelationTypeBuilder<TParent>
|
||||
: ChildBuilderBase<TParent, IRelationType>,
|
||||
public class RelationTypeBuilder
|
||||
: ChildBuilderBase<RelationBuilder, IRelationType>,
|
||||
IWithIdBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
@@ -32,7 +25,11 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private Guid? _parentObjectType;
|
||||
private DateTime? _updateDate;
|
||||
|
||||
public RelationTypeBuilder(TParent parentBuilder) : base(parentBuilder)
|
||||
public RelationTypeBuilder() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public RelationTypeBuilder(RelationBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -91,8 +88,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var deleteDate = _deleteDate ?? null;
|
||||
|
||||
return new RelationType(name, alias, isBidirectional, parentObjectType,
|
||||
childObjectType)
|
||||
return new RelationType(name, alias, isBidirectional, parentObjectType, childObjectType)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
@@ -102,19 +98,19 @@ namespace Umbraco.Tests.Common.Builders
|
||||
};
|
||||
}
|
||||
|
||||
public RelationTypeBuilder<TParent> WithIsBidirectional(bool isBidirectional)
|
||||
public RelationTypeBuilder WithIsBidirectional(bool isBidirectional)
|
||||
{
|
||||
_isBidirectional = isBidirectional;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationTypeBuilder<TParent> WithChildObjectType(Guid childObjectType)
|
||||
public RelationTypeBuilder WithChildObjectType(Guid childObjectType)
|
||||
{
|
||||
_childObjectType = childObjectType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelationTypeBuilder<TParent> WithParentObjectType(Guid parentObjectType)
|
||||
public RelationTypeBuilder WithParentObjectType(Guid parentObjectType)
|
||||
{
|
||||
_parentObjectType = parentObjectType;
|
||||
return this;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class StylesheetBuilder
|
||||
: BuilderBase<Stylesheet>
|
||||
{
|
||||
private string _path;
|
||||
private string _content;
|
||||
|
||||
public StylesheetBuilder WithPath(string path)
|
||||
{
|
||||
_path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StylesheetBuilder WithContent(string content)
|
||||
{
|
||||
_content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Stylesheet Build()
|
||||
{
|
||||
var path = _path ?? string.Empty;
|
||||
var content = _content ?? string.Empty;
|
||||
|
||||
return new Stylesheet(path)
|
||||
{
|
||||
Content = content,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
public class TemplateBuilder
|
||||
: BuilderBase<Template>,
|
||||
IWithIdBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithAliasBuilder,
|
||||
IWithNameBuilder,
|
||||
IWithCreateDateBuilder,
|
||||
IWithUpdateDateBuilder,
|
||||
IWithPathBuilder
|
||||
{
|
||||
private int? _id;
|
||||
private Guid? _key;
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private DateTime? _createDate;
|
||||
private DateTime? _updateDate;
|
||||
private string _path;
|
||||
private string _content;
|
||||
private bool? _isMasterTemplate;
|
||||
private string _masterTemplateAlias;
|
||||
private Lazy<int> _masterTemplateId;
|
||||
|
||||
public TemplateBuilder WithContent(string content)
|
||||
{
|
||||
_content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemplateBuilder AsMasterTemplate(string masterTemplateAlias, int masterTemplateId)
|
||||
{
|
||||
_isMasterTemplate = true;
|
||||
_masterTemplateAlias = masterTemplateAlias;
|
||||
_masterTemplateId = new Lazy<int>(() => masterTemplateId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Template Build()
|
||||
{
|
||||
var id = _id ?? 0;
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var name = _name ?? Guid.NewGuid().ToString();
|
||||
var alias = _alias ?? name.ToCamelCase();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
var updateDate = _updateDate ?? DateTime.Now;
|
||||
var path = _path ?? string.Empty;
|
||||
var content = _content;
|
||||
var isMasterTemplate = _isMasterTemplate ?? false;
|
||||
var masterTemplateAlias = _masterTemplateAlias ?? string.Empty;
|
||||
var masterTemplateId = _masterTemplateId ?? null;
|
||||
|
||||
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
return new Template(shortStringHelper, name, alias)
|
||||
{
|
||||
Id = id,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
UpdateDate = updateDate,
|
||||
Path = path,
|
||||
Content = content,
|
||||
IsMasterTemplate = isMasterTemplate,
|
||||
MasterTemplateAlias = masterTemplateAlias,
|
||||
MasterTemplateId = masterTemplateId,
|
||||
};
|
||||
}
|
||||
|
||||
int? IWithIdBuilder.Id
|
||||
{
|
||||
get => _id;
|
||||
set => _id = value;
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
DateTime? IWithCreateDateBuilder.CreateDate
|
||||
{
|
||||
get => _createDate;
|
||||
set => _createDate = value;
|
||||
}
|
||||
|
||||
DateTime? IWithUpdateDateBuilder.UpdateDate
|
||||
{
|
||||
get => _updateDate;
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
string IWithPathBuilder.Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class RelationTests
|
||||
{
|
||||
private readonly RelationBuilder _builder = new RelationBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var relation = BuildRelation();
|
||||
|
||||
var clone = (Relation) relation.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, relation);
|
||||
Assert.AreEqual(clone, relation);
|
||||
Assert.AreEqual(clone.ChildId, relation.ChildId);
|
||||
Assert.AreEqual(clone.Comment, relation.Comment);
|
||||
Assert.AreEqual(clone.CreateDate, relation.CreateDate);
|
||||
Assert.AreEqual(clone.Id, relation.Id);
|
||||
Assert.AreEqual(clone.Key, relation.Key);
|
||||
Assert.AreEqual(clone.ParentId, relation.ParentId);
|
||||
Assert.AreNotSame(clone.RelationType, relation.RelationType);
|
||||
Assert.AreEqual(clone.RelationType, relation.RelationType);
|
||||
Assert.AreEqual(clone.RelationTypeId, relation.RelationTypeId);
|
||||
Assert.AreEqual(clone.UpdateDate, relation.UpdateDate);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(relation, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var relation = BuildRelation();
|
||||
|
||||
var json = JsonConvert.SerializeObject(relation);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private Relation BuildRelation()
|
||||
{
|
||||
return _builder
|
||||
.BetweenIds(9, 8)
|
||||
.WithId(4)
|
||||
.WithComment("test comment")
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.AddRelationType()
|
||||
.WithId(66)
|
||||
.WithAlias("test")
|
||||
.WithName("Test")
|
||||
.WithIsBidirectional(false)
|
||||
.WithParentObjectType(Guid.NewGuid())
|
||||
.WithChildObjectType(Guid.NewGuid())
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
Assert.AreEqual(clone.Id, item.Id);
|
||||
Assert.AreEqual(clone.Key, item.Key);
|
||||
Assert.AreEqual(clone.Name, item.Name);
|
||||
Assert.AreNotSame(clone.ParentObjectType, item.ParentObjectType);
|
||||
Assert.AreNotSame(clone.ChildObjectType, item.ChildObjectType);
|
||||
Assert.AreEqual(clone.CreateDate, item.CreateDate);
|
||||
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
|
||||
|
||||
//This double verifies by reflection
|
||||
|
||||
+42
-27
@@ -3,26 +3,24 @@ using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class StylesheetTests
|
||||
{
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
SettingsForTests.Reset();
|
||||
}
|
||||
private readonly StylesheetBuilder _builder = new StylesheetBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Create_Stylesheet()
|
||||
{
|
||||
// Arrange
|
||||
var stylesheet = new Stylesheet("/css/styles.css");
|
||||
stylesheet.Content = @"body { color:#000; } .bold {font-weight:bold;}";
|
||||
// Act
|
||||
var stylesheet = _builder
|
||||
.WithPath("/css/styles.css")
|
||||
.WithContent(@"body { color:#000; } .bold {font-weight:bold;}")
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.That(stylesheet.Name, Is.EqualTo("styles.css"));
|
||||
@@ -33,8 +31,12 @@ namespace Umbraco.Tests.Models
|
||||
public void Can_Add_Property()
|
||||
{
|
||||
// Arrange
|
||||
var stylesheet = new Stylesheet("/css/styles.css") {Content = @"body { color:#000; } .bold {font-weight:bold;}"};
|
||||
var stylesheet = _builder
|
||||
.WithPath("/css/styles.css")
|
||||
.WithContent(@"body { color:#000; } .bold {font-weight:bold;}")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-weight:bold; font-family:Arial;"));
|
||||
|
||||
// Assert
|
||||
@@ -48,13 +50,16 @@ namespace Umbraco.Tests.Models
|
||||
public void Can_Remove_Property()
|
||||
{
|
||||
// Arrange
|
||||
var stylesheet = new Stylesheet("/css/styles.css") { Content = @"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}" };
|
||||
|
||||
|
||||
var stylesheet = _builder
|
||||
.WithPath("/css/styles.css")
|
||||
.WithContent(@"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}")
|
||||
.Build();
|
||||
Assert.AreEqual(1, stylesheet.Properties.Count());
|
||||
|
||||
// Act
|
||||
stylesheet.RemoveProperty("Hello");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(0, stylesheet.Properties.Count());
|
||||
Assert.AreEqual(@"body { color:#000; } .bold {font-weight:bold;}", stylesheet.Content);
|
||||
}
|
||||
@@ -63,17 +68,20 @@ namespace Umbraco.Tests.Models
|
||||
public void Can_Update_Property()
|
||||
{
|
||||
// Arrange
|
||||
var stylesheet = new Stylesheet("/css/styles.css")
|
||||
{
|
||||
Content = @"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}"
|
||||
};
|
||||
var stylesheet = _builder
|
||||
.WithPath("/css/styles.css")
|
||||
.WithContent(@"body { color:#000; } /**umb_name:Hello*/p{font-size:2em;} .bold {font-weight:bold;}")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var prop = stylesheet.Properties.Single();
|
||||
prop.Alias = "li";
|
||||
prop.Value = "font-size:5em;";
|
||||
|
||||
//re-get
|
||||
// - re-get
|
||||
prop = stylesheet.Properties.Single();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("li", prop.Alias);
|
||||
Assert.AreEqual("font-size:5em;", prop.Value);
|
||||
Assert.AreEqual("body { color:#000; } /**umb_name:Hello*/\r\nli {\r\n\tfont-size:5em;\r\n} .bold {font-weight:bold;}", stylesheet.Content);
|
||||
@@ -83,12 +91,15 @@ namespace Umbraco.Tests.Models
|
||||
public void Can_Get_Properties_From_Css()
|
||||
{
|
||||
// Arrange
|
||||
var stylesheet = new Stylesheet("/css/styles.css");
|
||||
stylesheet.Content = @"body { color:#000; } .bold {font-weight:bold;} /**umb_name:Hello */ p { font-size: 1em; } /**umb_name:testing123*/ li:first-child {padding:0px;}";
|
||||
var stylesheet = _builder
|
||||
.WithPath("/css/styles.css")
|
||||
.WithContent(@"body { color:#000; } .bold {font-weight:bold;} /**umb_name:Hello */ p { font-size: 1em; } /**umb_name:testing123*/ li:first-child {padding:0px;}")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var properties = stylesheet.Properties;
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(2, properties.Count());
|
||||
Assert.AreEqual("Hello", properties.First().Name);
|
||||
Assert.AreEqual("font-size: 1em;", properties.First().Value);
|
||||
@@ -102,13 +113,17 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var stylesheet = new Stylesheet("/css/styles.css");
|
||||
stylesheet.Content = @"@media screen and (min-width: 600px) and (min-width: 900px) {
|
||||
.class {
|
||||
background: #666;
|
||||
}
|
||||
}";
|
||||
// Arrange
|
||||
var stylesheet = _builder
|
||||
.WithPath("/css/styles.css")
|
||||
.WithContent(@"@media screen and (min-width: 600px) and (min-width: 900px) {
|
||||
.class {
|
||||
background: #666;
|
||||
}
|
||||
}")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var json = JsonConvert.SerializeObject(stylesheet);
|
||||
Debug.Print(json);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class TemplateTests
|
||||
{
|
||||
private readonly TemplateBuilder _builder = new TemplateBuilder();
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var template = BuildTemplate();
|
||||
|
||||
var clone = (Template)template.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, template);
|
||||
Assert.AreEqual(clone, template);
|
||||
Assert.AreEqual(clone.Path, template.Path);
|
||||
Assert.AreEqual(clone.IsMasterTemplate, template.IsMasterTemplate);
|
||||
Assert.AreEqual(clone.CreateDate, template.CreateDate);
|
||||
Assert.AreEqual(clone.Alias, template.Alias);
|
||||
Assert.AreEqual(clone.Id, template.Id);
|
||||
Assert.AreEqual(clone.Key, template.Key);
|
||||
Assert.AreEqual(clone.MasterTemplateAlias, template.MasterTemplateAlias);
|
||||
Assert.AreEqual(clone.MasterTemplateId.Value, template.MasterTemplateId.Value);
|
||||
Assert.AreEqual(clone.Name, template.Name);
|
||||
Assert.AreEqual(clone.UpdateDate, template.UpdateDate);
|
||||
|
||||
// clone.Content should be null but getting it would lazy-load
|
||||
var type = clone.GetType();
|
||||
var contentField = type.BaseType.GetField("_content", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
var value = contentField.GetValue(clone);
|
||||
Assert.IsNull(value);
|
||||
|
||||
// this double verifies by reflection
|
||||
// need to exclude content else it would lazy-load
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps.Where(x => x.Name != "Content"))
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(template, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var template = BuildTemplate();
|
||||
|
||||
var json = JsonConvert.SerializeObject(template);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private Template BuildTemplate()
|
||||
{
|
||||
return _builder
|
||||
.WithId(3)
|
||||
.WithAlias("test")
|
||||
.WithName("Test")
|
||||
.WithCreateDate(DateTime.Now)
|
||||
.WithUpdateDate(DateTime.Now)
|
||||
.WithKey(Guid.NewGuid())
|
||||
.WithPath("-1,3")
|
||||
.WithContent("blah")
|
||||
.AsMasterTemplate("master", 88)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class RelationBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int parentId = 9;
|
||||
const int childId = 8;
|
||||
const int id = 4;
|
||||
var key = Guid.NewGuid();
|
||||
var createDate = DateTime.Now.AddHours(-1);
|
||||
var updateDate = DateTime.Now;
|
||||
const string comment = "test comment";
|
||||
const int relationTypeId = 66;
|
||||
const string relationTypeAlias = "test";
|
||||
const string relationTypeName = "name";
|
||||
var parentObjectType = Guid.NewGuid();
|
||||
var childObjectType = Guid.NewGuid();
|
||||
|
||||
var builder = new RelationBuilder();
|
||||
|
||||
// Act
|
||||
var relation = builder
|
||||
.BetweenIds(parentId, childId)
|
||||
.WithId(id)
|
||||
.WithComment(comment)
|
||||
.WithCreateDate(createDate)
|
||||
.WithUpdateDate(updateDate)
|
||||
.WithKey(key)
|
||||
.AddRelationType()
|
||||
.WithId(relationTypeId)
|
||||
.WithAlias(relationTypeAlias)
|
||||
.WithName(relationTypeName)
|
||||
.WithIsBidirectional(false)
|
||||
.WithParentObjectType(parentObjectType)
|
||||
.WithChildObjectType(childObjectType)
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(parentId, relation.ParentId);
|
||||
Assert.AreEqual(childId, relation.ChildId);
|
||||
Assert.AreEqual(id, relation.Id);
|
||||
Assert.AreEqual(createDate, relation.CreateDate);
|
||||
Assert.AreEqual(updateDate, relation.UpdateDate);
|
||||
Assert.AreEqual(key, relation.Key);
|
||||
Assert.AreEqual(comment, relation.Comment);
|
||||
Assert.AreEqual(relationTypeId, relation.RelationType.Id);
|
||||
Assert.AreEqual(relationTypeAlias, relation.RelationType.Alias);
|
||||
Assert.AreEqual(relationTypeName, relation.RelationType.Name);
|
||||
Assert.IsFalse(relation.RelationType.IsBidirectional);
|
||||
Assert.AreEqual(parentObjectType, relation.RelationType.ParentObjectType);
|
||||
Assert.AreEqual(childObjectType, relation.RelationType.ChildObjectType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class RelationTypeBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int id = 3;
|
||||
const string alias = "test";
|
||||
const string name = "Test";
|
||||
var key = Guid.NewGuid();
|
||||
var createDate = DateTime.Now.AddHours(-2);
|
||||
var updateDate = DateTime.Now.AddHours(-1);
|
||||
var deleteDate = DateTime.Now;
|
||||
var parentObjectType = Guid.NewGuid();
|
||||
var childObjectType = Guid.NewGuid();
|
||||
const bool isBidirectional = true;
|
||||
|
||||
var builder = new RelationTypeBuilder();
|
||||
|
||||
// Act
|
||||
var relationType = builder
|
||||
.WithId(id)
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithKey(key)
|
||||
.WithCreateDate(createDate)
|
||||
.WithUpdateDate(updateDate)
|
||||
.WithDeleteDate(deleteDate)
|
||||
.WithParentObjectType(parentObjectType)
|
||||
.WithChildObjectType(childObjectType)
|
||||
.WithIsBidirectional(isBidirectional)
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(id, relationType.Id);
|
||||
Assert.AreEqual(alias, relationType.Alias);
|
||||
Assert.AreEqual(name, relationType.Name);
|
||||
Assert.AreEqual(key, relationType.Key);
|
||||
Assert.AreEqual(createDate, relationType.CreateDate);
|
||||
Assert.AreEqual(updateDate, relationType.UpdateDate);
|
||||
Assert.AreEqual(deleteDate, relationType.DeleteDate);
|
||||
Assert.AreEqual(parentObjectType, relationType.ParentObjectType);
|
||||
Assert.AreEqual(childObjectType, relationType.ChildObjectType);
|
||||
Assert.AreEqual(isBidirectional, relationType.IsBidirectional);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class StylesheetBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const string path = "/css/styles.css";
|
||||
const string content = @"body { color:#000; } .bold {font-weight:bold;}";
|
||||
|
||||
var builder = new StylesheetBuilder();
|
||||
|
||||
// Act
|
||||
var stylesheet = builder
|
||||
.WithPath(path)
|
||||
.WithContent(content)
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("\\css\\styles.css", stylesheet.Path);
|
||||
Assert.AreEqual(content, stylesheet.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class TemplateBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const int id = 3;
|
||||
const string alias = "test";
|
||||
const string name = "Test";
|
||||
var key = Guid.NewGuid();
|
||||
var createDate = DateTime.Now.AddHours(-1);
|
||||
var updateDate = DateTime.Now;
|
||||
const string path = "-1,3";
|
||||
const string content = "blah";
|
||||
const string masterTemplateAlias = "master";
|
||||
const int masterTemplateId = 88;
|
||||
|
||||
var builder = new TemplateBuilder();
|
||||
|
||||
// Act
|
||||
var template = builder
|
||||
.WithId(3)
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithCreateDate(createDate)
|
||||
.WithUpdateDate(updateDate)
|
||||
.WithKey(key)
|
||||
.WithPath(path)
|
||||
.WithContent(content)
|
||||
.AsMasterTemplate(masterTemplateAlias, masterTemplateId)
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(id, template.Id);
|
||||
Assert.AreEqual(alias, template.Alias);
|
||||
Assert.AreEqual(name, template.Name);
|
||||
Assert.AreEqual(createDate, template.CreateDate);
|
||||
Assert.AreEqual(updateDate, template.UpdateDate);
|
||||
Assert.AreEqual(key, template.Key);
|
||||
Assert.AreEqual(path, template.Path);
|
||||
Assert.AreEqual(content, template.Content);
|
||||
Assert.IsTrue(template.IsMasterTemplate);
|
||||
Assert.AreEqual(masterTemplateAlias, template.MasterTemplateAlias);
|
||||
Assert.AreEqual(masterTemplateId, template.MasterTemplateId.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class RelationTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new Relation(9, 8, new RelationType("test", "test", false, Guid.NewGuid(), Guid.NewGuid())
|
||||
{
|
||||
Id = 66
|
||||
})
|
||||
{
|
||||
Comment = "test comment",
|
||||
CreateDate = DateTime.Now,
|
||||
Id = 4,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now
|
||||
};
|
||||
|
||||
var clone = (Relation) item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
Assert.AreEqual(clone.ChildId, item.ChildId);
|
||||
Assert.AreEqual(clone.Comment, item.Comment);
|
||||
Assert.AreEqual(clone.CreateDate, item.CreateDate);
|
||||
Assert.AreEqual(clone.Id, item.Id);
|
||||
Assert.AreEqual(clone.Key, item.Key);
|
||||
Assert.AreEqual(clone.ParentId, item.ParentId);
|
||||
Assert.AreNotSame(clone.RelationType, item.RelationType);
|
||||
Assert.AreEqual(clone.RelationType, item.RelationType);
|
||||
Assert.AreEqual(clone.RelationTypeId, item.RelationTypeId);
|
||||
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var item = new Relation(9, 8, new RelationType("test", "test", false, Guid.NewGuid(), Guid.NewGuid())
|
||||
{
|
||||
Id = 66
|
||||
})
|
||||
{
|
||||
Comment = "test comment",
|
||||
CreateDate = DateTime.Now,
|
||||
Id = 4,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(item);
|
||||
Debug.Print(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class TemplateTests : UmbracoTestBase
|
||||
{
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new Template(ShortStringHelper, "Test", "test")
|
||||
{
|
||||
Id = 3,
|
||||
CreateDate = DateTime.Now,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
Content = "blah",
|
||||
Path = "-1,3",
|
||||
IsMasterTemplate = true,
|
||||
MasterTemplateAlias = "master",
|
||||
MasterTemplateId = new Lazy<int>(() => 88)
|
||||
};
|
||||
|
||||
var clone = (Template)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
Assert.AreEqual(clone.Path, item.Path);
|
||||
Assert.AreEqual(clone.IsMasterTemplate, item.IsMasterTemplate);
|
||||
Assert.AreEqual(clone.CreateDate, item.CreateDate);
|
||||
Assert.AreEqual(clone.Alias, item.Alias);
|
||||
Assert.AreEqual(clone.Id, item.Id);
|
||||
Assert.AreEqual(clone.Key, item.Key);
|
||||
Assert.AreEqual(clone.MasterTemplateAlias, item.MasterTemplateAlias);
|
||||
Assert.AreEqual(clone.MasterTemplateId.Value, item.MasterTemplateId.Value);
|
||||
Assert.AreEqual(clone.Name, item.Name);
|
||||
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
|
||||
|
||||
// clone.Content should be null but getting it would lazy-load
|
||||
var type = clone.GetType();
|
||||
var contentField = type.BaseType.GetField("_content", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
var value = contentField.GetValue(clone);
|
||||
Assert.IsNull(value);
|
||||
|
||||
// this double verifies by reflection
|
||||
// need to exclude content else it would lazy-load
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps.Where(x => x.Name != "Content"))
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var item = new Template(ShortStringHelper, "Test", "test")
|
||||
{
|
||||
Id = 3,
|
||||
CreateDate = DateTime.Now,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now,
|
||||
Content = "blah",
|
||||
MasterTemplateAlias = "master",
|
||||
MasterTemplateId = new Lazy<int>(() => 88)
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(item);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -298,6 +298,8 @@
|
||||
<Compile Include="Models\DictionaryTranslationTests.cs" />
|
||||
<Compile Include="Models\RelationTests.cs" />
|
||||
<Compile Include="Models\TemplateTests.cs" />
|
||||
<Compile Include="Models\PropertyGroupTests.cs" />
|
||||
<Compile Include="Models\PropertyTypeTests.cs" />
|
||||
<Compile Include="Models\LightEntityTest.cs" />
|
||||
<Compile Include="Models\UserTests.cs" />
|
||||
<Compile Include="Web\Mvc\RenderModelBinderTests.cs" />
|
||||
@@ -399,7 +401,6 @@
|
||||
<Compile Include="PropertyEditors\PropertyEditorValueConverterTests.cs" />
|
||||
<Compile Include="Models\ContentTests.cs" />
|
||||
<Compile Include="Models\ContentXmlTest.cs" />
|
||||
<Compile Include="Models\StylesheetTests.cs" />
|
||||
<Compile Include="Persistence\SqlCeTableByTableTest.cs" />
|
||||
<Compile Include="Persistence\DatabaseContextTests.cs" />
|
||||
<Compile Include="Persistence\Mappers\ContentMapperTest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user