Refactor IContent vs IContentType

This commit is contained in:
Stephan
2019-02-05 19:58:33 +01:00
parent 29f2f34f9b
commit b260c18056
21 changed files with 330 additions and 140 deletions

View File

@@ -15,7 +15,7 @@ namespace Umbraco.Core.Models
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
[DebuggerDisplay("Id: {Id}, Name: {Name}, ContentType: {ContentTypeBase.Alias}")]
[DebuggerDisplay("Id: {Id}, Name: {Name}, ContentType: {ContentType.Alias}")]
public abstract class ContentBase : TreeEntityBase, IContentBase
{
protected static readonly ContentCultureInfosCollection NoInfos = new ContentCultureInfosCollection();

View File

@@ -1,20 +1,17 @@
namespace Umbraco.Core.Models
using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a simplified view of a content type.
/// </summary>
public interface ISimpleContentType
public interface ISimpleContentType : IUmbracoEntity
{
/// <summary>
/// Gets the alias of the content type.
/// </summary>
string Alias { get; }
/// <summary>
/// Gets the identifier of the content type.
/// </summary>
int Id { get; }
/// <summary>
/// Gets the default template of the content type.
/// </summary>
@@ -35,11 +32,6 @@
/// </summary>
bool IsContainer { get; }
/// <summary>
/// Gets the name of the content type.
/// </summary>
string Name { get; }
/// <summary>
/// Gets a value indicating whether content of that type can be created at the root of the tree.
/// </summary>

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
{
@@ -7,67 +9,56 @@ namespace Umbraco.Core.Models
/// </summary>
public class SimpleContentType : ISimpleContentType
{
private readonly int _id;
private readonly string _name;
/// <summary>
/// Initializes a new instance of the <see cref="SimpleContentType"/> class.
/// </summary>
public SimpleContentType(IContentType contentType)
: this((IContentTypeBase)contentType)
{
if (contentType == null) throw new ArgumentNullException(nameof(contentType));
Id = contentType.Id;
Alias = contentType.Alias;
DefaultTemplate = contentType.DefaultTemplate;
Variations = contentType.Variations;
Icon = contentType.Icon;
IsContainer = contentType.IsContainer;
Icon = contentType.Icon;
Name = contentType.Name;
AllowedAsRoot = contentType.AllowedAsRoot;
IsElement = contentType.IsElement;
}
/// <summary>
/// Initializes a new instance of the <see cref="SimpleContentType"/> class.
/// </summary>
public SimpleContentType(IMediaType mediaType)
{
if (mediaType == null) throw new ArgumentNullException(nameof(mediaType));
Id = mediaType.Id;
Alias = mediaType.Alias;
Variations = mediaType.Variations;
Icon = mediaType.Icon;
IsContainer = mediaType.IsContainer;
Icon = mediaType.Icon;
Name = mediaType.Name;
AllowedAsRoot = mediaType.AllowedAsRoot;
IsElement = mediaType.IsElement;
}
: this((IContentTypeBase)mediaType)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="SimpleContentType"/> class.
/// </summary>
public SimpleContentType(IMemberType memberType)
{
if (memberType == null) throw new ArgumentNullException(nameof(memberType));
: this((IContentTypeBase)memberType)
{ }
Id = memberType.Id;
Alias = memberType.Alias;
Variations = memberType.Variations;
Icon = memberType.Icon;
IsContainer = memberType.IsContainer;
Icon = memberType.Icon;
Name = memberType.Name;
AllowedAsRoot = memberType.AllowedAsRoot;
IsElement = memberType.IsElement;
private SimpleContentType(IContentTypeBase contentType)
{
if (contentType == null) throw new ArgumentNullException(nameof(contentType));
_id = contentType.Id;
Alias = contentType.Alias;
Variations = contentType.Variations;
Icon = contentType.Icon;
IsContainer = contentType.IsContainer;
Icon = contentType.Icon;
_name = contentType.Name;
AllowedAsRoot = contentType.AllowedAsRoot;
IsElement = contentType.IsElement;
}
/// <inheritdoc />
public string Alias { get; }
/// <inheritdoc />
public int Id { get; }
public int Id
{
get => _id;
set => throw new NotSupportedException();
}
/// <inheritdoc />
public ITemplate DefaultTemplate { get; }
@@ -82,7 +73,11 @@ namespace Umbraco.Core.Models
public bool IsContainer { get; }
/// <inheritdoc />
public string Name { get; }
public string Name
{
get => _name;
set => throw new NotSupportedException();
}
/// <inheritdoc />
public bool AllowedAsRoot { get; }
@@ -121,5 +116,34 @@ namespace Umbraco.Core.Models
return ((Alias != null ? Alias.GetHashCode() : 0) * 397) ^ Id;
}
}
// we have to have all this, because we're an IUmbracoEntity, because that is
// required by the query expression visitor / SimpleContentTypeMapper
public object DeepClone() => throw new NotImplementedException();
public Guid Key { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public DateTime CreateDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public DateTime UpdateDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public DateTime? DeleteDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool HasIdentity => throw new NotImplementedException();
public int CreatorId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int ParentId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public void SetParent(ITreeEntity parent) => throw new NotImplementedException();
public int Level { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Path { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int SortOrder { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool Trashed => throw new NotImplementedException();
public bool IsDirty() => throw new NotImplementedException();
public bool IsPropertyDirty(string propName) => throw new NotImplementedException();
public IEnumerable<string> GetDirtyProperties() => throw new NotImplementedException();
public void ResetDirtyProperties() => throw new NotImplementedException();
public bool WasDirty() => throw new NotImplementedException();
public bool WasPropertyDirty(string propertyName) => throw new NotImplementedException();
public void ResetWereDirtyProperties() => throw new NotImplementedException();
public void ResetDirtyProperties(bool rememberDirty) => throw new NotImplementedException();
public IEnumerable<string> GetWereDirtyProperties() => throw new NotImplementedException();
}
}

View File

@@ -25,6 +25,7 @@ namespace Umbraco.Core.Persistence.Mappers
Add<AuditItemMapper>();
Add<ContentMapper>();
Add<ContentTypeMapper>();
Add<SimpleContentTypeMapper>();
Add<DataTypeMapper>();
Add<DictionaryMapper>();
Add<DictionaryTranslationMapper>();

View File

@@ -0,0 +1,38 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
namespace Umbraco.Core.Persistence.Mappers
{
[MapperFor(typeof(ISimpleContentType))]
[MapperFor(typeof(SimpleContentType))]
public sealed class SimpleContentTypeMapper : BaseMapper
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache => PropertyInfoCacheInstance;
protected override void BuildMap()
{
if (PropertyInfoCache.IsEmpty == false) return;
CacheMap<ContentType, NodeDto>(src => src.Id, dto => dto.NodeId);
CacheMap<ContentType, NodeDto>(src => src.CreateDate, dto => dto.CreateDate);
CacheMap<ContentType, NodeDto>(src => src.Level, dto => dto.Level);
CacheMap<ContentType, NodeDto>(src => src.ParentId, dto => dto.ParentId);
CacheMap<ContentType, NodeDto>(src => src.Path, dto => dto.Path);
CacheMap<ContentType, NodeDto>(src => src.SortOrder, dto => dto.SortOrder);
CacheMap<ContentType, NodeDto>(src => src.Name, dto => dto.Text);
CacheMap<ContentType, NodeDto>(src => src.Trashed, dto => dto.Trashed);
CacheMap<ContentType, NodeDto>(src => src.Key, dto => dto.UniqueId);
CacheMap<ContentType, NodeDto>(src => src.CreatorId, dto => dto.UserId);
CacheMap<ContentType, ContentTypeDto>(src => src.Alias, dto => dto.Alias);
CacheMap<ContentType, ContentTypeDto>(src => src.AllowedAsRoot, dto => dto.AllowAtRoot);
CacheMap<ContentType, ContentTypeDto>(src => src.Description, dto => dto.Description);
CacheMap<ContentType, ContentTypeDto>(src => src.Icon, dto => dto.Icon);
CacheMap<ContentType, ContentTypeDto>(src => src.IsContainer, dto => dto.IsContainer);
CacheMap<ContentType, ContentTypeDto>(src => src.IsElement, dto => dto.IsElement);
CacheMap<ContentType, ContentTypeDto>(src => src.Thumbnail, dto => dto.Thumbnail);
}
}
}

View File

@@ -467,6 +467,7 @@
<Compile Include="Persistence\Mappers\AuditEntryMapper.cs" />
<Compile Include="Persistence\Mappers\AuditItemMapper.cs" />
<Compile Include="Persistence\Mappers\ConsentMapper.cs" />
<Compile Include="Persistence\Mappers\SimpleContentTypeMapper.cs" />
<Compile Include="Persistence\Repositories\IAuditEntryRepository.cs" />
<Compile Include="Persistence\Repositories\IConsentRepository.cs" />
<Compile Include="Persistence\Repositories\Implement\AuditEntryRepository.cs" />

View File

@@ -264,7 +264,7 @@ AnotherContentFinder
public void Resolves_Assigned_Mappers()
{
var foundTypes1 = _typeLoader.GetAssignedMapperTypes();
Assert.AreEqual(29, foundTypes1.Count());
Assert.AreEqual(30, foundTypes1.Count());
}
[Test]

View File

@@ -1,22 +1,60 @@
using System;
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.Composers;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.Testing;
using Umbraco.Web.PropertyEditors;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class ContentExtensionsTests : UmbracoTestBase
{
#region Others
private IContentTypeService _contentTypeService;
protected override void Compose()
{
base.Compose();
Composition.Register(_ => Mock.Of<ILogger>());
Composition.ComposeFileSystems();
Composition.Register(_ => Mock.Of<IDataTypeService>());
Composition.Register(_ => Mock.Of<IContentSection>());
// all this is required so we can validate properties...
var editor = new TextboxPropertyEditor(Mock.Of<ILogger>()) { Alias = "test" };
Composition.Register(_ => new DataEditorCollection(new[] { editor }));
Composition.Register<PropertyEditorCollection>();
var dataType = Mock.Of<IDataType>();
Mock.Get(dataType).Setup(x => x.Configuration).Returns(() => new object());
var dataTypeService = Mock.Of<IDataTypeService>();
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny<int>()))
.Returns(() => dataType);
_contentTypeService = Mock.Of<IContentTypeService>();
var mediaTypeService = Mock.Of<IMediaTypeService>();
var memberTypeService = Mock.Of<IMemberTypeService>();
Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService)));
}
[Test]
public void DirtyProperty_Reset_Clears_SavedPublishedState()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.PublishedState = PublishedState.Publishing;
@@ -30,6 +68,8 @@ namespace Umbraco.Tests.Models
public void DirtyProperty_OnlyIfActuallyChanged_Content()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// if you assign a content property with its value it is not dirty
@@ -52,6 +92,8 @@ namespace Umbraco.Tests.Models
public void DirtyProperty_OnlyIfActuallyChanged_User()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var prop = content.Properties.First();
@@ -76,6 +118,8 @@ namespace Umbraco.Tests.Models
public void DirtyProperty_UpdateDate()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var prop = content.Properties.First();
@@ -99,6 +143,8 @@ namespace Umbraco.Tests.Models
public void DirtyProperty_WasDirty_ContentProperty()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties(false);
Assert.IsFalse(content.IsDirty());
@@ -126,6 +172,8 @@ namespace Umbraco.Tests.Models
public void DirtyProperty_WasDirty_ContentSortOrder()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties(false);
Assert.IsFalse(content.IsDirty());
@@ -153,6 +201,8 @@ namespace Umbraco.Tests.Models
public void DirtyProperty_WasDirty_UserProperty()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var prop = content.Properties.First();
content.ResetDirtyProperties(false);
@@ -178,7 +228,5 @@ namespace Umbraco.Tests.Models
//Assert.IsFalse(content.WasDirty()); // not impacted by user properties
Assert.IsTrue(content.WasDirty()); // now it is!
}
#endregion
}
}

