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-11-10 11:27:12 +01:00
|
|
|
|
using System.Threading;
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void CacheActiveForIntsAndGuids()
|
2017-09-19 15:51:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
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())
|
|
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository, cacheHelper: realCache);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
|
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");
|
2017-11-10 11:27:12 +01:00
|
|
|
|
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
|
2017-09-19 15:51:47 +02:00
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var content = MockedContent.CreateSimpleContent(contentType);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
repository.AddOrUpdate(content);
|
|
|
|
|
|
unitOfWork.Complete();
|
|
|
|
|
|
|
|
|
|
|
|
udb.EnableSqlCount = true;
|
|
|
|
|
|
|
|
|
|
|
|
//go get it, this should already be cached since the default repository key is the INT
|
2017-11-10 11:27:12 +01:00
|
|
|
|
repository.Get(content.Id);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
Assert.AreEqual(0, udb.SqlCount);
|
|
|
|
|
|
//retrieve again, this should use cache
|
2017-11-10 11:27:12 +01:00
|
|
|
|
repository.Get(content.Id);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
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
|
2017-11-10 11:27:12 +01:00
|
|
|
|
repository.Get(content.Key);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
var sqlCount = udb.SqlCount;
|
|
|
|
|
|
Assert.Greater(sqlCount, 0);
|
|
|
|
|
|
//retrieve again, this should use cache now
|
2017-11-10 11:27:12 +01:00
|
|
|
|
repository.Get(content.Key);
|
2017-09-19 15:51:47 +02:00
|
|
|
|
Assert.AreEqual(sqlCount, udb.SqlCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void CreateVersions()
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
|
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository, out DataTypeDefinitionRepository _);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
var versions = new List<Guid>();
|
|
|
|
|
|
var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
2017-11-10 11:27:12 +01:00
|
|
|
|
ServiceContext.FileService.SaveTemplate(hasPropertiesContentType.DefaultTemplate); // else, FK violation on contentType!
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
IContent content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
|
|
|
|
|
|
|
|
|
|
|
// save = create the initial version
|
2017-05-12 14:49:44 +02:00
|
|
|
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// publish = no new version (was not published)
|
|
|
|
|
|
content1.SetValue("title", "title");
|
|
|
|
|
|
((Content) content1).PublishValues();
|
|
|
|
|
|
((Content) content1).PublishedState = PublishedState.Publishing;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
2017-11-10 11:27:12 +01:00
|
|
|
|
versions.Add(content1.Version); // the same version
|
|
|
|
|
|
|
|
|
|
|
|
// no new version has been created
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.IsTrue(content1.Published);
|
|
|
|
|
|
Assert.AreEqual(PublishedState.Published, ((Content) content1).PublishedState);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
|
|
|
|
|
|
|
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(true, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
|
|
|
|
|
|
// change something
|
|
|
|
|
|
// save = update the current (draft) version
|
|
|
|
|
|
content1.Name = "name-1";
|
|
|
|
|
|
content1.SetValue("title", "title-1");
|
2017-05-12 14:49:44 +02:00
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
2017-11-10 11:27:12 +01:00
|
|
|
|
versions.Add(content1.Version); // the same version
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// no new version has been created
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.IsTrue(content1.Published);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(true, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// unpublish = should create a new version
|
|
|
|
|
|
((Content) content1).PublishedState = PublishedState.Unpublishing;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
2017-11-10 11:27:12 +01:00
|
|
|
|
versions.Add(content1.Version); // the new version
|
|
|
|
|
|
|
|
|
|
|
|
// a new version has been created
|
|
|
|
|
|
Assert.AreNotEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.IsFalse(content1.Published);
|
|
|
|
|
|
Assert.AreEqual(PublishedState.Unpublished, ((Content) content1).PublishedState);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
|
|
|
|
|
|
|
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(false, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
|
|
|
|
|
|
// change something
|
|
|
|
|
|
// save = update the current (draft) version
|
|
|
|
|
|
content1.Name = "name-2";
|
|
|
|
|
|
content1.SetValue("title", "title-2");
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
versions.Add(content1.Version); // the same version
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// no new version has been created
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(false, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// publish = no new version (was not published)
|
|
|
|
|
|
((Content) content1).PublishValues();
|
|
|
|
|
|
((Content) content1).PublishedState = PublishedState.Publishing;
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
versions.Add(content1.Version); // the same version
|
|
|
|
|
|
|
|
|
|
|
|
// no new version has been created
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.IsTrue(content1.Published);
|
|
|
|
|
|
Assert.AreEqual(PublishedState.Published, ((Content) content1).PublishedState);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
|
|
|
|
|
|
|
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(true, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
|
|
|
|
|
|
// change something
|
|
|
|
|
|
// save = update the current (draft) version
|
|
|
|
|
|
content1.Name = "name-3";
|
|
|
|
|
|
content1.SetValue("title", "title-3");
|
|
|
|
|
|
//Thread.Sleep(2000); // force date change
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
versions.Add(content1.Version); // the same version
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// no new version has been created
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(true, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// publish = new version (was published)
|
|
|
|
|
|
content1.Name = "name-4";
|
|
|
|
|
|
content1.SetValue("title", "title-4");
|
|
|
|
|
|
((Content) content1).PublishValues();
|
|
|
|
|
|
((Content) content1).PublishedState = PublishedState.Publishing;
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
versions.Add(content1.Version); // new version
|
|
|
|
|
|
|
|
|
|
|
|
// a new version has been created
|
|
|
|
|
|
Assert.AreNotEqual(versions[versions.Count - 2], versions[versions.Count - 1]);
|
|
|
|
|
|
Assert.IsTrue(content1.Published);
|
|
|
|
|
|
Assert.AreEqual(PublishedState.Published, ((Content) content1).PublishedState);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 1], repository.Get(content1.Id).Version);
|
|
|
|
|
|
|
|
|
|
|
|
// misc checks
|
|
|
|
|
|
Assert.AreEqual(true, unitOfWork.Database.ExecuteScalar<bool>("SELECT published FROM uDocument WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
Console.WriteLine(unitOfWork.Database.ExecuteScalar<DateTime>("SELECT updateDate FROM uContent WHERE nodeId=@id", new { id = content1.Id }));
|
|
|
|
|
|
|
|
|
|
|
|
// get older version
|
|
|
|
|
|
var content = repository.GetByVersion(versions[versions.Count - 2]);
|
|
|
|
|
|
Assert.IsNotNull(content.Version);
|
|
|
|
|
|
Assert.AreEqual(versions[versions.Count - 2], content.Version);
|
|
|
|
|
|
Assert.AreEqual("name-4", content1.Name);
|
|
|
|
|
|
Assert.AreEqual("title-4", content1.GetValue("title"));
|
|
|
|
|
|
Assert.AreEqual("name-3", content.Name);
|
|
|
|
|
|
Assert.AreEqual("title-3", content.GetValue("title"));
|
|
|
|
|
|
|
|
|
|
|
|
// get all versions - most recent first
|
|
|
|
|
|
var allVersions = repository.GetAllVersions(content1.Id).ToArray();
|
|
|
|
|
|
var expVersions = versions.Distinct().Reverse().ToArray();
|
|
|
|
|
|
Assert.AreEqual(expVersions.Length, allVersions.Length);
|
|
|
|
|
|
for (var i = 0; i < expVersions.Length; i++)
|
|
|
|
|
|
Assert.AreEqual(expVersions[i], allVersions[i].Version);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void PropertyDataAssignedCorrectly()
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
var provider = TestObjects.GetScopeUnitOfWorkProvider(Logger);
|
|
|
|
|
|
using (var unitOfWork = provider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository, out DataTypeDefinitionRepository _);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
var emptyContentType = MockedContentTypes.CreateBasicContentType();
|
|
|
|
|
|
var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
2017-11-10 11:27:12 +01:00
|
|
|
|
ServiceContext.FileService.SaveTemplate(hasPropertiesContentType.DefaultTemplate); // else, FK violation on contentType!
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var content1 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
|
|
|
|
|
var content2 = MockedContent.CreateBasicContent(emptyContentType);
|
|
|
|
|
|
var content3 = MockedContent.CreateSimpleContent(hasPropertiesContentType);
|
|
|
|
|
|
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(emptyContentType);
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(hasPropertiesContentType);
|
|
|
|
|
|
repository.AddOrUpdate(content1);
|
|
|
|
|
|
repository.AddOrUpdate(content2);
|
|
|
|
|
|
repository.AddOrUpdate(content3);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// this will cause the GetPropertyCollection to execute and we need to ensure that
|
2017-05-12 14:49:44 +02:00
|
|
|
|
// all of the properties and property types are all correct
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetAll(content1.Id, content2.Id, content3.Id).ToArray();
|
|
|
|
|
|
var n1 = result[0];
|
|
|
|
|
|
var n2 = result[1];
|
|
|
|
|
|
var n3 = result[2];
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(content1.Id, n1.Id);
|
|
|
|
|
|
Assert.AreEqual(content2.Id, n2.Id);
|
|
|
|
|
|
Assert.AreEqual(content3.Id, n3.Id);
|
|
|
|
|
|
|
|
|
|
|
|
// compare everything including properties and their values
|
|
|
|
|
|
// this ensures that they have been properly retrieved
|
|
|
|
|
|
TestHelper.AssertPropertyValuesAreEqual(content1, n1);
|
|
|
|
|
|
TestHelper.AssertPropertyValuesAreEqual(content2, n2);
|
|
|
|
|
|
TestHelper.AssertPropertyValuesAreEqual(content3, n3);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void PropertyValuesWithSpecialTypes()
|
2016-06-27 15:21:21 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository, out DataTypeDefinitionRepository dataTypeDefinitionRepository);
|
2016-07-08 17:58:01 +02:00
|
|
|
|
|
2016-06-27 15:21:21 +02:00
|
|
|
|
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);
|
|
|
|
|
|
|
2017-11-15 08:53:20 +01:00
|
|
|
|
var propertyTypeCollection = new PropertyTypeCollection(true,
|
2016-06-27 15:21:21 +02:00
|
|
|
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// int and decimal values are passed in as strings as they would be from the backoffice UI
|
2016-06-27 15:21:21 +02:00
|
|
|
|
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
|
|
|
|
repository.AddOrUpdate(textpage);
|
2016-07-08 17:58:01 +02:00
|
|
|
|
unitOfWork.Complete();
|
2016-06-27 15:21:21 +02:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void SaveContent()
|
2012-10-30 20:01:09 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository);
|
|
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
|
|
|
|
|
|
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
|
2016-06-07 12:20:10 +02:00
|
|
|
|
IContent textpage = MockedContent.CreateSimpleContent(contentType);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
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.That(contentType.HasIdentity, Is.True);
|
|
|
|
|
|
Assert.That(textpage.HasIdentity, Is.True);
|
2015-08-05 16:30:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void SaveContentWithDefaultTemplate()
|
2015-08-05 16:30:21 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository, out TemplateRepository templateRepository);
|
2016-04-29 10:53:19 +02:00
|
|
|
|
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage2", "Textpage");
|
|
|
|
|
|
contentType.AllowedTemplates = Enumerable.Empty<ITemplate>(); // because CreateSimpleContentType assigns one already
|
2015-08-05 16:30:21 +02:00
|
|
|
|
contentType.SetDefaultTemplate(template);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var textpage = MockedContent.CreateSimpleContent(contentType);
|
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);
|
|
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.NotNull(textpage.Template);
|
|
|
|
|
|
Assert.AreEqual(textpage.Template, contentType.DefaultTemplate);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
|
|
|
|
|
|
unitOfWork.Complete();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
TestHelper.AssertPropertyValuesAreEqual(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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void SaveContentWithAtSignInName()
|
2013-09-05 10:44:28 +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())
|
2013-09-18 11:40:40 +10:00
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository);
|
2014-03-11 15:02:23 +11:00
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
2017-11-10 11:27:12 +01:00
|
|
|
|
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var textpage = MockedContent.CreateSimpleContent(contentType, "test@umbraco.org");
|
|
|
|
|
|
var anotherTextpage = MockedContent.CreateSimpleContent(contentType, "@lightgiants");
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
|
2013-09-18 11:40:40 +10:00
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void SaveContentMultiple()
|
2012-10-30 20:01:09 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository);
|
|
|
|
|
|
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
|
|
|
|
|
|
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
|
|
|
|
|
|
var textpage = MockedContent.CreateSimpleContent(contentType);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
contentTypeRepository.AddOrUpdate(contentType);
|
|
|
|
|
|
repository.AddOrUpdate(textpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
repository.AddOrUpdate(subpage);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetContentIsNotDirty()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2013-11-19 15:36:30 +11:00
|
|
|
|
var content = repository.Get(NodeDto.NodeIdSeed + 3);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var dirty = ((Content) content).IsDirty();
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
|
|
|
|
|
Assert.That(dirty, Is.False);
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void UpdateContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.AreEqual(content.Id, updatedContent.Id);
|
|
|
|
|
|
Assert.AreEqual(content.Name, updatedContent.Name);
|
|
|
|
|
|
Assert.AreEqual(content.Version, updatedContent.Version);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(content.GetValue("title"), "Welcome to our Home page");
|
|
|
|
|
|
content.SetValue("title", "toot");
|
|
|
|
|
|
repository.AddOrUpdate(content);
|
|
|
|
|
|
unitOfWork.Flush();
|
|
|
|
|
|
updatedContent = repository.Get(NodeDto.NodeIdSeed + 2);
|
2014-01-08 15:43:58 +11:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.AreEqual("toot", updatedContent.GetValue("title"));
|
|
|
|
|
|
Assert.AreEqual(content.Version, updatedContent.Version);
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void UpdateContentWithNullTemplate()
|
2015-08-05 16:30:21 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
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);
|
|
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.IsNull(updatedContent.Template);
|
2015-08-05 16:30:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void DeleteContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out var contentTypeRepository);
|
|
|
|
|
|
var contentType = contentTypeRepository.Get(NodeDto.NodeIdSeed + 1);
|
|
|
|
|
|
var content = new Content("Textpage 2 Child Node", NodeDto.NodeIdSeed + 4, contentType);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
content.CreatorId = 0;
|
|
|
|
|
|
content.WriterId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.IsNull(content1);
|
2014-01-08 15:43:58 +11:00
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
var content = repository.Get(NodeDto.NodeIdSeed + 4);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.AreEqual(NodeDto.NodeIdSeed + 4, content.Id);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
Assert.That(content.CreateDate, Is.GreaterThan(DateTime.MinValue));
|
|
|
|
|
|
Assert.That(content.UpdateDate, Is.GreaterThan(DateTime.MinValue));
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.AreNotEqual(0, content.ParentId);
|
|
|
|
|
|
Assert.AreEqual("Text Page 2", content.Name);
|
|
|
|
|
|
Assert.AreNotEqual(Guid.Empty, content.Version);
|
|
|
|
|
|
Assert.AreEqual(NodeDto.NodeIdSeed + 1, content.ContentTypeId);
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void QueryContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var result = repository.GetByQuery(query);
|
|
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.GreaterOrEqual(2, result.Count());
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetAllContentManyVersions()
|
2014-09-11 16:04:16 +10:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
2014-09-11 16:04:16 +10:00
|
|
|
|
var result = repository.GetAll().ToArray();
|
2017-11-10 11:27:12 +01:00
|
|
|
|
|
|
|
|
|
|
// save them all
|
2014-09-11 16:04:16 +10:00
|
|
|
|
foreach (var content in result)
|
|
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
content.SetValue("title", content.GetValue<string>("title") + "x");
|
2014-09-11 16:04:16 +10:00
|
|
|
|
repository.AddOrUpdate(content);
|
|
|
|
|
|
}
|
2016-05-02 12:12:21 +02:00
|
|
|
|
unitOfWork.Flush();
|
2017-11-10 11:27:12 +01:00
|
|
|
|
|
|
|
|
|
|
// publish them all
|
2014-09-11 16:04:16 +10:00
|
|
|
|
foreach (var content in result)
|
|
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
((Content) content).PublishAllValues();
|
|
|
|
|
|
((Content) content).PublishedState = 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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
// get them all again
|
2014-09-11 16:04:16 +10:00
|
|
|
|
var result2 = repository.GetAll().ToArray();
|
|
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.AreEqual(result.Length, result2.Length);
|
2014-09-11 16:04:16 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_CustomPropertySort()
|
2016-04-20 12:50:52 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Name.Contains("Text"));
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 2, out var totalRecords, "title", Direction.Ascending, false);
|
2016-04-20 12:50:52 +02:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_FirstPage()
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out var totalRecords, "Name", Direction.Ascending, true);
|
|
|
|
|
|
|
2016-04-20 12:50:52 +02:00
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_SecondPage()
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 1, 1, out var totalRecords, "Name", Direction.Ascending, true);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_SinglePage()
|
2014-08-14 08:42:36 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 2, out var totalRecords, "Name", Direction.Ascending, true);
|
2014-08-14 08:42:36 +02:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_DescendingOrder()
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out var totalRecords, "Name", Direction.Descending, true);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
|
|
|
|
|
Assert.That(totalRecords, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
Assert.That(result.Count(), Is.EqualTo(1));
|
|
|
|
|
|
Assert.That(result.First().Name, Is.EqualTo("Text Page 2"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_FilterMatchingSome()
|
2014-08-14 00:16:37 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2016-11-02 12:39:41 +01:00
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var filterQuery = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Name.Contains("Page 2"));
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out var totalRecords, "Name", Direction.Ascending, true, filterQuery);
|
2014-08-14 00:16:37 +02:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetPagedResultsByQuery_FilterMatchingAll()
|
2014-08-14 08:42:36 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
2016-05-26 15:30:40 +02:00
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2016-05-02 15:38:45 +02:00
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var filterQuery = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Name.Contains("text"));
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var result = repository.GetPagedResultsByQuery(query, 0, 1, out var totalRecords, "Name", Direction.Ascending, true, filterQuery);
|
2014-08-14 08:42:36 +02:00
|
|
|
|
|
|
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetAllContentByIds()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
|
2013-09-18 11:40:40 +10:00
|
|
|
|
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]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void GetAllContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var contents = repository.GetAll();
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void ExistContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
|
|
|
|
|
var exists = repository.Exists(NodeDto.NodeIdSeed + 2);
|
2012-11-05 09:03:48 -01:00
|
|
|
|
|
2013-09-18 11:40:40 +10:00
|
|
|
|
Assert.That(exists, Is.True);
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void CountContent()
|
2012-11-05 09:03:48 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
|
|
|
|
|
|
|
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().Where(x => x.Level == 2);
|
2013-09-18 11:40:40 +10:00
|
|
|
|
var result = repository.Count(query);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.GreaterThanOrEqualTo(2));
|
|
|
|
|
|
}
|
2012-11-05 09:03:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-13 19:07:43 -01:00
|
|
|
|
[Test]
|
2017-11-10 11:27:12 +01:00
|
|
|
|
public void QueryContentByUniqueId()
|
2012-11-13 19:07:43 -01:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2017-11-10 11:27:12 +01:00
|
|
|
|
var repository = CreateRepository(unitOfWork, out _);
|
2012-11-13 19:07:43 -01:00
|
|
|
|
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = unitOfWork.SqlContext.Query<IContent>().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();
|
|
|
|
|
|
|
2017-11-10 11:27:12 +01:00
|
|
|
|
Assert.IsNotNull(content);
|
|
|
|
|
|
Assert.AreEqual(NodeDto.NodeIdSeed + 2, content.Id);
|
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");
|
2017-11-10 11:27:12 +01:00
|
|
|
|
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
|
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
|
|
|
|
}
|