backports data type service updates and fixes unit tests with correct seeding value.

This commit is contained in:
Shannon
2013-12-16 17:17:23 +11:00
parent 6a9b8d5540
commit 2ce952bdbb
18 changed files with 502 additions and 177 deletions

View File

@@ -0,0 +1,29 @@
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a stored pre-value field value
/// </summary>
public class PreValue
{
public PreValue(int id, string value)
{
Value = value;
Id = id;
}
public PreValue(string value)
{
Value = value;
}
/// <summary>
/// The value stored for the pre-value field
/// </summary>
public string Value { get; private set; }
/// <summary>
/// The database id for the pre-value field value
/// </summary>
public int Id { get; private set; }
}
}

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents the pre-value data for a DataType
/// </summary>
/// <remarks>
/// Due to the legacy nature of the data that can be stored for pre-values, we have this class which encapsulates the 2 different
/// ways that pre-values are stored: A string array or a Dictionary.
///
/// Most legacy property editors won't support the dictionary format but new property editors should always use the dictionary format.
/// In order to get overrideable pre-values working we need a dictionary since we'll have to reference a pre-value by a key.
/// </remarks>
public class PreValueCollection
{
private IDictionary<string, PreValue> _preValuesAsDictionary;
private IEnumerable<PreValue> _preValuesAsArray;
public IEnumerable<PreValue> PreValuesAsArray
{
get
{
if (_preValuesAsArray == null)
{
throw new InvalidOperationException("The current pre-value collection is dictionary based, use the PreValuesAsDictionary property instead");
}
return _preValuesAsArray;
}
set { _preValuesAsArray = value; }
}
public IDictionary<string, PreValue> PreValuesAsDictionary
{
get
{
if (_preValuesAsDictionary == null)
{
throw new InvalidOperationException("The current pre-value collection is array based, use the PreValuesAsArray property instead");
}
return _preValuesAsDictionary;
}
set { _preValuesAsDictionary = value; }
}
/// <summary>
/// Check if it is a dictionary based collection
/// </summary>
public bool IsDictionaryBased
{
get { return _preValuesAsDictionary != null; }
}
public PreValueCollection(IEnumerable<PreValue> preVals)
{
_preValuesAsArray = preVals;
}
public PreValueCollection(IDictionary<string, PreValue> preVals)
{
_preValuesAsDictionary = preVals;
}
/// <summary>
/// Regardless of how the pre-values are stored this will return as a dictionary, it will convert an array based to a dictionary
/// </summary>
/// <returns></returns>
public IDictionary<string, PreValue> FormatAsDictionary()
{
if (IsDictionaryBased)
{
return PreValuesAsDictionary;
}
//it's an array so need to format it, the alias will just be an iteration
var result = new Dictionary<string, PreValue>();
var asArray = PreValuesAsArray.ToArray();
for (var i = 0; i < asArray.Length; i++)
{
result.Add(i.ToInvariantString(), asArray[i]);
}
return result;
}
}
}

View File