View File

@@ -17,6 +17,7 @@ using Umbraco.Core.Models.Entities;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Tests.Testing;
@@ -28,6 +29,8 @@ namespace Umbraco.Tests.Models
[TestFixture]
public class ContentTests : UmbracoTestBase
{
private IContentTypeService _contentTypeService;
protected override void Compose()
{
base.Compose();
@@ -48,19 +51,24 @@ namespace Umbraco.Tests.Models
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny<int>()))
.Returns(() => dataType);
Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService));
_contentTypeService = Mock.Of<IContentTypeService>();
var mediaTypeService = Mock.Of<IMediaTypeService>();
var memberTypeService = Mock.Of<IMemberTypeService>();
Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService)));
}
[Test]
public void Variant_Culture_Names_Track_Dirty_Changes()
{
var contentType = new ContentType(-1) { Alias = "contentType" };
contentType.Variations = ContentVariation.Culture;
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = new Content("content", -1, contentType) { Id = 1, VersionId = 1 };
const string langFr = "fr-FR";
contentType.Variations = ContentVariation.Culture;
Assert.IsFalse(content.IsPropertyDirty("CultureInfos")); //hasn't been changed
Thread.Sleep(500); //The "Date" wont be dirty if the test runs too fast since it will be the same date
@@ -123,6 +131,7 @@ namespace Umbraco.Tests.Models
//ensure that nothing is marked as dirty
contentType.ResetDirtyProperties(false);
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateSimpleContent(contentType);
@@ -138,6 +147,8 @@ namespace Umbraco.Tests.Models
public void All_Dirty_Properties_Get_Reset()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties(false);
@@ -154,6 +165,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -167,6 +180,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -183,6 +198,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -199,6 +216,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.Id = 10;
content.Key = new Guid("29181B97-CB8F-403F-86DE-5FEB497F4800");
@@ -278,6 +297,8 @@ namespace Umbraco.Tests.Models
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
contentType.Variations = ContentVariation.Culture;
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.SetCultureName("Hello", "en-US");
@@ -387,6 +408,8 @@ namespace Umbraco.Tests.Models
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
contentType.Variations = ContentVariation.Culture;
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.SetCultureName("Hello", "en-US");
@@ -458,6 +481,8 @@ namespace Umbraco.Tests.Models
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var i = 200;
foreach (var property in content.Properties)
@@ -509,6 +534,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -527,6 +554,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -591,6 +620,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -613,6 +644,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -642,6 +675,8 @@ namespace Umbraco.Tests.Models
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act - note that the PropertyType's properties like SortOrder is not updated through the Content object
@@ -663,6 +698,8 @@ namespace Umbraco.Tests.Models
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -680,6 +717,8 @@ namespace Umbraco.Tests.Models
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -697,6 +736,8 @@ namespace Umbraco.Tests.Models
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -716,6 +757,8 @@ namespace Umbraco.Tests.Models
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -731,6 +774,8 @@ namespace Umbraco.Tests.Models
public void Can_Verify_Content_Is_Published()
{
var contentType = MockedContentTypes.CreateTextPageContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties();
@@ -800,6 +845,8 @@ namespace Umbraco.Tests.Models
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.ResetDirtyProperties(); //reset
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateTextpageContent(contentType, "test", -1);
content.ResetDirtyProperties();

View File

@@ -4,15 +4,20 @@ using AutoMapper;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.Composers;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Services;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services.Implement;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Tests.Testing;
using Umbraco.Web.PropertyEditors;
using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Tests.Models.Mapping
@@ -21,12 +26,37 @@ namespace Umbraco.Tests.Models.Mapping
[UmbracoTest(AutoMapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
public class ContentWebModelMappingTests : TestWithDatabaseBase
{
private IContentTypeService _contentTypeService;
protected override void Compose()
{
base.Compose();
Composition.RegisterUnique(f => Mock.Of<ICultureDictionaryFactory>());
Composition.RegisterUnique(f => Mock.Of<IContentTypeService>());
Composition.Register(_ => Mock.Of<ILogger>());
Composition.ComposeFileSystems();
Composition.Register(_ => Mock.Of<IDataTypeService>());
Composition.Register(_ => Mock.Of<IContentSection>());
// all this is required so we can validate properties...
var editor = new TextboxPropertyEditor(Mock.Of<ILogger>()) { Alias = "test" };
Composition.Register(_ => new DataEditorCollection(new[] { editor }));
Composition.Register<PropertyEditorCollection>();
var dataType = Mock.Of<IDataType>();
Mock.Get(dataType).Setup(x => x.Configuration).Returns(() => new object());
var dataTypeService = Mock.Of<IDataTypeService>();
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny<int>()))
.Returns(() => dataType);
_contentTypeService = Mock.Of<IContentTypeService>();
var mediaTypeService = Mock.Of<IMediaTypeService>();
var memberTypeService = Mock.Of<IMemberTypeService>();
Composition.RegisterUnique(_ => _contentTypeService);
Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService)));
}
[DataEditor("Test.Test", "Test", "~/Test.html")]
@@ -53,6 +83,8 @@ namespace Umbraco.Tests.Models.Mapping
public void To_Media_Item_Simple()
{
var contentType = MockedContentTypes.CreateImageMediaType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedMedia.CreateMediaImage(contentType, -1);
FixUsers(content);
@@ -70,6 +102,8 @@ namespace Umbraco.Tests.Models.Mapping
public void To_Content_Item_Simple()
{
var contentType = MockedContentTypes.CreateSimpleContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateSimpleContent(contentType);
FixUsers(content);
@@ -87,6 +121,8 @@ namespace Umbraco.Tests.Models.Mapping
public void To_Content_Item_Dto()
{
var contentType = MockedContentTypes.CreateSimpleContentType();
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateSimpleContent(contentType);
FixUsers(content);
@@ -117,8 +153,8 @@ namespace Umbraco.Tests.Models.Mapping
public void To_Display_Model()
{
var contentType = MockedContentTypes.CreateSimpleContentType();
var contentTypeServiceMock = Mock.Get(Current.Services.ContentTypeService);
contentTypeServiceMock.Setup(x => x.Get(contentType.Id)).Returns(() => contentType);
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
Mock.Get(_contentTypeService).Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateSimpleContent(contentType);
@@ -127,7 +163,7 @@ namespace Umbraco.Tests.Models.Mapping
// need ids for tabs
var id = 1;
foreach (var g in content.PropertyGroups)
foreach (var g in contentType.CompositionPropertyGroups)
g.Id = id++;
var result = Mapper.Map<IContent, ContentItemDisplay>(content);
@@ -141,7 +177,7 @@ namespace Umbraco.Tests.Models.Mapping
AssertDisplayProperty(invariantContent, p);
}
Assert.AreEqual(content.PropertyGroups.Count(), invariantContent.Tabs.Count());
Assert.AreEqual(contentType.CompositionPropertyGroups.Count(), invariantContent.Tabs.Count());
Assert.IsTrue(invariantContent.Tabs.First().IsActive);
Assert.IsTrue(invariantContent.Tabs.Except(new[] { invariantContent.Tabs.First() }).All(x => x.IsActive == false));
}
@@ -151,9 +187,8 @@ namespace Umbraco.Tests.Models.Mapping
{
var contentType = MockedContentTypes.CreateSimpleContentType();
contentType.PropertyGroups.Clear();
var contentTypeServiceMock = Mock.Get(Current.Services.ContentTypeService);
contentTypeServiceMock.Setup(x => x.Get(contentType.Id)).Returns(() => contentType);
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
Mock.Get(_contentTypeService).Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = new Content("Home", -1, contentType) { Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0 };
@@ -168,7 +203,7 @@ namespace Umbraco.Tests.Models.Mapping
AssertDisplayProperty(invariantContent, p);
}
Assert.AreEqual(content.PropertyGroups.Count(), invariantContent.Tabs.Count());
Assert.AreEqual(contentType.CompositionPropertyGroups.Count(), invariantContent.Tabs.Count());
}
[Test]
@@ -186,8 +221,8 @@ namespace Umbraco.Tests.Models.Mapping
p.Id = idSeed;
idSeed++;
}
var contentTypeServiceMock = Mock.Get(Current.Services.ContentTypeService);
contentTypeServiceMock.Setup(x => x.Get(contentType.Id)).Returns(() => contentType);
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
Mock.Get(_contentTypeService).Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
var content = MockedContent.CreateSimpleContent(contentType);
@@ -200,7 +235,7 @@ namespace Umbraco.Tests.Models.Mapping
}
//need ids for tabs
var id = 1;
foreach (var g in content.PropertyGroups)
foreach (var g in contentType.CompositionPropertyGroups)
{
g.Id = id;
id++;
@@ -221,7 +256,7 @@ namespace Umbraco.Tests.Models.Mapping
AssertDisplayProperty(invariantContent, p);
}
Assert.AreEqual(content.PropertyGroups.Count(), invariantContent.Tabs.Count() - 1);
Assert.AreEqual(contentType.CompositionPropertyGroups.Count(), invariantContent.Tabs.Count() - 1);
Assert.IsTrue(invariantContent.Tabs.Any(x => x.Label == Current.Services.TextService.Localize("general/properties")));
Assert.AreEqual(2, invariantContent.Tabs.Where(x => x.Label == Current.Services.TextService.Localize("general/properties")).SelectMany(x => x.Properties.Where(p => p.Alias.StartsWith("_umb_") == false)).Count());
}

