Fixing broken media tests after having added ToXml and saving of xml to ContentXml table in the MediaService

This commit is contained in:
Morten Christensen
2013-01-24 12:25:48 -01:00
parent b17dcd2b56
commit 23141e1e8c
6 changed files with 48 additions and 23 deletions

View File

@@ -299,21 +299,9 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Gets the <see cref="IProfile"/> for the Creator of this media item.
/// Gets the <see cref="IProfile"/> for the Creator of this content/media item.
/// </summary>
internal static IProfile GetCreatorProfile(this IMedia media)
{
using (var repository = RepositoryResolver.Current.Factory.CreateUserRepository(
PetaPocoUnitOfWorkProvider.CreateUnitOfWork()))
{
return repository.GetProfileById(media.CreatorId);
}
}
/// <summary>
/// Gets the <see cref="IProfile"/> for the Creator of this content.
/// </summary>
public static IProfile GetCreatorProfile(this IContent content)
public static IProfile GetCreatorProfile(this IContentBase content)
{
using (var repository = RepositoryResolver.Current.Factory.CreateUserRepository(
PetaPocoUnitOfWorkProvider.CreateUnitOfWork()))
@@ -383,7 +371,9 @@ namespace Umbraco.Core.Models
var x = media.ToXml(nodeName);
x.Add(new XAttribute("nodeType", media.ContentType.Id));
x.Add(new XAttribute("writerName", media.GetCreatorProfile().Name));
//TODO Using the GetCreatorProfile extension method seems to be causing threading/connection problems because of the way the repo is used
//x.Add(new XAttribute("writerName", media.GetCreatorProfile().Name));
x.Add(new XAttribute("writerName", string.Empty));
x.Add(new XAttribute("writerID", media.CreatorId));
x.Add(new XAttribute("version", media.Version));
x.Add(new XAttribute("template", 0));

View File

@@ -36,7 +36,7 @@ namespace Umbraco.Core.Persistence.Repositories
var sql = GetBaseQuery(false);
sql.Where(GetBaseWhereClause(), new { Id = id });
var dto = Database.Query<UserDto>(sql).FirstOrDefault();
var dto = Database.FirstOrDefault<UserDto>(sql);
if (dto == null)
return null;
@@ -139,7 +139,7 @@ namespace Umbraco.Core.Persistence.Repositories
var sql = GetBaseQuery(false);
sql.Where(GetBaseWhereClause(), new { Id = id });
var dto = Database.Query<UserDto>(sql).FirstOrDefault();
var dto = Database.FirstOrDefault<UserDto>(sql);
if (dto == null)
return null;

View File

@@ -54,7 +54,7 @@ namespace Umbraco.Core.Services
_contentService = new Lazy<ContentService>(() => new ContentService(provider, repositoryFactory.Value, publishingStrategy, _userService.Value));
if(_mediaService == null)
_mediaService = new Lazy<MediaService>(() => new MediaService(provider, repositoryFactory.Value));
_mediaService = new Lazy<MediaService>(() => new MediaService(provider, repositoryFactory.Value, _userService.Value));
if(_macroService == null)
_macroService = new Lazy<MacroService>(() => new MacroService(fileProvider, repositoryFactory.Value));

View File

@@ -1,16 +1,12 @@
using System;
using System.Linq;
using System.Linq;
using System.Xml.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.ObjectResolution;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Web;
using umbraco.editorControls.tinyMCE3;
using umbraco.interfaces;
using File = System.IO.File;
namespace Umbraco.Tests.Models
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence;
@@ -9,6 +10,8 @@ using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using umbraco.editorControls.tinyMCE3;
using umbraco.interfaces;
namespace Umbraco.Tests.Persistence.Repositories
{
@@ -18,6 +21,20 @@ namespace Umbraco.Tests.Persistence.Repositories
[SetUp]
public override void Initialize()
{
//NOTE The DataTypesResolver is only necessary because we are using the Save method in the MediaService
//this ensures its reset
PluginManager.Current = new PluginManager();
//for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
PluginManager.Current.AssembliesToScan = new[]
{
typeof(IDataType).Assembly,
typeof(tinyMCE3dataType).Assembly
};
DataTypesResolver.Current = new DataTypesResolver(
PluginManager.Current.ResolveDataTypes());
base.Initialize();
CreateTestData();
@@ -288,6 +305,9 @@ namespace Umbraco.Tests.Persistence.Repositories
[TearDown]
public override void TearDown()
{
//reset the app context
DataTypesResolver.Reset();
base.TearDown();
}

View File

@@ -13,6 +13,8 @@ using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using umbraco.editorControls.tinyMCE3;
using umbraco.interfaces;
namespace Umbraco.Tests.Services
{
@@ -25,6 +27,20 @@ namespace Umbraco.Tests.Services
[SetUp]
public override void Initialize()
{
//NOTE The DataTypesResolver is only necessary because we are using the Save method in the MediaService
//this ensures its reset
PluginManager.Current = new PluginManager();
//for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
PluginManager.Current.AssembliesToScan = new[]
{
typeof(IDataType).Assembly,
typeof(tinyMCE3dataType).Assembly
};
DataTypesResolver.Current = new DataTypesResolver(
PluginManager.Current.ResolveDataTypes());
base.Initialize();
//we need to use our own custom IDatabaseFactory for the DatabaseContext because we MUST ensure that
@@ -47,6 +63,9 @@ namespace Umbraco.Tests.Services
[TearDown]
public override void TearDown()
{
//reset the app context
DataTypesResolver.Reset();
_error = null;
//dispose!