2012-11-05 09:03:48 -01:00
|
|
|
|
using System;
|
2013-07-08 17:29:26 +10:00
|
|
|
|
using System.Collections.Generic;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using System.Globalization;
|
2012-11-05 09:03:48 -01:00
|
|
|
|
using System.Linq;
|
2017-09-19 15:51:47 +02:00
|
|
|
|
using System.Web;
|
2015-01-09 10:51:15 +11:00
|
|
|
|
using Moq;
|
2012-11-05 09:03:48 -01:00
|
|
|
|
using NUnit.Framework;
|
2014-01-28 10:46:59 +11:00
|
|
|
|
using Umbraco.Core;
|
2017-09-19 15:51:47 +02:00
|
|
|
|
using Umbraco.Core.Cache;
|
2015-01-09 10:51:15 +11:00
|
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
2012-10-30 20:01:09 -01:00
|
|
|
|
using Umbraco.Core.Models;
|
2013-07-08 17:29:26 +10:00
|
|
|
|
using Umbraco.Core.Models.Rdbms;
|
2012-10-30 20:01:09 -01:00
|
|
|
|
using Umbraco.Core.Persistence;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
|
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
|
|
|
|
|
using Umbraco.Tests.TestHelpers;
|
|
|
|
|
|
using Umbraco.Tests.TestHelpers.Entities;
|
2014-08-14 00:16:37 +02:00
|
|
|
|
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
2016-04-12 15:11:07 +02:00
|
|
|
|
using Umbraco.Core.Persistence.SqlSyntax;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using Umbraco.Core.Scoping;
|
2016-12-16 10:40:14 +01:00
|
|
|
|
using Umbraco.Tests.Testing;
|
2012-10-30 20:01:09 -01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Persistence.Repositories
|
|
|
|
|
|
{
|
2013-07-03 16:40:22 +10:00
|
|
|
|
[TestFixture]
|
2016-11-05 19:23:55 +01:00
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
2016-10-13 21:08:07 +02:00
|
|
|
|
public class ContentRepositoryTest : TestWithDatabaseBase
|
2012-10-30 20:01:09 -01:00
|
|
|
|
{
|
2016-10-13 21:08:07 +02:00
|
|
|
|
public override void SetUp()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
2016-10-13 21:08:07 +02:00
|
|
|
|
base.SetUp();
|
2012-11-05 09:03:48 -01:00
|
|
|
|
|
|
|
|
|
|
CreateTestData();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
VersionableRepositoryBase.ThrowOnWarning = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void TearDown()
|
|
|
|
|
|
{
|
|
|
|
|
|
VersionableRepositoryBase.ThrowOnWarning = false;
|
|
|
|
|
|
|
|
|
|
|
|
base.TearDown();
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-19 15:51:47 +02:00
|
|
|
|
private ContentRepository CreateRepository(IScopeUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository, out DataTypeDefinitionRepository dtdRepository, CacheHelper cacheHelper = null)
|
2016-06-27 15:21:21 +02:00
|
|
|
|
{
|
2017-09-19 15:51:47 +02:00
|
|
|
|
cacheHelper = cacheHelper ?? CacheHelper;
|
|
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
TemplateRepository tr;
|
|
|
|
|
|
var ctRepository = CreateRepository(unitOfWork, out contentTypeRepository, out tr);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
dtdRepository = new DataTypeDefinitionRepository(unitOfWork, cacheHelper, Logger, contentTypeRepository);
|
2016-06-27 15:21:21 +02:00
|
|
|
|
return ctRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-19 15:51:47 +02:00
|
|
|
|
private ContentRepository CreateRepository(IScopeUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository, CacheHelper cacheHelper = null)
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2015-08-05 16:30:21 +02:00
|
|
|
|
TemplateRepository tr;
|
2017-09-19 15:51:47 +02:00
|
|
|
|
return CreateRepository(unitOfWork, out contentTypeRepository, out tr, cacheHelper);
|
2015-08-05 16:30:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-19 15:51:47 +02:00
|
|
|
|
private ContentRepository CreateRepository(IScopeUnitOfWork unitOfWork, out ContentTypeRepository contentTypeRepository, out TemplateRepository templateRepository, CacheHelper cacheHelper = null)
|
2015-08-05 16:30:21 +02:00
|
|
|
|
{
|
2017-09-19 15:51:47 +02:00
|
|
|
|
cacheHelper = cacheHelper ?? CacheHelper;
|
|
|
|
|
|
|
|
|
|
|
|
templateRepository = new TemplateRepository(unitOfWork, cacheHelper, Logger, Mock.Of<IFileSystem>(), Mock.Of<IFileSystem>(), Mock.Of<ITemplatesSection>());
|
|
|
|
|
|
var tagRepository = new TagRepository(unitOfWork, cacheHelper, Logger);
|
|
|
|
|
|
contentTypeRepository = new ContentTypeRepository(unitOfWork, cacheHelper, Logger, templateRepository);
|
|
|
|
|
|
var repository = new ContentRepository(unitOfWork, cacheHelper, Logger, contentTypeRepository, templateRepository, tagRepository, Mock.Of<IContentSection>());
|
2013-09-18 11:40:40 +10:00
|
|
|
|
return repository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-19 15:51:47 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Cache_Active_By_Int_And_Guid()
|
|
|
|
|
|
{
|
|
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
|
|
|
|
|
|
var realCache = new CacheHelper(
|
|
|
|
|
|
new ObjectCacheRuntimeCacheProvider(),
|
|
|
|
|
|
new StaticCacheProvider(),
|
|
|
|
|
|
new StaticCacheProvider(),
|
|
|
|
|
|
new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()));
|
|
|
|
|
|
|
|
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
|
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository, cacheHelper: realCache);
|
|
|
|
|
|
|
2017-09-22 15:23:46 +02:00
|
|
|
|
var udb = (UmbracoDatabase) unitOfWork.Database;
|
2017-09-19 15:51:47 +02:00
|
|
|
|
|
|
|
|
|
|
udb.EnableSqlCount = false;
|
|
|
|
|
|
|
|
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
|
|
|
|
|
var content = MockedContent.CreateSimpleContent(contentType);
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
|
|
|
|
|
repository.AddOrUpdate(content);
|
|
|
|
|
|
unitOfWork.Complete();
|
|
|
|
|
|
|
|
|
|
|
|
udb.EnableSqlCount = true;
|
|
|
|
|
|
|
|
|
|
|
|
//go get it, this should already be cached since the default repository key is the INT
|
|
|
|
|
|
var found = repository.Get(content.Id);
|
|
|
|
|
|
Assert.AreEqual(0, udb.SqlCount);
|
|
|
|
|
|
//retrieve again, this should use cache
|
|
|
|
|
|
found = repository.Get(content.Id);
|
|
|
|
|
|
Assert.AreEqual(0, udb.SqlCount);
|
|
|
|
|
|
|
|
|
|
|
|
//reset counter
|
|
|
|
|
|
udb.EnableSqlCount = false;
|
|
|
|
|
|
udb.EnableSqlCount = true;
|
|
|
|
|
|
|
|
|
|
|
|
//now get by GUID, this won't be cached yet because the default repo key is not a GUID
|
|
|
|
|
|
found = repository.Get(content.Key);
|
|
|
|
|
|
var sqlCount = udb.SqlCount;
|
|
|
|
|
|
Assert.Greater(sqlCount, 0);
|
|
|
|
|
|
//retrieve again, this should use cache now
|
|
|
|
|
|
found = repository.Get(content.Key);
|
|
|
|
|
|
Assert.AreEqual(sqlCount, udb.SqlCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Get_Always_Returns_Latest_Version()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
|
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out ContentTypeRepository contentTypeRepository, out DataTypeDefinitionRepository dataTypeDefinitionRepository);
|
|
|
|
|
|
|
|
|
|
|
|
IContent content1;
|
|
|
|
|
|
var versions = new List<Guid>();
|
|
|
|
|
|
var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
|
|
|
|
|
content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
|
|
|
|
|
|
|
|
|
|
|
//save version
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(hasPropertiesContentType);
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
2017-06-23 18:54:42 +02:00
|
|
|
|
versions.Add(content1.Version); // the first version
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
//publish version
|
2017-06-23 18:54:42 +02:00
|
|
|
|
content1.ChangePublishedState(PublishedState.Publishing);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
2017-06-23 18:54:42 +02:00
|
|
|
|
versions.Add(content1.Version); // the first version got published, same id
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
//change something and make a pending version
|
|
|
|
|
|
content1.Name = "new name";
|
2017-06-23 18:54:42 +02:00
|
|
|
|
if (content1.Published)
|
|
|
|
|
|
content1.ChangePublishedState(PublishedState.Saving);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
2017-06-23 18:54:42 +02:00
|
|
|
|
versions.Add(content1.Version); // the second version
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-06-23 18:54:42 +02:00
|
|
|
|
Assert.AreEqual(2, versions.Distinct().Count());
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
var content = repository.GetByQuery(unitOfWork.Query<IContent>().Where(c => c.Id == content1.Id)).ToArray()[0];
|
|
|
|
|
|
Assert.AreEqual(versions[2], content.Version);
|
|
|
|
|
|
|
|
|
|
|
|
content = repository.Get(content1.Id);
|
|
|
|
|
|
Assert.AreEqual(versions[2], content.Version);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var version in versions)
|
|
|
|
|
|
{
|
|
|
|
|
|
content = repository.GetByVersion(version);
|
|
|
|
|
|
Assert.IsNotNull(content);
|
|
|
|
|
|
Assert.AreEqual(version, content.Version);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Deal_With_Corrupt_Duplicate_Newest_Published_Flags()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
|
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out ContentTypeRepository contentTypeRepository, out DataTypeDefinitionRepository dataTypeDefinitionRepository);
|
|
|
|
|
|
|
|
|
|
|
|
var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
2017-09-22 15:23:46 +02:00
|
|
|
|
IContent content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(hasPropertiesContentType);
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
|
|
|
|
|
|
var versionDtos = new List<ContentVersionDto>();
|
|
|
|
|
|
|
|
|
|
|
|
//Now manually corrupt the data
|
|
|
|
|
|
var versions = new[] { Guid.NewGuid(), Guid.NewGuid() };
|
|
|
|
|
|
for (var index = 0; index < versions.Length; index++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var version = versions[index];
|
|
|
|
|
|
var versionDate = DateTime.Now.AddMinutes(index);
|
|
|
|
|
|
var versionDto = new ContentVersionDto
|
|
|
|
|
|
{
|
|
|
|
|
|
NodeId = content1.Id,
|
|
|
|
|
|
VersionDate = versionDate,
|
|
|
|
|
|
VersionId = version
|
|
|
|
|
|
};
|
|
|
|
|
|
unitOfWork.Database.Insert(versionDto);
|
|
|
|
|
|
versionDtos.Add(versionDto);
|
|
|
|
|
|
unitOfWork.Database.Insert(new DocumentDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Newest = true,
|
|
|
|
|
|
NodeId = content1.Id,
|
|
|
|
|
|
Published = true,
|
|
|
|
|
|
Text = content1.Name,
|
|
|
|
|
|
VersionId = version,
|
|
|
|
|
|
WriterUserId = 0,
|
|
|
|
|
|
UpdateDate = versionDate,
|
|
|
|
|
|
TemplateId = content1.Template == null || content1.Template.Id <= 0 ? null : (int?)content1.Template.Id
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var content = repository.GetByQuery(unitOfWork.Query<IContent>().Where(c => c.Id == content1.Id)).ToArray();
|
|
|
|
|
|
Assert.AreEqual(1, content.Length);
|
|
|
|
|
|
Assert.AreEqual(content[0].Version, versionDtos.Single(x => x.Id == versionDtos.Max(y => y.Id)).VersionId);
|
|
|
|
|
|
Assert.AreEqual(content[0].UpdateDate.ToString(CultureInfo.InvariantCulture), versionDtos.Single(x => x.Id == versionDtos.Max(y => y.Id)).VersionDate.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
|
|
|
|
|
|
|
var contentItem = repository.GetByVersion(content1.Version);
|
|
|
|
|
|
Assert.IsNotNull(contentItem);
|
|
|
|
|
|
|
|
|
|
|
|
contentItem = repository.Get(content1.Id);
|
|
|
|
|
|
Assert.IsNotNull(contentItem);
|
|
|
|
|
|
Assert.AreEqual(contentItem.UpdateDate.ToString(CultureInfo.InvariantCulture), versionDtos.Single(x => x.Id == versionDtos.Max(y => y.Id)).VersionDate.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
|
Assert.AreEqual(contentItem.Version, versionDtos.Single(x => x.Id == versionDtos.Max(y => y.Id)).VersionId);
|
|
|
|
|
|
|
|
|
|
|
|
var allVersions = repository.GetAllVersions(content[0].Id);
|
|
|
|
|
|
var allKnownVersions = versionDtos.Select(x => x.VersionId).Union(new[] { content1.Version }).ToArray();
|
|
|
|
|
|
Assert.IsTrue(allKnownVersions.ContainsAll(allVersions.Select(x => x.Version)));
|
|
|
|
|
|
Assert.IsTrue(allVersions.Select(x => x.Version).ContainsAll(allKnownVersions));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This tests the regression issue of U4-9438
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// The problem was the iteration of the property data in VersionableRepositoryBase when a content item
|
|
|
|
|
|
/// in the list actually doesn't have any property types, it would still skip over a property row.
|
|
|
|
|
|
/// To test, we have 3 content items, the first has properties, the second doesn't and the third does.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Property_Data_Assigned_Correctly()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
|
|
|
|
|
var allContent = new List<IContent>();
|
|
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out ContentTypeRepository contentTypeRepository, out DataTypeDefinitionRepository dataTypeDefinitionRepository);
|
|
|
|
|
|
|
|
|
|
|
|
var emptyContentType = MockedContentTypes.CreateBasicContentType();
|
|
|
|
|
|
var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
|
|
|
|
|
var content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
|
|
|
|
|
var content2 = MockedContent.CreateBasicContent(emptyContentType);
|
|
|
|
|
|
var content3 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(emptyContentType);
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(hasPropertiesContentType);
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
repository.AddOrUpdate(content2);
|
|
|
|
|
|
repository.AddOrUpdate(content3);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
|
|
|
|
|
|
allContent.Add(content1);
|
|
|
|
|
|
allContent.Add(content2);
|
|
|
|
|
|
allContent.Add(content3);
|
|
|
|
|
|
|
|
|
|
|
|
//this will cause the GetPropertyCollection to execute and we need to ensure that
|
|
|
|
|
|
// all of the properties and property types are all correct
|
|
|
|
|
|
var result = repository.GetAll(allContent.Select(x => x.Id).ToArray()).ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var content in result)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var contentProperty in content.Properties)
|
|
|
|
|
|
{
|
|
|
|
|
|
//prior to the fix, the 2nd document iteration in the GetPropertyCollection would have caused
|
|
|
|
|
|
//the enumerator to move forward past the first property of the 3rd document which would have
|
|
|
|
|
|
//ended up not assiging a property to the 3rd document. This would have ended up with the 3rd
|
|
|
|
|
|
//document still having 3 properties but the last one would not have been assigned an identity
|
|
|
|
|
|
//because the property data would not have been assigned.
|
|
|
|
|
|
Assert.IsTrue(contentProperty.HasIdentity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This test ensures that when property values using special database fields are saved, the actual data in the
|
|
|
|
|
|
/// object being stored is also transformed in the same way as the data being stored in the database is.
|
2016-11-02 12:39:41 +01:00
|
|
|
|
/// Before you would see that ex: a decimal value being saved as 100 or "100", would be that exact value in the
|
2016-06-27 15:21:21 +02:00
|
|
|
|
/// object, but the value saved to the database was actually 100.000000.
|
2016-11-02 12:39:41 +01:00
|
|
|
|
/// When querying the database for the value again - the value would then differ from what is in the object.
|
|
|
|
|
|
/// This caused inconsistencies between saving+publishing and simply saving and then publishing, due to the former
|
2016-06-27 15:21:21 +02:00
|
|
|
|
/// sending the non-transformed data directly on to publishing.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Property_Values_With_Special_DatabaseTypes_Are_Equal_Before_And_After_Being_Persisted()
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-07-08 17:58:01 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2016-06-27 15:21:21 +02:00
|
|
|
|
{
|
2016-07-08 17:58:01 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
DataTypeDefinitionRepository dataTypeDefinitionRepository;
|
|
|
|
|
|
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository, out dataTypeDefinitionRepository);
|
|
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
// Setup
|
|
|
|
|
|
var dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.DecimalAlias) { Name = "test", DatabaseType = DataTypeDatabaseType.Decimal };
|
|
|
|
|
|
dataTypeDefinitionRepository.AddOrUpdate(dtd);
|
2016-07-08 17:58:01 +02:00
|
|
|
|
unitOfWork.Complete();
|
2016-06-27 15:21:21 +02:00
|
|
|
|
|
|
|
|
|
|
const string decimalPropertyAlias = "decimalProperty";
|
|
|
|
|
|
const string intPropertyAlias = "intProperty";
|
|
|
|
|
|
const string dateTimePropertyAlias = "datetimeProperty";
|
|
|
|
|
|
var dateValue = new DateTime(2016, 1, 6);
|
|
|
|
|
|
|
|
|
|
|
|
var propertyTypeCollection = new PropertyTypeCollection(
|
|
|
|
|
|
new List<PropertyType>
|
|
|
|
|
|
{
|
|
|
|
|
|
MockedPropertyTypes.CreateDecimalProperty(decimalPropertyAlias, "Decimal property", dtd.Id),
|
|
|
|
|
|
MockedPropertyTypes.CreateIntegerProperty(intPropertyAlias, "Integer property"),
|
|
|
|
|
|
MockedPropertyTypes.CreateDateTimeProperty(dateTimePropertyAlias, "DateTime property")
|
|
|
|
|
|
});
|
|
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage", propertyTypeCollection);
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
2016-07-08 17:58:01 +02:00
|
|
|
|
unitOfWork.Complete();
|
2016-11-02 12:39:41 +01:00
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
// Int and decimal values are passed in as strings as they would be from the backoffice UI
|
|
|
|
|
|
var textpage = MockedContent.CreateSimpleContentWithSpecialDatabaseTypes(contentType, "test@umbraco.org", -1, "100", "150", dateValue);
|
2016-11-02 12:39:41 +01:00
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
// Act
|
|
|
|
|
|
repository.AddOrUpdate(textpage);
|
2016-07-08 17:58:01 +02:00
|
|
|
|
unitOfWork.Complete();
|
2016-06-27 15:21:21 +02:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(contentType.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(textpage.HasIdentity, Is.True);
|
2016-11-02 12:39:41 +01:00
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
var persistedTextpage = repository.Get(textpage.Id);
|
|
|
|
|
|
Assert.That(persistedTextpage.Name, Is.EqualTo(textpage.Name));
|
|
|
|
|
|
Assert.AreEqual(100m, persistedTextpage.GetValue(decimalPropertyAlias));
|
|
|
|
|
|
Assert.AreEqual(persistedTextpage.GetValue(decimalPropertyAlias), textpage.GetValue(decimalPropertyAlias));
|
|
|
|
|
|
Assert.AreEqual(150, persistedTextpage.GetValue(intPropertyAlias));
|
|
|
|
|
|
Assert.AreEqual(persistedTextpage.GetValue(intPropertyAlias), textpage.GetValue(intPropertyAlias));
|
|
|
|
|
|
Assert.AreEqual(dateValue, persistedTextpage.GetValue(dateTimePropertyAlias));
|
|
|
|
|
|
Assert.AreEqual(persistedTextpage.GetValue(dateTimePropertyAlias), textpage.GetValue(dateTimePropertyAlias));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-07-08 17:29:26 +10:00
|
|
|
|
[Test]
|
2012-10-30 20:01:09 -01:00
|
|
|
|
public void Can_Perform_Add_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-03-11 15:02:23 +11:00
|
|
|
|
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
|
2016-06-07 12:20:10 +02:00
|
|
|
|
IContent textpage = MockedContent.CreateSimpleContent(contentType);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
|
|
|
|
|
repository.AddOrUpdate(textpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Complete();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(contentType.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(textpage.HasIdentity, Is.True);
|
2015-08-05 16:30:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Add_With_Default_Template()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2015-08-05 16:30:21 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
TemplateRepository templateRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository, out templateRepository);
|
|
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
var template = new Template("hello", "hello");
|
|
|
|
|
|
templateRepository.AddOrUpdate(template);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2015-08-05 16:30:21 +02:00
|
|
|
|
|
2015-11-11 16:05:11 +01:00
|
|
|
|
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
|
|
|
|
|
|
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>(); // because CreateSimple... assigns one
|
2015-08-05 16:30:21 +02:00
|
|
|
|
contentType.SetDefaultTemplate(template);
|
|
|
|
|
|
Content textpage = MockedContent.CreateSimpleContent(contentType);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
2016-02-26 14:30:32 +00:00
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
|
|
|
|
|
repository.AddOrUpdate(textpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2015-08-05 16:30:21 +02:00
|
|
|
|
|
2016-06-07 12:20:10 +02:00
|
|
|
|
var fetched = repository.Get(textpage.Id);
|
|
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(textpage.Template, Is.Not.Null);
|
|
|
|
|
|
Assert.That(textpage.Template, Is.EqualTo(contentType.DefaultTemplate));
|
2016-05-02 12:12:21 +02:00
|
|
|
|
|
|
|
|
|
|
unitOfWork.Complete();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2016-06-07 12:20:10 +02:00
|
|
|
|
TestHelper.AssertAllPropertyValuesAreEquals(textpage, fetched, "yyyy-MM-dd HH:mm:ss");
|
2013-09-18 11:40:40 +10:00
|
|
|
|
}
|
2012-10-30 20:01:09 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-05 10:44:28 +02:00
|
|
|
|
//Covers issue U4-2791 and U4-2607
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Save_Content_With_AtSign_In_Name_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-03-11 15:02:23 +11:00
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
2013-09-18 12:42:18 +10:00
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 12:42:18 +10:00
|
|
|
|
|
|
|
|
|
|
var textpage = MockedContent.CreateSimpleContent(contentType, "test@umbraco.org", -1);
|
|
|
|
|
|
var anotherTextpage = MockedContent.CreateSimpleContent(contentType, "@lightgiants", -1);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Act
|
2014-01-08 15:43:58 +11:00
|
|
|
|
|
2013-09-18 11:40:40 +10:00
|
|
|
|
repository.AddOrUpdate(textpage);
|
|
|
|
|
|
repository.AddOrUpdate(anotherTextpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(contentType.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(textpage.HasIdentity, Is.True);
|
|
|
|
|
|
|
|
|
|
|
|
var content = repository.Get(textpage.Id);
|
|
|
|
|
|
Assert.That(content.Name, Is.EqualTo(textpage.Name));
|
|
|
|
|
|
|
|
|
|
|
|
var content2 = repository.Get(anotherTextpage.Id);
|
|
|
|
|
|
Assert.That(content2.Name, Is.EqualTo(anotherTextpage.Name));
|
2016-05-02 12:12:21 +02:00
|
|
|
|
|
|
|
|
|
|
unitOfWork.Complete();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
}
|
2013-09-05 10:44:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-30 20:01:09 -01:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Multiple_Adds_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-03-11 15:02:23 +11:00
|
|
|
|
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
2013-09-18 11:40:40 +10:00
|
|
|
|
Content textpage = MockedContent.CreateSimpleContent(contentType);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
|
|
|
|
|
repository.AddOrUpdate(textpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
|
|
|
|
|
|
repository.AddOrUpdate(subpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(contentType.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(textpage.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(subpage.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(textpage.Id, Is.EqualTo(subpage.ParentId));
|
|
|
|
|
|
}
|
2014-01-08 15:43:58 +11:00
|
|
|
|
|
2012-10-30 20:01:09 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Verify_Fresh_Entity_Is_Not_Dirty()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var content = repository.Get(NodeDto.NodeIdSeed + 3);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
bool dirty = ((Content)content).IsDirty();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(dirty, Is.False);
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Update_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var content = repository.Get(NodeDto.NodeIdSeed + 2);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
content.Name = "About 2";
|
|
|
|
|
|
repository.AddOrUpdate(content);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(updatedContent.Id, Is.EqualTo(content.Id));
|
|
|
|
|
|
Assert.That(updatedContent.Name, Is.EqualTo(content.Name));
|
|
|
|
|
|
}
|
2014-01-08 15:43:58 +11:00
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Update_With_Null_Template()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2015-08-05 16:30:21 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2015-08-05 16:30:21 +02:00
|
|
|
|
// Act
|
|
|
|
|
|
var content = repository.Get(NodeDto.NodeIdSeed + 2);
|
|
|
|
|
|
content.Template = null;
|
|
|
|
|
|
repository.AddOrUpdate(content);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2015-08-05 16:30:21 +02:00
|
|
|
|
var updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(updatedContent.Template, Is.Null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Delete_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var contentType = contentTypeRepository.Get(NodeDto.NodeIdSeed);
|
|
|
|
|
|
var content = new Content("Textpage 2 Child Node", NodeDto.NodeIdSeed + 3, contentType);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
content.CreatorId = 0;
|
|
|
|
|
|
content.WriterId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
repository.AddOrUpdate(content);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var id = content.Id;
|
|
|
|
|
|
|
2015-01-13 18:19:52 +11:00
|
|
|
|
repository.Delete(content);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
2015-01-13 18:19:52 +11:00
|
|
|
|
var content1 = repository.Get(id);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(content1, Is.Null);
|
2014-01-08 15:43:58 +11:00
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Get_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var content = repository.Get(NodeDto.NodeIdSeed + 3);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
2013-11-19 15:36:30 +11:00
|
|
|
|
Assert.That(content.Id, Is.EqualTo(NodeDto.NodeIdSeed + 3));
|
2013-09-18 11:40:40 +10:00
|
|
|
|
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"));
|
2015-06-18 15:30:55 +02:00
|
|
|
|
//Assert.That(content.SortOrder, Is.EqualTo(1));
|
2013-09-18 11:40:40 +10:00
|
|
|
|
Assert.That(content.Version, Is.Not.EqualTo(Guid.Empty));
|
2013-11-19 15:36:30 +11:00
|
|
|
|
Assert.That(content.ContentTypeId, Is.EqualTo(NodeDto.NodeIdSeed));
|
2013-09-18 11:40:40 +10:00
|
|
|
|
Assert.That(content.Path, Is.Not.Empty);
|
|
|
|
|
|
Assert.That(content.Properties.Any(), Is.True);
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetByQuery_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var result = repository.GetByQuery(query);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(result.Count(), Is.GreaterThanOrEqualTo(2));
|
2014-01-08 15:43:58 +11:00
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-11 16:04:16 +10:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Get_All_With_Many_Version()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2016-02-26 14:30:32 +00:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-09-11 16:04:16 +10:00
|
|
|
|
var result = repository.GetAll().ToArray();
|
|
|
|
|
|
foreach (var content in result)
|
|
|
|
|
|
{
|
2016-05-18 10:55:19 +02:00
|
|
|
|
content.ChangePublishedState(PublishedState.Saving);
|
2014-09-11 16:04:16 +10:00
|
|
|
|
repository.AddOrUpdate(content);
|
|
|
|
|
|
}
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2014-09-11 16:04:16 +10:00
|
|
|
|
foreach (var content in result)
|
|
|
|
|
|
{
|
2016-05-18 10:55:19 +02:00
|
|
|
|
content.ChangePublishedState(PublishedState.Publishing);
|
2014-09-11 16:04:16 +10:00
|
|
|
|
repository.AddOrUpdate(content);
|
|
|
|
|
|
}
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2014-09-11 16:04:16 +10:00
|
|
|
|
|
|
|
|
|
|
//re-get
|
|
|
|
|
|
|
|
|
|
|
|
var result2 = repository.GetAll().ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(result.Count(), result2.Count());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-12 15:11:07 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void RegexAliasTest()
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var regex = VersionableRepositoryBaseAliasRegex.For(new SqlServerSyntaxProvider(new Lazy<IScopeProvider>(() => null)));
|
2016-04-12 15:11:07 +02:00
|
|
|
|
Assert.AreEqual(@"(\[\w+]\.\[\w+])\s+AS\s+(\[\w+])", regex.ToString());
|
|
|
|
|
|
const string sql = "SELECT [table].[column1] AS [alias1], [table].[column2] AS [alias2] FROM [table];";
|
|
|
|
|
|
var matches = regex.Matches(sql);
|
|
|
|
|
|
Assert.AreEqual(2, matches.Count);
|
|
|
|
|
|
Assert.AreEqual("[table].[column1]", matches[0].Groups[1].Value);
|
|
|
|
|
|
Assert.AreEqual("[alias1]", matches[0].Groups[2].Value);
|
|
|
|
|
|
Assert.AreEqual("[table].[column2]", matches[1].Groups[1].Value);
|
|
|
|
|
|
Assert.AreEqual("[alias2]", matches[1].Groups[2].Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-20 12:50:52 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_Sorting_On_Custom_Property()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2016-04-20 12:50:52 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2016-04-20 12:50:52 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Name.Contains("Text"));
|
2016-04-20 12:50:52 +02:00
|
|
|
|
long totalRecords;
|
2016-04-29 10:53:19 +02:00
|
|
|
|
|
2016-04-20 12:50:52 +02:00
|
|
|
|
try
|
2016-04-29 10:53:19 +02:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlTrace = true;
|
|
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlCount = true;
|
2016-04-20 12:50:52 +02:00
|
|
|
|
|
|
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 2, out totalRecords, "title", Direction.Ascending, false);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(3, totalRecords);
|
|
|
|
|
|
Assert.AreEqual(2, result.Count());
|
|
|
|
|
|
|
|
|
|
|
|
result = repository.GetPagedResultsByQuery(query, 1, 2, out totalRecords, "title", Direction.Ascending, false);
|
2016-04-29 10:53:19 +02:00
|
|
|
|
|
2016-04-20 12:50:52 +02:00
|
|
|
|
Assert.AreEqual(1, result.Count());
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
2016-04-29 10:53:19 +02:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlTrace = false;
|
|
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlCount = false;
|
2016-04-29 10:53:19 +02:00
|
|
|
|
}
|
2016-04-20 12:50:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-14 00:16:37 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_ForFirstPage_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2015-05-04 11:58:00 +10:00
|
|
|
|
long totalRecords;
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
2016-04-20 12:50:52 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlTrace = true;
|
|
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlCount = true;
|
2016-04-20 12:50:52 +02:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out totalRecords, "Name", Direction.Ascending, true);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 1"));
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlTrace = false;
|
|
|
|
|
|
unitOfWork.Database.AsUmbracoDatabase().EnableSqlCount = false;
|
2016-04-20 12:50:52 +02:00
|
|
|
|
}
|
2014-08-14 00:16:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_ForSecondPage_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2015-05-04 11:58:00 +10:00
|
|
|
|
long totalRecords;
|
2014-12-13 22:00:32 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 1, 1, out totalRecords, "Name", Direction.Ascending, true);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 2"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-14 08:42:36 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_WithSinglePage_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2014-08-14 08:42:36 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-08-14 08:42:36 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2015-05-04 11:58:00 +10:00
|
|
|
|
long totalRecords;
|
2014-12-13 22:00:32 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 2, out totalRecords, "Name", Direction.Ascending, true);
|
2014-08-14 08:42:36 +02:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(2));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 1"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-14 00:16:37 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_WithDescendingOrder_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2015-05-04 11:58:00 +10:00
|
|
|
|
long totalRecords;
|
2014-12-13 22:00:32 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out totalRecords, "Name", Direction.Descending, true);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 2"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2014-08-14 08:42:36 +02:00
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_WithFilterMatchingSome_On_ContentRepository()
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2016-11-02 12:39:41 +01:00
|
|
|
|
|
2015-05-04 11:58:00 +10:00
|
|
|
|
long totalRecords;
|
2016-05-02 15:38:45 +02:00
|
|
|
|
|
2016-12-16 14:18:37 +01:00
|
|
|
|
var filterQuery = unitOfWork.Query<IContent>().Where(x => x.Name.Contains("Page 2"));
|
2016-05-26 15:30:40 +02:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out totalRecords, "Name", Direction.Ascending, true, filterQuery);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(totalRecords, Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 2"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-08-14 08:42:36 +02:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetPagedResultsByQuery_WithFilterMatchingAll_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2014-08-14 08:42:36 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2014-08-14 08:42:36 +02:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == 2);
|
2016-05-26 15:30:40 +02:00
|
|
|
|
|
2015-05-04 11:58:00 +10:00
|
|
|
|
long totalRecords;
|
2016-05-02 15:38:45 +02:00
|
|
|
|
|
2016-12-16 14:18:37 +01:00
|
|
|
|
var filterQuery = unitOfWork.Query<IContent>().Where(x => x.Name.Contains("text"));
|
2016-05-26 15:30:40 +02:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out totalRecords, "Name", Direction.Ascending, true, filterQuery);
|
2014-08-14 08:42:36 +02:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(totalRecords, Is.EqualTo(2));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 1"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetAll_By_Param_Ids_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var contents = repository.GetAll(NodeDto.NodeIdSeed + 2, NodeDto.NodeIdSeed + 3);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(contents, Is.Not.Null);
|
|
|
|
|
|
Assert.That(contents.Any(), Is.True);
|
|
|
|
|
|
Assert.That(contents.Count(), Is.EqualTo(2));
|
2014-01-08 15:43:58 +11:00
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_GetAll_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
|
|
|
|
|
var contents = repository.GetAll();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(contents, Is.Not.Null);
|
|
|
|
|
|
Assert.That(contents.Any(), Is.True);
|
|
|
|
|
|
Assert.That(contents.Count(), Is.GreaterThanOrEqualTo(4));
|
2017-09-19 15:51:47 +02:00
|
|
|
|
|
|
|
|
|
|
contents = repository.GetAll(contents.Select(x => x.Id).ToArray());
|
|
|
|
|
|
Assert.That(contents, Is.Not.Null);
|
|
|
|
|
|
Assert.That(contents.Any(), Is.True);
|
|
|
|
|
|
Assert.That(contents.Count(), Is.GreaterThanOrEqualTo(4));
|
|
|
|
|
|
|
|
|
|
|
|
contents = ((IReadRepository<Guid, IContent>)repository).GetAll(contents.Select(x => x.Key).ToArray());
|
|
|
|
|
|
Assert.That(contents, Is.Not.Null);
|
|
|
|
|
|
Assert.That(contents.Any(), Is.True);
|
|
|
|
|
|
Assert.That(contents.Count(), Is.GreaterThanOrEqualTo(4));
|
2013-09-18 11:40:40 +10:00
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
|
2014-01-08 15:43:58 +11:00
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Exists_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var exists = repository.Exists(NodeDto.NodeIdSeed + 1);
|
2012-11-05 09:03:48 -01:00
|
|
|
|
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(exists, Is.True);
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
|
2014-01-08 15:43:58 +11:00
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Perform_Count_On_ContentRepository()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
|
|
|
|
|
int level = 2;
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Level == level);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var result = repository.Count(query);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(result, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-13 19:07:43 -01:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Verify_Keys_Set()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var textpage = repository.Get(NodeDto.NodeIdSeed + 1);
|
|
|
|
|
|
var subpage = repository.Get(NodeDto.NodeIdSeed + 2);
|
|
|
|
|
|
var trashed = repository.Get(NodeDto.NodeIdSeed + 4);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(textpage.Key.ToString().ToUpper(), Is.EqualTo("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"));
|
|
|
|
|
|
Assert.That(subpage.Key.ToString().ToUpper(), Is.EqualTo("FF11402B-7E53-4654-81A7-462AC2108059"));
|
|
|
|
|
|
Assert.That(trashed.Key, Is.Not.EqualTo(Guid.Empty));
|
2014-01-08 15:43:58 +11:00
|
|
|
|
}
|
2012-11-13 19:07:43 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Get_Content_By_Guid_Key()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
ContentTypeRepository contentTypeRepository;
|
|
|
|
|
|
var repository = CreateRepository(unitOfWork, out contentTypeRepository);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
// Act
|
2016-12-01 08:29:11 +01:00
|
|
|
|
var query = repository.QueryT.Where(x => x.Key == new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"));
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var content = repository.GetByQuery(query).SingleOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.That(content, Is.Not.Null);
|
2013-11-19 15:36:30 +11:00
|
|
|
|
Assert.That(content.Id, Is.EqualTo(NodeDto.NodeIdSeed + 1));
|
2014-01-08 15:43:58 +11:00
|
|
|
|
}
|
2012-11-13 19:07:43 -01:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
public void CreateTestData()
|
|
|
|
|
|
{
|
2013-11-19 15:36:30 +11:00
|
|
|
|
//Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed)
|
2012-11-05 09:03:48 -01:00
|
|
|
|
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
|
2012-11-13 19:07:43 -01:00
|
|
|
|
contentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522");
|
2012-11-05 09:03:48 -01:00
|
|
|
|
ServiceContext.ContentTypeService.Save(contentType);
|
|
|
|
|
|
|
2013-11-19 15:36:30 +11:00
|
|
|
|
//Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1)
|
2012-11-05 09:03:48 -01:00
|
|
|
|
Content textpage = MockedContent.CreateSimpleContent(contentType);
|
2012-11-13 19:07:43 -01:00
|
|
|
|
textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0");
|
2012-11-05 09:03:48 -01:00
|
|
|
|
ServiceContext.ContentService.Save(textpage, 0);
|
|
|
|
|
|
|
2013-11-19 15:36:30 +11:00
|
|
|
|
//Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2)
|
2012-11-05 09:03:48 -01:00
|
|
|
|
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
|
2012-11-13 19:07:43 -01:00
|
|
|
|
subpage.Key = new Guid("FF11402B-7E53-4654-81A7-462AC2108059");
|
2012-11-05 09:03:48 -01:00
|
|
|
|
ServiceContext.ContentService.Save(subpage, 0);
|
|
|
|
|
|
|
2013-11-19 15:36:30 +11:00
|
|
|
|
//Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3)
|
2012-11-05 09:03:48 -01:00
|
|
|
|
Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id);
|
|
|
|
|
|
ServiceContext.ContentService.Save(subpage2, 0);
|
|
|
|
|
|
|
2013-11-19 15:36:30 +11:00
|
|
|
|
//Create and Save Content "Text Page Deleted" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 4)
|
2012-11-05 09:03:48 -01:00
|
|
|
|
Content trashed = MockedContent.CreateSimpleContent(contentType, "Text Page Deleted", -20);
|
|
|
|
|
|
trashed.Trashed = true;
|
|
|
|
|
|
ServiceContext.ContentService.Save(trashed, 0);
|
|
|
|
|
|
}
|
2012-10-30 20:01:09 -01:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|