@@ -84,39 +84,58 @@ namespace Umbraco.Core.Persistence.UnitOfWork
});
}
/// <summary>
/// Commits all batched changes within the scope of a PetaPoco transaction <see cref="Transaction"/>
/// </summary>
/// <remarks>
/// Unlike a typical unit of work, this UOW will let you commit more than once since a new transaction is creaed per
/// Commit() call instead of having one Transaction per UOW.
/// </remarks>
public void Commit()
{
using (var transaction = Database.GetTransaction())
{
foreach (var operation in _operations.OrderBy(o => o.ProcessDate))
{
switch (operation.Type)
{
case TransactionType.Insert:
operation.Repository.PersistNewItem(operation.Entity);
break;
case TransactionType.Delete:
operation.Repository.PersistDeletedItem(operation.Entity);
break;
case TransactionType.Update:
operation.Repository.PersistUpdatedItem(operation.Entity);
break;
}
}
transaction.Complete();
}
/// <summary>
/// Commits all batched changes within the scope of a PetaPoco transaction <see cref="Transaction"/>
/// </summary>
/// <remarks>
/// Unlike a typical unit of work, this UOW will let you commit more than once since a new transaction is creaed per
/// Commit() call instead of having one Transaction per UOW.
/// </remarks>
public void Commit()
{
Commit(null);
}
// Clear everything
_operations.Clear();
_key = Guid.NewGuid();
}
/// <summary>
/// Commits all batched changes within the scope of a PetaPoco transaction <see cref="Transaction"/>
/// </summary>
/// <param name="transactionCompleting">
/// Allows you to set a callback which is executed before the transaction is committed, allow you to add additional SQL
/// operations to the overall commit process after the queue has been processed.
/// </param>
internal void Commit(Action<UmbracoDatabase> transactionCompleting)
{
using (var transaction = Database.GetTransaction())
{
foreach (var operation in _operations.OrderBy(o => o.ProcessDate))
{
switch (operation.Type)
{
case TransactionType.Insert:
operation.Repository.PersistNewItem(operation.Entity);
break;
case TransactionType.Delete:
operation.Repository.PersistDeletedItem(operation.Entity);
break;
case TransactionType.Update:
operation.Repository.PersistUpdatedItem(operation.Entity);
break;
}
}
//Execute the callback if there is one
if (transactionCompleting != null)
{
transactionCompleting(Database);
}
transaction.Complete();
}
// Clear everything
_operations.Clear();
_key = Guid.NewGuid();
}
public object Key
{

View File

@@ -9,6 +9,7 @@ using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.PropertyEditors;
using umbraco.interfaces;
namespace Umbraco.Core.Services
@@ -18,16 +19,16 @@ namespace Umbraco.Core.Services
/// </summary>
public class DataTypeService : IDataTypeService
{
private readonly RepositoryFactory _repositoryFactory;
private readonly RepositoryFactory _repositoryFactory;
private readonly IDatabaseUnitOfWorkProvider _uowProvider;
private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
public DataTypeService()
: this(new RepositoryFactory())
{}
{ }
public DataTypeService(RepositoryFactory repositoryFactory)
: this(new PetaPocoUnitOfWorkProvider(), repositoryFactory)
: this(new PetaPocoUnitOfWorkProvider(), repositoryFactory)
{
}
@@ -36,9 +37,9 @@ namespace Umbraco.Core.Services
{
}
public DataTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory)
public DataTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory)
{
_repositoryFactory = repositoryFactory;
_repositoryFactory = repositoryFactory;
_uowProvider = provider;
}
@@ -74,7 +75,7 @@ namespace Umbraco.Core.Services
/// <summary>
/// Gets a <see cref="IDataTypeDefinition"/> by its control Id
/// </summary>
/// <param name="id">Id of the DataType control</param>
/// <param name="id">Id of the property editor</param>
/// <returns>Collection of <see cref="IDataTypeDefinition"/> objects with a matching contorl id</returns>
public IEnumerable<IDataTypeDefinition> GetDataTypeDefinitionByControlId(Guid id)
{
@@ -109,27 +110,25 @@ namespace Umbraco.Core.Services
{
using (var uow = _uowProvider.GetUnitOfWork())
{
var dtos = uow.Database.Fetch<DataTypePreValueDto>("WHERE datatypeNodeId = @Id", new {Id = id});
var dtos = uow.Database.Fetch<DataTypePreValueDto>("WHERE datatypeNodeId = @Id", new { Id = id });
var list = dtos.Select(x => x.Value).ToList();
return list;
}
}
/// <summary>
/// Gets all prevalues for an <see cref="IDataTypeDefinition"/>
/// Returns the PreValueCollection for the specified data type
/// </summary>
/// <remarks>
/// This method should be kept internal until a proper PreValue object model is introduced.
/// </remarks>
/// <param name="id">Id of the <see cref="IDataTypeDefinition"/> to retrieve prevalues from</param>
/// <returns>An enumerable list of Tuples containing Id, Alias, SortOrder, Value</returns>
internal IEnumerable<Tuple<int, string, int, string>> GetDetailedPreValuesByDataTypeId(int id)
/// <param name="id"></param>
/// <returns></returns>
public PreValueCollection GetPreValuesCollectionByDataTypeId(int id)
{
using (var uow = _uowProvider.GetUnitOfWork())
{
var dtos = uow.Database.Fetch<DataTypePreValueDto>("WHERE datatypeNodeId = @Id", new { Id = id });
var list = dtos.Select(x => new Tuple<int, string, int, string>(x.Id, x.Alias, x.SortOrder, x.Value)).ToList();
return list;
var list = dtos.Select(x => new Tuple<PreValue, string, int>(new PreValue(x.Id, x.Value), x.Alias, x.SortOrder)).ToList();
return PreValueConverter.ConvertToPreValuesCollection(list);
}
}
@@ -154,8 +153,8 @@ namespace Umbraco.Core.Services
/// <param name="userId">Id of the user issueing the save</param>
public void Save(IDataTypeDefinition dataTypeDefinition, int userId = 0)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
return;
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
return;
using (new WriteLock(Locker))
{
@@ -206,8 +205,11 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="id">Id of the DataTypeDefinition to save PreValues for</param>
/// <param name="values">List of string values to save</param>
[Obsolete("This should no longer be used, use the alternative SavePreValues or SaveDataTypeAndPreValues methods instead. This will only insert pre-values without keys")]
public void SavePreValues(int id, IEnumerable<string> values)
{
//TODO: Should we raise an event here since we are really saving values for the data type?
using (new WriteLock(Locker))
{
using (var uow = _uowProvider.GetUnitOfWork())
@@ -236,6 +238,111 @@ namespace Umbraco.Core.Services
}
}
/// <summary>
/// Saves/updates the pre-values
/// </summary>
/// <param name="id"></param>
/// <param name="values"></param>
/// <remarks>
/// We need to actually look up each pre-value and maintain it's id if possible - this is because of silly property editors
/// like 'dropdown list publishing keys'
/// </remarks>
public void SavePreValues(int id, IDictionary<string, PreValue> values)
{
//TODO: Should we raise an event here since we are really saving values for the data type?
using (new WriteLock(Locker))
{
using (var uow = _uowProvider.GetUnitOfWork())
{
using (var transaction = uow.Database.GetTransaction())
{
AddOrUpdatePreValues(id, values, uow);
transaction.Complete();
}
}
}
}
/// <summary>
/// This will save a data type and it's pre-values in one transaction
/// </summary>
/// <param name="dataTypeDefinition"></param>
/// <param name="values"></param>
/// <param name="userId"></param>
public void SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary<string, PreValue> values, int userId = 0)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
return;
using (new WriteLock(Locker))
{
var uow = (PetaPocoUnitOfWork)_uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateDataTypeDefinitionRepository(uow))
{
dataTypeDefinition.CreatorId = userId;
repository.AddOrUpdate(dataTypeDefinition);
//complete the transaction, but run the delegate before the db transaction is finalized
uow.Commit(database => AddOrUpdatePreValues(dataTypeDefinition.Id, values, uow));
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
}
}
Audit.Add(AuditTypes.Save, string.Format("Save DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
}
private void AddOrUpdatePreValues(int id, IDictionary<string, PreValue> preValueCollection, IDatabaseUnitOfWork uow)
{
//first just get all pre-values for this data type so we can compare them to see if we need to insert or update or replace
var sql = new Sql().Select("*")
.From<DataTypePreValueDto>()
.Where<DataTypePreValueDto>(dto => dto.DataTypeNodeId == id)
.OrderBy<DataTypePreValueDto>(dto => dto.SortOrder);
var currentVals = uow.Database.Fetch<DataTypePreValueDto>(sql).ToArray();
//already existing, need to be updated
var valueIds = preValueCollection.Where(x => x.Value.Id > 0).Select(x => x.Value.Id).ToArray();
var existingByIds = currentVals.Where(x => valueIds.Contains(x.Id)).ToArray();
//These ones need to be removed from the db, they no longer exist in the new values
var deleteById = currentVals.Where(x => valueIds.Contains(x.Id) == false);
foreach (var d in deleteById)
{
uow.Database.Execute(
"DELETE FROM cmsDataTypePreValues WHERE datatypeNodeId = @DataTypeId AND id=@Id",
new { DataTypeId = id, Id = d.Id });
}
var sortOrder = 1;
foreach (var pre in preValueCollection)
{
var existing = existingByIds.FirstOrDefault(valueDto => valueDto.Id == pre.Value.Id);
if (existing != null)
{
existing.Value = pre.Value.Value;
existing.SortOrder = sortOrder;
uow.Database.Update(existing);
}
else
{
var dto = new DataTypePreValueDto
{
DataTypeNodeId = id,
Value = pre.Value.Value,
SortOrder = sortOrder,
Alias = pre.Key
};
uow.Database.Insert(dto);
}
sortOrder++;
}
}
/// <summary>
/// Deletes an <see cref="IDataTypeDefinition"/>
/// </summary>
@@ -246,43 +353,43 @@ namespace Umbraco.Core.Services
/// <param name="dataTypeDefinition"><see cref="IDataTypeDefinition"/> to delete</param>
/// <param name="userId">Optional Id of the user issueing the deletion</param>
public void Delete(IDataTypeDefinition dataTypeDefinition, int userId = 0)
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
return;
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
{
//Find ContentTypes using this IDataTypeDefinition on a PropertyType
var query = Query<PropertyType>.Builder.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id);
var contentTypes = repository.GetByQuery(query);
{
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
return;
//Loop through the list of results and remove the PropertyTypes that references the DataTypeDefinition that is being deleted
foreach (var contentType in contentTypes)
{
if (contentType == null) continue;
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
{
//Find ContentTypes using this IDataTypeDefinition on a PropertyType
var query = Query<PropertyType>.Builder.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id);
var contentTypes = repository.GetByQuery(query);
foreach (var group in contentType.PropertyGroups)
{
var types = @group.PropertyTypes.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id).ToList();
foreach (var propertyType in types)
{
@group.PropertyTypes.Remove(propertyType);
}
}
//Loop through the list of results and remove the PropertyTypes that references the DataTypeDefinition that is being deleted
foreach (var contentType in contentTypes)
{
if (contentType == null) continue;
repository.AddOrUpdate(contentType);
}
foreach (var group in contentType.PropertyGroups)
{
var types = @group.PropertyTypes.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id).ToList();
foreach (var propertyType in types)
{
@group.PropertyTypes.Remove(propertyType);
}
}
var dataTypeRepository = _repositoryFactory.CreateDataTypeDefinitionRepository(uow);
dataTypeRepository.Delete(dataTypeDefinition);
repository.AddOrUpdate(contentType);
}
uow.Commit();
var dataTypeRepository = _repositoryFactory.CreateDataTypeDefinitionRepository(uow);
dataTypeRepository.Delete(dataTypeDefinition);
Deleted.RaiseEvent(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
}
uow.Commit();
Audit.Add(AuditTypes.Delete, string.Format("Delete DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
Deleted.RaiseEvent(new DeleteEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
}
Audit.Add(AuditTypes.Delete, string.Format("Delete DataTypeDefinition performed by user"), userId, dataTypeDefinition.Id);
}
/// <summary>
@@ -290,6 +397,7 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="id">Id of the DataType, which corresponds to the Guid Id of the control</param>
/// <returns><see cref="IDataType"/> object</returns>
[Obsolete("IDataType is obsolete and is no longer used, it will be removed from the codebase in future versions")]
public IDataType GetDataTypeById(Guid id)
{
return DataTypesResolver.Current.GetById(id);
@@ -299,6 +407,7 @@ namespace Umbraco.Core.Services
/// Gets a complete list of all registered <see cref="IDataType"/>'s
/// </summary>
/// <returns>An enumerable list of <see cref="IDataType"/> objects</returns>
[Obsolete("IDataType is obsolete and is no longer used, it will be removed from the codebase in future versions")]
public IEnumerable<IDataType> GetAllDataTypes()
{
return DataTypesResolver.Current.DataTypes;
@@ -308,22 +417,58 @@ namespace Umbraco.Core.Services
/// <summary>
/// Occurs before Delete
/// </summary>
public static event TypedEventHandler<IDataTypeService, DeleteEventArgs<IDataTypeDefinition>> Deleting;
public static event TypedEventHandler<IDataTypeService, DeleteEventArgs<IDataTypeDefinition>> Deleting;
/// <summary>
/// Occurs after Delete
/// </summary>
public static event TypedEventHandler<IDataTypeService, DeleteEventArgs<IDataTypeDefinition>> Deleted;
public static event TypedEventHandler<IDataTypeService, DeleteEventArgs<IDataTypeDefinition>> Deleted;
/// <summary>
/// Occurs before Save
/// </summary>
public static event TypedEventHandler<IDataTypeService, SaveEventArgs<IDataTypeDefinition>> Saving;
public static event TypedEventHandler<IDataTypeService, SaveEventArgs<IDataTypeDefinition>> Saving;
/// <summary>
/// Occurs after Save
/// </summary>
public static event TypedEventHandler<IDataTypeService, SaveEventArgs<IDataTypeDefinition>> Saved;
public static event TypedEventHandler<IDataTypeService, SaveEventArgs<IDataTypeDefinition>> Saved;
#endregion
internal static class PreValueConverter
{
/// <summary>
/// Converts the tuple to a pre-value collection
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
internal static PreValueCollection ConvertToPreValuesCollection(IEnumerable<Tuple<PreValue, string, int>> list)
{
//now we need to determine if they are dictionary based, otherwise they have to be array based
var dictionary = new Dictionary<string, PreValue>();
//need to check all of the keys, if there's only one and it is empty then it's an array
var keys = list.Select(x => x.Item2).Distinct().ToArray();
if (keys.Length == 1 && keys[0].IsNullOrWhiteSpace())
{
return new PreValueCollection(list.OrderBy(x => x.Item3).Select(x => x.Item1));
}
foreach (var item in list
.OrderBy(x => x.Item3) //we'll order them first so we maintain the order index in the dictionary
.GroupBy(x => x.Item2)) //group by alias
{
if (item.Count() > 1)
{
//if there's more than 1 item per key, then it cannot be a dictionary, just return the array
return new PreValueCollection(list.OrderBy(x => x.Item3).Select(x => x.Item1));
}
dictionary.Add(item.Key, item.First().Item1);
}
return new PreValueCollection(dictionary);
}
}
}
}

View File

@@ -83,13 +83,36 @@ namespace Umbraco.Core.Services
/// <returns>An enumerable list of string values</returns>
IEnumerable<string> GetPreValuesByDataTypeId(int id);
/// <summary>
/// Gets a pre-value collection by data type id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
PreValueCollection GetPreValuesCollectionByDataTypeId(int id);
/// <summary>
/// Saves a list of PreValues for a given DataTypeDefinition
/// </summary>
/// <param name="id">Id of the DataTypeDefinition to save PreValues for</param>
/// <param name="values">List of string values to save</param>
[Obsolete("This should no longer be used, use the alternative SavePreValues or SaveDataTypeAndPreValues methods instead. This will only insert pre-values without keys")]
void SavePreValues(int id, IEnumerable<string> values);
/// <summary>
/// Saves a list of PreValues for a given DataTypeDefinition
/// </summary>
/// <param name="id">Id of the DataTypeDefinition to save PreValues for</param>
/// <param name="values">List of key/value pairs to save</param>
void SavePreValues(int id, IDictionary<string, PreValue> values);
/// <summary>
/// Saves the data type and it's prevalues
/// </summary>
/// <param name="dataTypeDefinition"></param>
/// <param name="values"></param>
/// <param name="userId"></param>
void SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary<string, PreValue> values, int userId = 0);
/// <summary>
/// Gets a specific PreValue by its Id
/// </summary>