View File

@@ -67,20 +67,7 @@ namespace Umbraco.Tests.Models
Assert.AreEqual(clone.Id, member.Id);
Assert.AreEqual(clone.VersionId, member.VersionId);
Assert.AreEqual(clone.AdditionalData, member.AdditionalData);
Assert.AreNotSame(clone.ContentType, member.ContentType);
Assert.AreEqual(clone.ContentType, member.ContentType);
Assert.AreEqual(clone.ContentType.PropertyGroups.Count, member.ContentType.PropertyGroups.Count);
for (var index = 0; index < member.ContentType.PropertyGroups.Count; index++)
{
Assert.AreNotSame(clone.ContentType.PropertyGroups[index], member.ContentType.PropertyGroups[index]);
Assert.AreEqual(clone.ContentType.PropertyGroups[index], member.ContentType.PropertyGroups[index]);
}
Assert.AreEqual(clone.ContentType.PropertyTypes.Count(), member.ContentType.PropertyTypes.Count());
for (var index = 0; index < member.ContentType.PropertyTypes.Count(); index++)
{
Assert.AreNotSame(clone.ContentType.PropertyTypes.ElementAt(index), member.ContentType.PropertyTypes.ElementAt(index));
Assert.AreEqual(clone.ContentType.PropertyTypes.ElementAt(index), member.ContentType.PropertyTypes.ElementAt(index));
}
Assert.AreEqual(clone.ContentTypeId, member.ContentTypeId);
Assert.AreEqual(clone.CreateDate, member.CreateDate);
Assert.AreEqual(clone.CreatorId, member.CreatorId);
@@ -112,6 +99,9 @@ namespace Umbraco.Tests.Models
Assert.AreEqual(clone.Properties[index], member.Properties[index]);
}
// this can be the same, it is immutable
Assert.AreSame(clone.ContentType, member.ContentType);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)

