diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index 7c74d093ba..ff16c5306c 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -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(); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs index 93c4cb0b8e..4abfc6e18d 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs @@ -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 _media = new Dictionary(); + + 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 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 GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars) + { + throw new NotImplementedException(); + } + + public IEnumerable 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 diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index afeddd1bf1..16f42b8197 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -211,7 +211,7 @@ namespace Umbraco.Web private IEnumerable TypedDocumentsByIds(ContextualPublishedCache cache, IEnumerable ids) { - return ids.Select(eachId => TypedDocumentById(eachId, cache)); + return ids.Select(eachId => TypedDocumentById(eachId, cache)).WhereNotNull(); } private IEnumerable TypedDocumentsByXPath(string xpath, XPathVariable[] vars, ContextualPublishedContentCache cache) diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index e407edda4f..35797a4432 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -584,27 +584,57 @@ namespace Umbraco.Web return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids)); } + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. public IEnumerable TypedContent(params int[] ids) { return ContentQuery.TypedContent(ids); } - public IEnumerable TypedContent(params string[] ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable TypedContent(params string[] ids) { return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids)); } - public IEnumerable TypedContent(IEnumerable ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable TypedContent(IEnumerable ids) { return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids)); } - public IEnumerable TypedContent(IEnumerable ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable TypedContent(IEnumerable ids) { return ContentQuery.TypedContent(ConvertIdsObjectToInts(ids)); } - public IEnumerable TypedContent(IEnumerable ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public IEnumerable TypedContent(IEnumerable ids) { return ContentQuery.TypedContent(ids); } @@ -651,32 +681,68 @@ namespace Umbraco.Web return ContentQuery.ContentSingleAtXPath(xpath, vars); } + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. public dynamic Content(params object[] ids) { return ContentQuery.Content(ConvertIdsObjectToInts(ids)); } - public dynamic Content(params int[] ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public dynamic Content(params int[] ids) { return ContentQuery.Content(ids); } - public dynamic Content(params string[] ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public dynamic Content(params string[] ids) { return ContentQuery.Content(ConvertIdsObjectToInts(ids)); } - public dynamic Content(IEnumerable ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public dynamic Content(IEnumerable ids) { return ContentQuery.Content(ConvertIdsObjectToInts(ids)); } - public dynamic Content(IEnumerable ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public dynamic Content(IEnumerable ids) { return ContentQuery.Content(ids); } - public dynamic Content(IEnumerable ids) + /// + /// Gets the contents corresponding to the identifiers. + /// + /// The content identifiers. + /// The existing contents corresponding to the identifiers. + /// If an identifier does not match an existing content, it will be missing in the returned value. + public dynamic Content(IEnumerable ids) { return ContentQuery.Content(ConvertIdsObjectToInts(ids)); } @@ -758,32 +824,68 @@ namespace Umbraco.Web return ConvertIdObjectToInt(id, out intId) ? ContentQuery.TypedMedia(intId) : null; } - public IEnumerable TypedMedia(params object[] ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable TypedMedia(params object[] ids) { return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids)); } - public IEnumerable TypedMedia(params int[] ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable TypedMedia(params int[] ids) { return ContentQuery.TypedMedia(ids); } - public IEnumerable TypedMedia(params string[] ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable TypedMedia(params string[] ids) { return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids)); } - public IEnumerable TypedMedia(IEnumerable ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable TypedMedia(IEnumerable ids) { return ContentQuery.TypedMedia(ConvertIdsObjectToInts(ids)); } - public IEnumerable TypedMedia(IEnumerable ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable TypedMedia(IEnumerable ids) { return ContentQuery.TypedMedia(ids); } - public IEnumerable TypedMedia(IEnumerable ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public IEnumerable TypedMedia(IEnumerable 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) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public dynamic Media(params object[] ids) { return ContentQuery.Media(ConvertIdsObjectToInts(ids)); } - public dynamic Media(params int[] ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public dynamic Media(params int[] ids) { return ContentQuery.Media(ids); } - public dynamic Media(params string[] ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public dynamic Media(params string[] ids) { return ContentQuery.Media(ConvertIdsObjectToInts(ids)); } - public dynamic Media(IEnumerable ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public dynamic Media(IEnumerable ids) { return ContentQuery.Media(ConvertIdsObjectToInts(ids)); } - public dynamic Media(IEnumerable ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public dynamic Media(IEnumerable ids) { return ContentQuery.Media(ids); } - public dynamic Media(IEnumerable ids) + /// + /// Gets the medias corresponding to the identifiers. + /// + /// The media identifiers. + /// The existing medias corresponding to the identifiers. + /// If an identifier does not match an existing media, it will be missing in the returned value. + public dynamic Media(IEnumerable ids) { return ContentQuery.Media(ConvertIdsObjectToInts(ids)); }