View File

@@ -707,20 +707,23 @@ namespace Umbraco.Core.Services
{
var prevalues = new XElement("PreValues");
var prevalueList = ((DataTypeService)_dataTypeService).GetDetailedPreValuesByDataTypeId(dataTypeDefinition.Id);
foreach (var tuple in prevalueList)
var prevalueList = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id)
.FormatAsDictionary();
var sort = 0;
foreach (var pv in prevalueList)
{
var prevalue = new XElement("PreValue");
prevalue.Add(new XAttribute("Id", tuple.Item1));
prevalue.Add(new XAttribute("Value", tuple.Item4));
prevalue.Add(new XAttribute("Alias", tuple.Item2));
prevalue.Add(new XAttribute("SortOrder", tuple.Item3));
prevalue.Add(new XAttribute("Id", pv.Value.Id));
prevalue.Add(new XAttribute("Value", pv.Value.Value));
prevalue.Add(new XAttribute("Alias", pv.Key));
prevalue.Add(new XAttribute("SortOrder", sort));
prevalues.Add(prevalue);
sort++;
}
var xml = new XElement("DataType", prevalues);
xml.Add(new XAttribute("Name", dataTypeDefinition.Name));
//The 'ID' when exporting is actually the property editor alias (in pre v7 it was the IDataType GUID id)
xml.Add(new XAttribute("Id", dataTypeDefinition.ControlId));
xml.Add(new XAttribute("Definition", dataTypeDefinition.Key));
xml.Add(new XAttribute("DatabaseType", dataTypeDefinition.DatabaseType.ToString()));