View File

@@ -227,6 +227,9 @@ namespace Umbraco.Tests.Models
// now it will work
contentType.Variations = ContentVariation.Culture;
// recreate content to re-capture content type variations
content = new Content("content", -1, contentType) { Id = 1, VersionId = 1 };
// invariant name works
content.Name = "name";
Assert.AreEqual("name", content.GetCultureName(null));

View File

@@ -130,10 +130,11 @@ namespace Umbraco.Tests.Persistence.Repositories
var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
ServiceContext.FileService.SaveTemplate(hasPropertiesContentType.DefaultTemplate); // else, FK violation on contentType!
contentTypeRepository.Save(hasPropertiesContentType);
IContent content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
// save = create the initial version
contentTypeRepository.Save(hasPropertiesContentType);
repository.Save(content1);
versions.Add(content1.VersionId); // the first version
@@ -399,9 +400,10 @@ namespace Umbraco.Tests.Persistence.Repositories
var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository);
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
contentTypeRepository.Save(contentType);
IContent textpage = MockedContent.CreateSimpleContent(contentType);
contentTypeRepository.Save(contentType);
repository.Save(textpage);
scope.Complete();
@@ -487,9 +489,10 @@ namespace Umbraco.Tests.Persistence.Repositories
var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository);
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
contentTypeRepository.Save(contentType);
var textpage = MockedContent.CreateSimpleContent(contentType);
contentTypeRepository.Save(contentType);
repository.Save(textpage);

