Update to DefaultPublishedMediaStore, changed namespace for some unit tests.

This commit is contained in:
Shannon Deminick
2012-09-20 03:47:24 +07:00
parent 394078d470
commit dc000ea33c
8 changed files with 68 additions and 15 deletions

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace Umbraco.Tests
{
[TestFixture]
public class PublishMediaStoreTests
{
[Test]
public void Test_DictionaryDocument()
{
Func<int, Dictionary<string, string>> getDictionary = i => new Dictionary<string, string>()
{
{"id", i.ToString()},
{"template", "testTemplate"},
{"sortOrder", "44"},
{"nodeName", "Testing"},
{"urlName", "testing"},
{"nodeTypeAlias", "myType"},
{"nodeType", "22"},
{"writerName", "Shannon"},
{"creatorName", "Shannon"},
{"writerID", "33"},
{"creatorID", "33"},
{"path", "1,2,3,4,5"},
{"createDate", "2012-01-02"},
{"level", "3"}
};
var dicDoc = new DefaultPublishedMediaStore.DictionaryDocument(
getDictionary(1234),
d => new DefaultPublishedMediaStore.DictionaryDocument(
getDictionary(321),
a => null,
a => new List<IDocument>()),
d => new List<IDocument>());
}
}
}

View File

@@ -6,7 +6,7 @@ using Umbraco.Tests.TestHelpers;
using umbraco.BasePages;
using umbraco.interfaces;
namespace Umbraco.Tests
namespace Umbraco.Tests.Resolvers
{
[TestFixture]

View File

@@ -5,10 +5,9 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.ObjectResolution;
using Umbraco.Tests.TestHelpers;
using umbraco.editorControls.macrocontainer;
using umbraco.interfaces;
namespace Umbraco.Tests
namespace Umbraco.Tests.Resolvers
{
[TestFixture]
public class MacroFieldEditorsResolverTests

View File

@@ -5,7 +5,7 @@ using NUnit.Framework;
using Umbraco.Core.ObjectResolution;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests
namespace Umbraco.Tests.Resolvers
{
[TestFixture]
public class ManyObjectResolverTests

View File

@@ -5,10 +5,9 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.ObjectResolution;
using Umbraco.Tests.TestHelpers;
using umbraco.cms.businesslogic.packager;
using umbraco.interfaces;
namespace Umbraco.Tests
namespace Umbraco.Tests.Resolvers
{
[TestFixture]
public class PackageActionsResolverTests

View File

@@ -52,7 +52,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActionsResolverTests.cs" />
<Compile Include="ContentStores\PublishMediaStoreTests.cs" />
<Compile Include="Resolvers\ActionsResolverTests.cs" />
<Compile Include="AsynchronousRollingFileAppenderTests.cs" />
<Compile Include="BusinessLogic\ApplicationTest.cs" />
<Compile Include="BusinessLogic\ApplicationTreeTest.cs" />
@@ -63,7 +64,7 @@
<Compile Include="DynamicDocument\DynamicDocumentTestsBase.cs" />
<Compile Include="DynamicDocument\DynamicNodeTests.cs" />
<Compile Include="ObjectExtensionsTests.cs" />
<Compile Include="PublishContentStoreTests.cs" />
<Compile Include="ContentStores\PublishContentStoreTests.cs" />
<Compile Include="DataTypeFactoryTests.cs" />
<Compile Include="Routing\BaseRoutingTest.cs" />
<Compile Include="GlobalSettingsTests.cs" />
@@ -78,11 +79,11 @@
<Compile Include="Stubs\TestControllerFactory.cs" />
<Compile Include="TestHelpers\BaseWebTest.cs" />
<Compile Include="UriUtilityTests.cs" />
<Compile Include="MacroFieldEditorsResolverTests.cs" />
<Compile Include="Resolvers\MacroFieldEditorsResolverTests.cs" />
<Compile Include="MacroEngineFactoryTests.cs" />
<Compile Include="ManyObjectResolverTests.cs" />
<Compile Include="Resolvers\ManyObjectResolverTests.cs" />
<Compile Include="MediaFactoryTests.cs" />
<Compile Include="PackageActionsResolverTests.cs" />
<Compile Include="Resolvers\PackageActionsResolverTests.cs" />
<Compile Include="PluginManagerExtensions.cs" />
<Compile Include="PluginManagerTests.cs" />
<Compile Include="Stubs\FakeLastChanceLookup.cs" />

View File

@@ -107,7 +107,10 @@ namespace Umbraco.Web
}
}
return new DictionaryDocument(values, d => d.ParentId.HasValue ? GetUmbracoMedia(d.ParentId.Value) : null);
return new DictionaryDocument(values,
d => d.ParentId.HasValue ? GetUmbracoMedia(d.ParentId.Value) : null,
//TODO: Fix this!
d => Enumerable.Empty<IDocument>());
}
/// <summary>
@@ -122,13 +125,17 @@ namespace Umbraco.Web
//TODO: Unit test this!
public DictionaryDocument(IDictionary<string, string> valueDictionary, Func<DictionaryDocument, IDocument> getParent)
public DictionaryDocument(
IDictionary<string, string> valueDictionary,
Func<DictionaryDocument, IDocument> getParent,
Func<DictionaryDocument, IEnumerable<IDocument>> getChildren)
{
if (valueDictionary == null) throw new ArgumentNullException("valueDictionary");
if (getParent == null) throw new ArgumentNullException("getParent");
_getParent = getParent;
_getChildren = getChildren;
ValidateAndSetProperty(valueDictionary, val => Id = int.Parse(val), "id", "nodeId", "__NodeId"); //should validate the int!
ValidateAndSetProperty(valueDictionary, val => TemplateId = int.Parse(val), "template", "templateId");
ValidateAndSetProperty(valueDictionary, val => SortOrder = int.Parse(val), "sortOrder");
@@ -166,6 +173,8 @@ namespace Umbraco.Web
}
private readonly Func<DictionaryDocument, IDocument> _getParent;
private readonly Func<DictionaryDocument, IEnumerable<IDocument>> _getChildren;
public IDocument Parent
{
get { return _getParent(this); }
@@ -189,7 +198,10 @@ namespace Umbraco.Web
public Guid Version { get; private set; }
public int Level { get; private set; }
public Collection<IDocumentProperty> Properties { get; private set; }
public IEnumerable<IDocument> Children { get; private set; }
public IEnumerable<IDocument> Children
{
get { return _getChildren(this); }
}
private readonly List<string> _keysAdded = new List<string>();
private void ValidateAndSetProperty(IDictionary<string, string> valueDictionary, Action<string> setProperty, params string[] potentialKeys)