View File

@@ -439,6 +439,16 @@ namespace Umbraco.Core
return String.Format(CultureInfo.InvariantCulture, format, args);
}
/// <summary>
/// Converts an integer to an invariant formatted string
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ToInvariantString(this int str)
{
return str.ToString(CultureInfo.InvariantCulture);
}
/// <summary>
/// Compares 2 strings with invariant culture and case ignored
/// </summary>

View File

@@ -189,6 +189,8 @@
<Compile Include="Models\ContentTypeCompositionBase.cs" />
<Compile Include="Models\ContentTypeExtensions.cs" />
<Compile Include="Models\ContentTypeSort.cs" />
<Compile Include="Models\PreValue.cs" />
<Compile Include="Models\PreValueCollection.cs" />
<Compile Include="Models\PublishedContent\IPublishedContentExtended.cs" />
<Compile Include="Models\PublishedContent\PublishedPropertyBase.cs" />
<Compile Include="Models\PublishedContent\PublishedContentModelFactoryImpl.cs" />

View File

@@ -5,6 +5,7 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Serialization;
using Umbraco.Tests.CodeFirst.Definitions;
using Umbraco.Tests.CodeFirst.TestModels;
@@ -39,7 +40,7 @@ namespace Umbraco.Tests.CodeFirst
var mappedContentTypes = ContentTypeDefinitionFactory.RetrieveMappedContentTypes();
ServiceContext.ContentTypeService.Save(mappedContentTypes);
var model = ServiceContext.ContentTypeService.GetContentType(1046);
var model = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed + 1);
Assert.That(model, Is.Not.Null);
}
@@ -145,8 +146,8 @@ namespace Umbraco.Tests.CodeFirst
var mappedContentTypes = ContentTypeDefinitionFactory.RetrieveMappedContentTypes().ToList();
ServiceContext.ContentTypeService.Save(mappedContentTypes);
var type1 = ServiceContext.ContentTypeService.GetContentType(1045);
var type2 = ServiceContext.ContentTypeService.GetContentType(1046);
var type1 = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var type2 = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed + 1);
Assert.That(type1, Is.Not.Null);
Assert.That(type2, Is.Not.Null);
@@ -163,7 +164,7 @@ namespace Umbraco.Tests.CodeFirst
var mappedContentTypes = ContentTypeDefinitionFactory.RetrieveMappedContentTypes().ToList();
ServiceContext.ContentTypeService.Save(mappedContentTypes);
var type1 = ServiceContext.ContentTypeService.GetContentType(1047);
var type1 = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed + 2);
Assert.That(type1, Is.Not.Null);
Assert.That(type1.PropertyGroups.Count(), Is.EqualTo(2));

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using umbraco.BusinessLogic;
@@ -27,7 +28,7 @@ namespace Umbraco.Tests.LegacyApi
// Arrange
var folder = MediaType.GetByAlias(Constants.Conventions.MediaTypes.Folder);
var folderStructure = folder.AllowedChildContentTypeIDs.ToList();
folderStructure.Add(1045);
folderStructure.Add(NodeDto.NodeIdSeed);
// Act
folder.AllowedChildContentTypeIDs = folderStructure.ToArray();
@@ -37,7 +38,7 @@ namespace Umbraco.Tests.LegacyApi
var updated = MediaType.GetByAlias(Constants.Conventions.MediaTypes.Folder);
Assert.That(updated.AllowedChildContentTypeIDs.Any(), Is.True);
Assert.That(updated.AllowedChildContentTypeIDs.Any(x => x == 1045), Is.True);
Assert.That(updated.AllowedChildContentTypeIDs.Any(x => x == NodeDto.NodeIdSeed), Is.True);
}
[Test]
@@ -85,7 +86,7 @@ namespace Umbraco.Tests.LegacyApi
public void CreateTestData()
{
//Create and Save ContentType "video" -> 1045
//Create and Save ContentType "video" -> NodeDto.NodeIdSeed
var videoMediaType = MockedContentTypes.CreateVideoMediaType();
ServiceContext.ContentTypeService.Save(videoMediaType);
}