View File

@@ -61,8 +61,9 @@ namespace Umbraco.Tests.Persistence.Repositories
udb.EnableSqlCount = false;
var mediaType = MockedContentTypes.CreateSimpleMediaType("umbTextpage1", "Textpage");
var media = MockedMedia.CreateSimpleMedia(mediaType, "hello", -1);
mediaTypeRepository.Save(mediaType);
var media = MockedMedia.CreateSimpleMedia(mediaType, "hello", -1);
repository.Save(media);
udb.EnableSqlCount = true;
@@ -271,7 +272,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
repository.Save(folder);
}
var types = new[] { 1031 };
var query = scope.SqlContext.Query<IMedia>().Where(x => types.Contains(x.ContentTypeId));
@@ -302,7 +303,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
repository.Save(folder);
}
var types = new[] { "Folder" };
var query = scope.SqlContext.Query<IMedia>().Where(x => types.Contains(x.ContentType.Alias));

View File

@@ -164,21 +164,19 @@ namespace Umbraco.Tests.Persistence.Repositories
var memberType = MockedContentTypes.CreateSimpleMemberType();
memberTypeRepository.Save(memberType);
var member = MockedMember.CreateSimpleMember(memberType, "Johnny Hefty", "johnny@example.com", "123", "hefty");
repository.Save(member);
var sut = repository.Get(member.Id);
Assert.That(sut.ContentType.PropertyGroups.Count(), Is.EqualTo(2));
Assert.That(sut.ContentType.PropertyTypes.Count(), Is.EqualTo(3 + Constants.Conventions.Member.GetStandardPropertyTypeStubs().Count));
Assert.That(memberType.CompositionPropertyGroups.Count(), Is.EqualTo(2));
Assert.That(memberType.CompositionPropertyTypes.Count(), Is.EqualTo(3 + Constants.Conventions.Member.GetStandardPropertyTypeStubs().Count));
Assert.That(sut.Properties.Count(), Is.EqualTo(3 + Constants.Conventions.Member.GetStandardPropertyTypeStubs().Count));
var grp = sut.PropertyGroups.FirstOrDefault(x => x.Name == Constants.Conventions.Member.StandardPropertiesGroupName);
var grp = memberType.CompositionPropertyGroups.FirstOrDefault(x => x.Name == Constants.Conventions.Member.StandardPropertiesGroupName);
Assert.IsNotNull(grp);
var aliases = Constants.Conventions.Member.GetStandardPropertyTypeStubs().Select(x => x.Key).ToArray();
foreach (var p in sut.PropertyTypes.Where(x => aliases.Contains(x.Alias)))
foreach (var p in memberType.CompositionPropertyTypes.Where(x => aliases.Contains(x.Alias)))
{
Assert.AreEqual(grp.Id, p.PropertyGroupId.Value);
}

