U4-7063 - Umbraco.TypedContent(ints) should not return nulls

This commit is contained in:
Stephan
2015-09-04 10:42:56 +02:00
parent 1fdb813d1d
commit a542cf56d4
4 changed files with 232 additions and 27 deletions

View File

@@ -139,7 +139,6 @@ namespace Umbraco.Tests.PublishedContent
}
[Test]
[Ignore("Fails as long as PublishedContentModel is internal.")] // fixme
public void OfType1()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
@@ -155,7 +154,6 @@ namespace Umbraco.Tests.PublishedContent
}
[Test]
[Ignore("Fails as long as PublishedContentModel is internal.")] // fixme
public void OfType2()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
@@ -169,7 +167,6 @@ namespace Umbraco.Tests.PublishedContent
}
[Test]
[Ignore("Fails as long as PublishedContentModel is internal.")] // fixme
public void OfType()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
@@ -196,7 +193,6 @@ namespace Umbraco.Tests.PublishedContent
}
[Test]
[Ignore("Fails as long as PublishedContentModel is internal.")] // fixme
public void Issue()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
@@ -218,6 +214,16 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual(1234, content3.Prop1);
}
[Test]
public void PublishedContentQueryTypedContentList()
{
var query = new PublishedContentQuery(UmbracoContext.Current.ContentCache, UmbracoContext.Current.MediaCache);
var result = query.TypedContent(new[] { 1, 2, 4 }).ToArray();
Assert.AreEqual(2, result.Length);
Assert.AreEqual(1, result[0].Id);
Assert.AreEqual(2, result[1].Id);
}
static SolidPublishedCaches CreatePublishedContent()
{
var caches = new SolidPublishedCaches();

View File

@@ -14,6 +14,7 @@ namespace Umbraco.Tests.PublishedContent
class SolidPublishedCaches : IPublishedCaches
{
public readonly SolidPublishedContentCache ContentCache = new SolidPublishedContentCache();
public readonly SolidPublishedMediaCache MediaCache = new SolidPublishedMediaCache();
public ContextualPublishedContentCache CreateContextualContentCache(UmbracoContext context)
{
@@ -22,7 +23,7 @@ namespace Umbraco.Tests.PublishedContent
public ContextualPublishedMediaCache CreateContextualMediaCache(UmbracoContext context)
{
return null;
return new ContextualPublishedMediaCache(MediaCache, context);
}
}
@@ -106,6 +107,66 @@ namespace Umbraco.Tests.PublishedContent
}
}
class SolidPublishedMediaCache : IPublishedMediaCache
{
private readonly Dictionary<int, IPublishedContent> _media = new Dictionary<int, IPublishedContent>();
public void Add(SolidPublishedContent content)
{
_media[content.Id] = content.CreateModel();
}
public void Clear()
{
_media.Clear();
}
public IPublishedContent GetById(UmbracoContext umbracoContext, bool preview, int contentId)
{
return _media.ContainsKey(contentId) ? _media[contentId] : null;
}
public IEnumerable<IPublishedContent> GetAtRoot(UmbracoContext umbracoContext, bool preview)
{
return _media.Values.Where(x => x.Parent == null);
}
public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars)
{
throw new NotImplementedException();
}
public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
{
throw new NotImplementedException();
}
public IEnumerable<IPublishedContent> GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars)
{
throw new NotImplementedException();
}
public IEnumerable<IPublishedContent> GetByXPath(UmbracoContext umbracoContext, bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
{
throw new NotImplementedException();
}
public System.Xml.XPath.XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext, bool preview)
{
throw new NotImplementedException();
}
public bool XPathNavigatorIsNavigable
{
get { throw new NotImplementedException(); }
}
public bool HasContent(UmbracoContext umbracoContext, bool preview)
{
return _media.Count > 0;
}
}
class SolidPublishedContent : IPublishedContent
{
#region Constructor

View File

@@ -211,7 +211,7 @@ namespace Umbraco.Web
private IEnumerable<IPublishedContent> TypedDocumentsByIds(ContextualPublishedCache cache, IEnumerable<int> ids)
{
return ids.Select(eachId => TypedDocumentById(eachId, cache));
return ids.Select(eachId => TypedDocumentById(eachId, cache)).WhereNotNull();
}
private IEnumerable<IPublishedContent> TypedDocumentsByXPath(string xpath, XPathVariable[] vars, ContextualPublishedContentCache cache)

View File

@@ -584,27 +584,57 @@ namespace Umbraco.Web
return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids));
}
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedContent(params int[] ids)
{
return ContentQuery.TypedContent(ids);
}
public IEnumerable<IPublishedContent> TypedContent(params string[] ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedContent(params string[] ids)
{
return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids));
}
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<object> ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<object> ids)
{
return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids));
}
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<string> ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<string> ids)
{
return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids));
}
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<int> ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedContent(IEnumerable<int> ids)
{
return ContentQuery.TypedContent(ids);
}
@@ -651,32 +681,68 @@ namespace Umbraco.Web
return ContentQuery.ContentSingleAtXPath(xpath, vars);
}
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content(params object[] ids)
{
return ContentQuery.Content(ConvertIdsObjectToInts(ids));
}
public dynamic Content(params int[] ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content(params int[] ids)
{
return ContentQuery.Content(ids);
}
public dynamic Content(params string[] ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content(params string[] ids)
{
return ContentQuery.Content(ConvertIdsObjectToInts(ids));
}
public dynamic Content(IEnumerable<object> ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content(IEnumerable<object> ids)
{
return ContentQuery.Content(ConvertIdsObjectToInts(ids));
}
public dynamic Content(IEnumerable<int> ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content(IEnumerable<int> ids)
{
return ContentQuery.Content(ids);
}
public dynamic Content(IEnumerable<string> ids)
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content(IEnumerable<string> ids)
{
return ContentQuery.Content(ConvertIdsObjectToInts(ids));
}
@@ -758,32 +824,68 @@ namespace Umbraco.Web
return ConvertIdObjectToInt(id, out intId) ? ContentQuery.TypedMedia(intId) : null;
}
public IEnumerable<IPublishedContent> TypedMedia(params object[] ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedMedia(params object[] ids)
{
return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids));
}
public IEnumerable<IPublishedContent> TypedMedia(params int[] ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedMedia(params int[] ids)
{
return ContentQuery.TypedMedia(ids);
}
public IEnumerable<IPublishedContent> TypedMedia(params string[] ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedMedia(params string[] ids)
{
return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids));
}
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<object> ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<object> ids)
{
return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids));
}
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<int> ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<int> ids)
{
return ContentQuery.TypedMedia(ids);
}
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<string> ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable<IPublishedContent> TypedMedia(IEnumerable<string> ids)
{
return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids));
}
@@ -810,32 +912,68 @@ namespace Umbraco.Web
return ConvertIdObjectToInt(id, out intId) ? ContentQuery.Media(intId) : DynamicNull.Null;
}
public dynamic Media(params object[] ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media(params object[] ids)
{
return ContentQuery.Media(ConvertIdsObjectToInts(ids));
}
public dynamic Media(params int[] ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media(params int[] ids)
{
return ContentQuery.Media(ids);
}
public dynamic Media(params string[] ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media(params string[] ids)
{
return ContentQuery.Media(ConvertIdsObjectToInts(ids));
}
public dynamic Media(IEnumerable<object> ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media(IEnumerable<object> ids)
{
return ContentQuery.Media(ConvertIdsObjectToInts(ids));
}
public dynamic Media(IEnumerable<int> ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media(IEnumerable<int> ids)
{
return ContentQuery.Media(ids);
}
public dynamic Media(IEnumerable<string> ids)
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media(IEnumerable<string> ids)
{
return ContentQuery.Media(ConvertIdsObjectToInts(ids));
}