View File

@@ -224,7 +224,7 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
// Act
var content = repository.Get(1048);
var content = repository.Get(NodeDto.NodeIdSeed + 3);
bool dirty = ((Content)content).IsDirty();
// Assert
@@ -242,11 +242,11 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
// Act
var content = repository.Get(1047);
var content = repository.Get(NodeDto.NodeIdSeed + 2);
content.Name = "About 2";
repository.AddOrUpdate(content);
unitOfWork.Commit();
var updatedContent = repository.Get(1047);
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
// Assert
Assert.That(updatedContent.Id, Is.EqualTo(content.Id));
@@ -264,8 +264,8 @@ namespace Umbraco.Tests.Persistence.Repositories
ContentTypeRepository contentTypeRepository;
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
var contentType = contentTypeRepository.Get(1045);
var content = new Content("Textpage 2 Child Node", 1048, contentType);
var contentType = contentTypeRepository.Get(NodeDto.NodeIdSeed);
var content = new Content("Textpage 2 Child Node", NodeDto.NodeIdSeed + 3, contentType);
content.CreatorId = 0;
content.WriterId = 0;
@@ -295,17 +295,17 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
// Act
var content = repository.Get(1048);
var content = repository.Get(NodeDto.NodeIdSeed + 3);
// Assert
Assert.That(content.Id, Is.EqualTo(1048));
Assert.That(content.Id, Is.EqualTo(NodeDto.NodeIdSeed + 3));
Assert.That(content.CreateDate, Is.GreaterThan(DateTime.MinValue));
Assert.That(content.UpdateDate, Is.GreaterThan(DateTime.MinValue));
Assert.That(content.ParentId, Is.Not.EqualTo(0));
Assert.That(content.Name, Is.EqualTo("Text Page 2"));
Assert.That(content.SortOrder, Is.EqualTo(1));
Assert.That(content.Version, Is.Not.EqualTo(Guid.Empty));
Assert.That(content.ContentTypeId, Is.EqualTo(1045));
Assert.That(content.ContentTypeId, Is.EqualTo(NodeDto.NodeIdSeed));
Assert.That(content.Path, Is.Not.Empty);
Assert.That(content.Properties.Any(), Is.True);
}
@@ -339,7 +339,7 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
// Act
var contents = repository.GetAll(1047, 1048);
var contents = repository.GetAll(NodeDto.NodeIdSeed + 2, NodeDto.NodeIdSeed + 3);
// Assert
Assert.That(contents, Is.Not.Null);
@@ -379,7 +379,7 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
// Act
var exists = repository.Exists(1046);
var exists = repository.Exists(NodeDto.NodeIdSeed + 1);
// Assert
Assert.That(exists, Is.True);
@@ -417,9 +417,9 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
// Act
var textpage = repository.Get(1046);
var subpage = repository.Get(1047);
var trashed = repository.Get(1049);
var textpage = repository.Get(NodeDto.NodeIdSeed + 1);
var subpage = repository.Get(NodeDto.NodeIdSeed + 2);
var trashed = repository.Get(NodeDto.NodeIdSeed + 4);
// Assert
Assert.That(textpage.Key.ToString().ToUpper(), Is.EqualTo("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"));
@@ -443,7 +443,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Assert
Assert.That(content, Is.Not.Null);
Assert.That(content.Id, Is.EqualTo(1046));
Assert.That(content.Id, Is.EqualTo(NodeDto.NodeIdSeed + 1));
}
}
@@ -457,7 +457,7 @@ namespace Umbraco.Tests.Persistence.Repositories
ContentTypeRepository contentTypeRepository;
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
var content = repository.Get(1047);
var content = repository.Get(NodeDto.NodeIdSeed + 2);
// Act
content.Language = "da-DK";
@@ -465,9 +465,9 @@ namespace Umbraco.Tests.Persistence.Repositories
repository.AddOrUpdate(content);
unitOfWork.Commit();
var latest = repository.Get(1047);
var english = repository.GetByLanguage(1047, "en-US");
var danish = repository.GetByLanguage(1047, "da-DK");
var latest = repository.Get(NodeDto.NodeIdSeed + 2);
var english = repository.GetByLanguage(NodeDto.NodeIdSeed + 2, "en-US");
var danish = repository.GetByLanguage(NodeDto.NodeIdSeed + 2, "da-DK");
// Assert
Assert.That(latest.Name, Is.EqualTo("Tekst Side 1"));
@@ -478,26 +478,26 @@ namespace Umbraco.Tests.Persistence.Repositories
public void CreateTestData()
{
//Create and Save ContentType "umbTextpage" -> 1045
//Create and Save ContentType "umbTextpage" -> NodeDto.NodeIdSeed
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
contentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522");
ServiceContext.ContentTypeService.Save(contentType);
//Create and Save Content "Homepage" based on "umbTextpage" -> 1046
//Create and Save Content "Homepage" based on "umbTextpage" -> NodeDto.NodeIdSeed + 1
Content textpage = MockedContent.CreateSimpleContent(contentType);
textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0");
ServiceContext.ContentService.Save(textpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1047
//Create and Save Content "Text Page 1" based on "umbTextpage" -> NodeDto.NodeIdSeed + 2
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
subpage.Key = new Guid("FF11402B-7E53-4654-81A7-462AC2108059");
ServiceContext.ContentService.Save(subpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1048
//Create and Save Content "Text Page 1" based on "umbTextpage" -> NodeDto.NodeIdSeed + 3
Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id);
ServiceContext.ContentService.Save(subpage2, 0);
//Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1049
//Create and Save Content "Text Page Deleted" based on "umbTextpage" -> NodeDto.NodeIdSeed + 4
Content trashed = MockedContent.CreateSimpleContent(contentType, "Text Page Deleted", -20);
trashed.Trashed = true;
ServiceContext.ContentService.Save(trashed, 0);

View File

@@ -5,6 +5,7 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Repositories;
@@ -93,7 +94,7 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork))
{
// Act
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
contentType.Thumbnail = "Doc2.png";
contentType.PropertyGroups["Content"].PropertyTypes.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext)
@@ -155,11 +156,11 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
// Assert
Assert.That(contentType, Is.Not.Null);
Assert.That(contentType.Id, Is.EqualTo(1046));
Assert.That(contentType.Id, Is.EqualTo(NodeDto.NodeIdSeed + 1));
}
}
@@ -195,7 +196,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var exists = repository.Exists(1045);
var exists = repository.Exists(NodeDto.NodeIdSeed);
// Assert
Assert.That(exists, Is.True);
@@ -210,14 +211,14 @@ namespace Umbraco.Tests.Persistence.Repositories
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
{
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
// Act
contentType.PropertyGroups["Meta"].PropertyTypes.Remove("metaDescription");
repository.AddOrUpdate(contentType);
unitOfWork.Commit();
var result = repository.Get(1046);
var result = repository.Get(NodeDto.NodeIdSeed + 1);
// Assert
Assert.That(result.PropertyTypes.Any(x => x.Alias == "metaDescription"), Is.False);
@@ -236,7 +237,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var contentType = repository.Get(1045);
var contentType = repository.Get(NodeDto.NodeIdSeed);
// Assert
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(3));
@@ -254,7 +255,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
// Assert
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(4));
@@ -270,7 +271,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
{
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
// Act
var urlAlias = new PropertyType(new Guid(), DataTypeDatabaseType.Nvarchar)
@@ -289,7 +290,7 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
// Assert
var updated = repository.Get(1046);
var updated = repository.Get(NodeDto.NodeIdSeed + 1);
Assert.That(addedPropertyType, Is.True);
Assert.That(updated.PropertyGroups.Count(), Is.EqualTo(2));
Assert.That(updated.PropertyTypes.Count(), Is.EqualTo(5));
@@ -314,7 +315,7 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
// Act
var contentType = repository.Get(1045);
var contentType = repository.Get(NodeDto.NodeIdSeed);
contentType.AllowedContentTypes = new List<ContentTypeSort>
{
new ContentTypeSort
@@ -334,7 +335,7 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
//Assert
var updated = repository.Get(1045);
var updated = repository.Get(NodeDto.NodeIdSeed);
Assert.That(updated.AllowedContentTypes.Any(), Is.True);
Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == subpageContentType.Alias), Is.True);
@@ -351,7 +352,7 @@ namespace Umbraco.Tests.Persistence.Repositories
ContentTypeRepository repository;
using (var contentRepository = CreateRepository(unitOfWork, out repository))
{
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
contentRepository.AddOrUpdate(subpage);
@@ -378,7 +379,7 @@ namespace Umbraco.Tests.Persistence.Repositories
ContentTypeRepository repository;
using (var contentRepository = CreateRepository(unitOfWork, out repository))
{
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
contentRepository.AddOrUpdate(subpage);
@@ -406,7 +407,7 @@ namespace Umbraco.Tests.Persistence.Repositories
ContentTypeRepository repository;
using (var contentRepository = CreateRepository(unitOfWork, out repository))
{
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
contentRepository.AddOrUpdate(subpage);
@@ -442,7 +443,7 @@ namespace Umbraco.Tests.Persistence.Repositories
ContentTypeRepository repository;
using (var contentRepository = CreateRepository(unitOfWork, out repository))
{
var contentType = repository.Get(1046);
var contentType = repository.Get(NodeDto.NodeIdSeed + 1);
var subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", contentType.Id);
contentRepository.AddOrUpdate(subpage);
@@ -475,11 +476,11 @@ namespace Umbraco.Tests.Persistence.Repositories
public void CreateTestData()
{
//Create and Save ContentType "umbTextpage" -> 1045
//Create and Save ContentType "umbTextpage" -> NodeDto.NodeIdSeed
ContentType simpleContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
ServiceContext.ContentTypeService.Save(simpleContentType);
//Create and Save ContentType "textPage" -> 1046
//Create and Save ContentType "textPage" -> NodeDto.NodeIdSeed + 1
ContentType textpageContentType = MockedContentTypes.CreateTextpageContentType();
ServiceContext.ContentTypeService.Save(textpageContentType);
}

View File

@@ -4,6 +4,7 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
@@ -145,7 +146,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var media = repository.Get(1046);
var media = repository.Get(NodeDto.NodeIdSeed + 1);
bool dirty = ((ICanBeDirty) media).IsDirty();
// Assert
@@ -164,12 +165,12 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var content = repository.Get(1047);
var content = repository.Get(NodeDto.NodeIdSeed + 2);
content.Name = "Test File Updated";
repository.AddOrUpdate(content);
unitOfWork.Commit();
var updatedContent = repository.Get(1047);
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
// Assert
Assert.That(updatedContent.Id, Is.EqualTo(content.Id));
@@ -188,12 +189,12 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var media = repository.Get(1047);
var media = repository.Get(NodeDto.NodeIdSeed + 2);
repository.Delete(media);
unitOfWork.Commit();
var deleted = repository.Get(1047);
var exists = repository.Exists(1047);
var deleted = repository.Get(NodeDto.NodeIdSeed + 2);
var exists = repository.Exists(NodeDto.NodeIdSeed + 2);
// Assert
Assert.That(deleted, Is.Null);
@@ -212,10 +213,10 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var media = repository.Get(1046);
var media = repository.Get(NodeDto.NodeIdSeed + 1);
// Assert
Assert.That(media.Id, Is.EqualTo(1046));
Assert.That(media.Id, Is.EqualTo(NodeDto.NodeIdSeed + 1));
Assert.That(media.CreateDate, Is.GreaterThan(DateTime.MinValue));
Assert.That(media.UpdateDate, Is.GreaterThan(DateTime.MinValue));
Assert.That(media.ParentId, Is.Not.EqualTo(0));
@@ -258,7 +259,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var medias = repository.GetAll(1046, 1047);
var medias = repository.GetAll(NodeDto.NodeIdSeed + 1, NodeDto.NodeIdSeed + 2);
// Assert
Assert.That(medias, Is.Not.Null);
@@ -298,9 +299,9 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var exists = repository.Exists(1046);
var existsToo = repository.Exists(1046);
var doesntExists = repository.Exists(1050);
var exists = repository.Exists(NodeDto.NodeIdSeed + 1);
var existsToo = repository.Exists(NodeDto.NodeIdSeed + 1);
var doesntExists = repository.Exists(NodeDto.NodeIdSeed + 5);
// Assert
Assert.That(exists, Is.True);
@@ -337,17 +338,17 @@ namespace Umbraco.Tests.Persistence.Repositories
public void CreateTestData()
{
//Create and Save folder-Media -> 1045
//Create and Save folder-Media -> NodeDto.NodeIdSeed
var folderMediaType = ServiceContext.ContentTypeService.GetMediaType(1031);
var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
ServiceContext.MediaService.Save(folder, 0);
//Create and Save image-Media -> 1046
//Create and Save image-Media -> NodeDto.NodeIdSeed + 1
var imageMediaType = ServiceContext.ContentTypeService.GetMediaType(1032);
var image = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);
ServiceContext.MediaService.Save(image, 0);
//Create and Save file-Media -> 1047
//Create and Save file-Media -> NodeDto.NodeIdSeed + 2
var fileMediaType = ServiceContext.ContentTypeService.GetMediaType(1033);
var file = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);
ServiceContext.MediaService.Save(file, 0);

View File

@@ -3,6 +3,7 @@ using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Repositories;
@@ -76,7 +77,7 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
// Act
var mediaType = repository.Get(1045);
var mediaType = repository.Get(NodeDto.NodeIdSeed);
mediaType.Thumbnail = "Doc2.png";
mediaType.PropertyGroups["Media"].PropertyTypes.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext)
@@ -197,12 +198,12 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
// Act
var mediaTypeV2 = repository.Get(1045);
var mediaTypeV2 = repository.Get(NodeDto.NodeIdSeed);
mediaTypeV2.PropertyGroups["Media"].PropertyTypes.Remove("title");
repository.AddOrUpdate(mediaTypeV2);
unitOfWork.Commit();
var mediaTypeV3 = repository.Get(1045);
var mediaTypeV3 = repository.Get(NodeDto.NodeIdSeed);
// Assert
Assert.That(mediaTypeV3.PropertyTypes.Any(x => x.Alias == "title"), Is.False);
@@ -224,7 +225,7 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
// Act
var contentType = repository.Get(1045);
var contentType = repository.Get(NodeDto.NodeIdSeed);
// Assert
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(2));

View File

@@ -3,6 +3,7 @@ using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
@@ -59,7 +60,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
var relationType = repositoryType.Get(1);
var relation = new Relation(1047, 1048, relationType);
var relation = new Relation(NodeDto.NodeIdSeed + 2, NodeDto.NodeIdSeed + 3, relationType);
repository.AddOrUpdate(relation);
unitOfWork.Commit();
@@ -132,8 +133,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Assert
Assert.That(relation, Is.Not.Null);
Assert.That(relation.HasIdentity, Is.True);
Assert.That(relation.ChildId, Is.EqualTo(1047));
Assert.That(relation.ParentId, Is.EqualTo(1046));
Assert.That(relation.ChildId, Is.EqualTo(NodeDto.NodeIdSeed + 2));
Assert.That(relation.ParentId, Is.EqualTo(NodeDto.NodeIdSeed + 1));
Assert.That(relation.RelationType.Alias, Is.EqualTo("relateContentOnCopy"));
}
}
@@ -211,7 +212,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
// Act
var query = Query<Relation>.Builder.Where(x => x.ParentId == 1046);
var query = Query<Relation>.Builder.Where(x => x.ParentId == NodeDto.NodeIdSeed + 1);
int count = repository.Count(query);
// Assert
@@ -251,7 +252,7 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = CreateRepository(unitOfWork, out repositoryType))
{
var content = ServiceContext.ContentService.GetById(1047);
var content = ServiceContext.ContentService.GetById(NodeDto.NodeIdSeed + 2);
ServiceContext.ContentService.Delete(content, 0);
// Act
@@ -284,19 +285,19 @@ namespace Umbraco.Tests.Persistence.Repositories
relationTypeRepository.AddOrUpdate(relateContentType);
unitOfWork.Commit();
//Create and Save ContentType "umbTextpage" -> 1045
//Create and Save ContentType "umbTextpage" -> NodeDto.NodeIdSeed
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
ServiceContext.ContentTypeService.Save(contentType);
//Create and Save Content "Homepage" based on "umbTextpage" -> 1046
//Create and Save Content "Homepage" based on "umbTextpage" -> NodeDto.NodeIdSeed + 1
Content textpage = MockedContent.CreateSimpleContent(contentType);
ServiceContext.ContentService.Save(textpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1047
//Create and Save Content "Text Page 1" based on "umbTextpage" -> NodeDto.NodeIdSeed + 2
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
ServiceContext.ContentService.Save(subpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1048
//Create and Save Content "Text Page 1" based on "umbTextpage" -> NodeDto.NodeIdSeed + 3
Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id);
ServiceContext.ContentService.Save(subpage2, 0);

View File

@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
@@ -25,7 +26,7 @@ namespace Umbraco.Tests.Services
public void Creating_100_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 100);
// Act
@@ -44,7 +45,7 @@ namespace Umbraco.Tests.Services
public void Creating_1000_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 1000);
// Act
@@ -63,7 +64,7 @@ namespace Umbraco.Tests.Services
public void Getting_100_Uncached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 100);
ServiceContext.ContentService.Save(pages, 0);
@@ -88,7 +89,7 @@ namespace Umbraco.Tests.Services
public void Getting_1000_Uncached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 1000);
ServiceContext.ContentService.Save(pages, 0);
@@ -113,7 +114,7 @@ namespace Umbraco.Tests.Services
public void Getting_100_Cached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 100);
ServiceContext.ContentService.Save(pages, 0);
@@ -141,7 +142,7 @@ namespace Umbraco.Tests.Services
public void Getting_1000_Cached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 1000);
ServiceContext.ContentService.Save(pages, 0);
@@ -173,7 +174,7 @@ namespace Umbraco.Tests.Services
public void CreateTestData()
{
//Create and Save ContentType "textpage" -> 1045
//Create and Save ContentType "textpage" -> NodeDto.NodeIdSeed
ContentType contentType = MockedContentTypes.CreateTextpageContentType();
ServiceContext.ContentTypeService.Save(contentType);
}