View File

@@ -75,7 +75,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
repository.Save(user);
// Assert
Assert.That(user.HasIdentity, Is.True);
@@ -96,9 +96,9 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
repository.Save(user1);
repository.Save(use2);
// Assert
Assert.That(user1.HasIdentity, Is.True);
@@ -117,7 +117,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var user = MockedUser.CreateUser();
repository.Save(user);
// Act
var resolved = repository.Get((int)user.Id);
@@ -132,9 +132,7 @@ namespace Umbraco.Tests.Persistence.Repositories
public void Can_Perform_Update_On_UserRepository()
{
var ct = MockedContentTypes.CreateBasicContentType("test");
var content = MockedContent.CreateBasicContent(ct);
var mt = MockedContentTypes.CreateSimpleMediaType("testmedia", "TestMedia");
var media = MockedMedia.CreateSimpleMedia(mt, "asdf", -1);
// Arrange
var provider = TestObjects.GetScopeProvider(Logger);
@@ -147,11 +145,12 @@ namespace Umbraco.Tests.Persistence.Repositories
contentTypeRepo.Save(ct);
mediaTypeRepo.Save(mt);
var content = MockedContent.CreateBasicContent(ct);
var media = MockedMedia.CreateSimpleMedia(mt, "asdf", -1);
contentRepository.Save(content);
mediaRepository.Save(media);
var user = CreateAndCommitUserWithGroup(userRepository, userGroupRepository);
@@ -171,7 +170,7 @@ namespace Umbraco.Tests.Persistence.Repositories
resolved.Username = "newName";
userRepository.Save(resolved);
var updatedItem = (User) userRepository.Get(user.Id);
// Assert
@@ -204,13 +203,13 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
repository.Save(user);
var id = user.Id;
var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of<IMapperCollection>(),TestObjects.GetGlobalSettings());
repository2.Delete(user);
var resolved = repository2.Get((int) id);
@@ -373,7 +372,7 @@ namespace Umbraco.Tests.Persistence.Repositories
scope.Database.AsUmbracoDatabase().EnableSqlCount = false;
}
}
}
[Test]
@@ -429,7 +428,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
var user = MockedUser.CreateUser();
repository.Save(user);
var group = MockedUserGroup.CreateUserGroup();
userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id });

View File

@@ -554,7 +554,6 @@ namespace Umbraco.Tests.Services
IContent contentItem = MockedContent.CreateTextpageContent(contentType1, "Testing", -1);
ServiceContext.ContentService.SaveAndPublish(contentItem);
var initProps = contentItem.Properties.Count;
var initPropTypes = contentItem.PropertyTypes.Count();
//remove a property
contentType1.RemovePropertyType(contentType1.PropertyTypes.First().Alias);
@@ -563,7 +562,6 @@ namespace Umbraco.Tests.Services
//re-load it from the db
contentItem = ServiceContext.ContentService.GetById(contentItem.Id);
Assert.AreEqual(initPropTypes - 1, contentItem.PropertyTypes.Count());
Assert.AreEqual(initProps - 1, contentItem.Properties.Count);
}

View File

@@ -83,7 +83,6 @@ namespace Umbraco.Tests.Services
IMember member = MockedMember.CreateSimpleMember(memberType, "test", "test@test.com", "pass", "test");
ServiceContext.MemberService.Save(member);
var initProps = member.Properties.Count;
var initPropTypes = member.PropertyTypes.Count();
//remove a property (NOT ONE OF THE DEFAULTS)
var standardProps = Constants.Conventions.Member.GetStandardPropertyTypeStubs();
@@ -93,7 +92,6 @@ namespace Umbraco.Tests.Services
//re-load it from the db
member = ServiceContext.MemberService.GetById(member.Id);
Assert.AreEqual(initPropTypes - 1, member.PropertyTypes.Count());
Assert.AreEqual(initProps - 1, member.Properties.Count);
}

View File

@@ -1,5 +1,7 @@
using System;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Testing
@@ -7,7 +9,7 @@ namespace Umbraco.Tests.Testing
public static class ContentBaseExtensions
{
/// <summary>
/// Set property values by alias with an annonymous object.
/// Set property values by alias with an anonymous object.
/// </summary>
/// <remarks>Does not support variants.</remarks>
public static void PropertyValues(this IContentBase content, object value, string culture = null, string segment = null)
@@ -15,11 +17,13 @@ namespace Umbraco.Tests.Testing
if (value == null)
throw new Exception("No properties has been passed in");
var contentType = Current.Services.ContentTypeBaseServices.GetContentTypeOf(content);
var propertyInfos = value.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
//Check if a PropertyType with alias exists thus being a valid property
var propertyType = content.PropertyTypes.FirstOrDefault(x => x.Alias == propertyInfo.Name);
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propertyInfo.Name);
if (propertyType == null)
throw new Exception($"The property alias {propertyInfo.Name} is not valid, because no PropertyType with this alias exists");

View File

@@ -110,7 +110,7 @@ namespace Umbraco.Tests.UmbracoExamine
m.GetCultureName(It.IsAny<string>()) == (string)x.Attribute("nodeName") &&
m.Path == (string)x.Attribute("path") &&
m.Properties == new PropertyCollection() &&
m.ContentType == Mock.Of<IMediaType>(mt =>
m.ContentType == Mock.Of<ISimpleContentType>(mt =>
mt.Alias == (string)x.Attribute("nodeTypeAlias") &&
mt.Id == (int)x.Attribute("nodeType"))))
.ToArray();

View File