View File

@@ -461,7 +461,7 @@ namespace Umbraco.Tests.Services
contentService.Save(content);
var parent = contentService.GetById(NodeDto.NodeIdSeed + 1);
bool parentPublished = contentService.Publish(parent, 0);//Publish root Home node to enable publishing of '1048'
bool parentPublished = contentService.Publish(parent, 0);//Publish root Home node to enable publishing of 'NodeDto.NodeIdSeed + 3'
// Act
bool published = contentService.Publish(content, 0);
@@ -482,7 +482,7 @@ namespace Umbraco.Tests.Services
contentService.Save(content, 0);
var parent = contentService.GetById(NodeDto.NodeIdSeed + 1);
bool parentPublished = contentService.Publish(parent, 0);//Publish root Home node to enable publishing of '1048'
bool parentPublished = contentService.Publish(parent, 0);//Publish root Home node to enable publishing of 'NodeDto.NodeIdSeed + 3'
// Act
bool published = contentService.Publish(content, 0);

View File

@@ -2,6 +2,7 @@
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
namespace Umbraco.Tests.Services
{
@@ -58,7 +59,7 @@ namespace Umbraco.Tests.Services
Assert.That(deletedDefinition, Is.Null);
//Further assertions against the ContentType that contains PropertyTypes based on the TextField
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var contentType = ServiceContext.ContentTypeService.GetContentType(NodeDto.NodeIdSeed);
Assert.That(contentType.Alias, Is.EqualTo("umbTextpage"));
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(1));
}