@@ -43,6 +43,14 @@ namespace Umbraco.Tests.Web.Controllers
[UmbracoTest(Database = UmbracoTestOptions.Database.None)]
public class ContentControllerTests : TestWithDatabaseBase
{
private IContentType _contentTypeForMockedContent;
public override void SetUp()
{
base.SetUp();
_contentTypeForMockedContent = null;
}
protected override void ComposeApplication(bool withApplication)
{
base.ComposeApplication(withApplication);
@@ -115,23 +123,42 @@ namespace Umbraco.Tests.Web.Controllers
};
}
private IContent GetMockedContent()
private IContentType GetMockedContentType()
{
var content = MockedContent.CreateSimpleContent(MockedContentTypes.CreateSimpleContentType());
content.Id = 123;
content.Path = "-1,123";
var contentType = MockedContentTypes.CreateSimpleContentType();
//ensure things have ids
var ids = 888;
foreach (var g in content.PropertyGroups)
foreach (var g in contentType.CompositionPropertyGroups)
{
g.Id = ids;
ids++;
}
foreach (var p in content.PropertyTypes)
foreach (var p in contentType.CompositionPropertyGroups)
{
p.Id = ids;
ids++;
}
return contentType;
}
private IContent GetMockedContent()
{
if (_contentTypeForMockedContent == null)
{
_contentTypeForMockedContent = GetMockedContentType();
Mock.Get(Current.Services.ContentTypeService)
.Setup(x => x.Get(_contentTypeForMockedContent.Id))
.Returns(_contentTypeForMockedContent);
Mock.Get(Current.Services.ContentTypeService)
.As<IContentTypeBaseService>()
.Setup(x => x.Get(_contentTypeForMockedContent.Id))
.Returns(_contentTypeForMockedContent);
}
var content = MockedContent.CreateSimpleContent(_contentTypeForMockedContent);
content.Id = 123;
content.Path = "-1,123";
return content;
}
@@ -229,7 +256,7 @@ namespace Umbraco.Tests.Web.Controllers
Factory.GetInstance<IProfilingLogger>(),
Factory.GetInstance<IRuntimeState>(),
helper);
return controller;
}
@@ -251,9 +278,6 @@ namespace Umbraco.Tests.Web.Controllers
{
ApiController CtrlFactory(HttpRequestMessage message, UmbracoContext umbracoContext, UmbracoHelper helper)
{
var contentServiceMock = Mock.Get(Current.Services.ContentService);
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => GetMockedContent());
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
var controller = new ContentController(
propertyEditorCollection,
@@ -336,15 +360,11 @@ namespace Umbraco.Tests.Web.Controllers
ApiController CtrlFactory(HttpRequestMessage message, UmbracoContext umbracoContext, UmbracoHelper helper)
{
var contentServiceMock = Mock.Get(Current.Services.ContentService);
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => content);
contentServiceMock.Setup(x => x.Save(It.IsAny<IContent>(), It.IsAny<int>(), It.IsAny<bool>()))
.Returns(new OperationResult(OperationResultType.Success, new Core.Events.EventMessages())); //success
var contentTypeServiceMock = Mock.Get(Current.Services.ContentTypeService);
contentTypeServiceMock.Setup(x => x.Get(content.ContentTypeId)).Returns(() => MockedContentTypes.CreateSimpleContentType());
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
var controller = new ContentController(
propertyEditorCollection,
@@ -369,8 +389,6 @@ namespace Umbraco.Tests.Web.Controllers
Assert.AreEqual(HttpStatusCode.OK, response.Item1.StatusCode);
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(response.Item2);
Assert.AreEqual(1, display.Variants.Count());
Assert.AreEqual(content.PropertyGroups.Count(), display.Variants.ElementAt(0).Tabs.Count());
Assert.AreEqual(content.PropertyTypes.Count(), display.Variants.ElementAt(0).Tabs.ElementAt(0).Properties.Count());
}
[Test]
@@ -380,15 +398,11 @@ namespace Umbraco.Tests.Web.Controllers
ApiController CtrlFactory(HttpRequestMessage message, UmbracoContext umbracoContext, UmbracoHelper helper)
{
var contentServiceMock = Mock.Get(Current.Services.ContentService);
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => content);
contentServiceMock.Setup(x => x.Save(It.IsAny<IContent>(), It.IsAny<int>(), It.IsAny<bool>()))
.Returns(new OperationResult(OperationResultType.Success, new Core.Events.EventMessages())); //success
var contentTypeServiceMock = Mock.Get(Current.Services.ContentTypeService);
contentTypeServiceMock.Setup(x => x.Get(content.ContentTypeId)).Returns(() => MockedContentTypes.CreateSimpleContentType());
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
var controller = new ContentController(
propertyEditorCollection,
@@ -428,15 +442,11 @@ namespace Umbraco.Tests.Web.Controllers
ApiController CtrlFactory(HttpRequestMessage message, UmbracoContext umbracoContext, UmbracoHelper helper)
{
var contentServiceMock = Mock.Get(Current.Services.ContentService);
contentServiceMock.Setup(x => x.GetById(123)).Returns(() => content);
contentServiceMock.Setup(x => x.Save(It.IsAny<IContent>(), It.IsAny<int>(), It.IsAny<bool>()))
.Returns(new OperationResult(OperationResultType.Success, new Core.Events.EventMessages())); //success
var contentTypeServiceMock = Mock.Get(Current.Services.ContentTypeService);
contentTypeServiceMock.Setup(x => x.Get(content.ContentTypeId)).Returns(() => MockedContentTypes.CreateSimpleContentType());
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
var controller = new ContentController(
propertyEditorCollection,