/// <summary>
 /// Converts the <param name="content"></param> to an <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphProductGroup"/>.
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns>The <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphProductGroup"/> for the <param name="content"></param>.</returns>
 /// <exception cref="T:System.Web.HttpException">The Web application is running under IIS 7 in Integrated mode.</exception>
 /// <exception cref="T:System.ArgumentException">The specified <see cref="UriPartial.Authority"/> is not valid.</exception>
 /// <exception cref="T:System.InvalidOperationException">The current <see cref="T:System.Uri" /> instance is not an absolute instance.</exception>
 /// <exception cref="T:System.ArgumentNullException">Parent products are <see langword="null" />.</exception>
 /// <exception cref="T:System.NotSupportedException">The query collection is read-only.</exception>
 /// <exception cref="T:System.MemberAccessException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and permissions to access the constructor are missing.</exception>
 /// <exception cref="T:System.MissingMemberException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and that type does not have a public, parameterless constructor.</exception>
 public static OpenGraphProductGroup ToOpenGraphProductGroup(this BundleContent content)
 {
     return(new OpenGraphProductGroup(
                title: content.DisplayName,
                new OpenGraphImage(content.GetDefaultAsset <IContentMedia>()),
                content.GetUrl()));
 }
        /// <summary>
        /// Renders the OpenGraph header tags for <see cref="BundleContent"/>
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="content">The content.</param>
        /// <returns>The <see cref="IHtmlString"/>.</returns>
        /// <exception cref="T:System.Web.HttpException">The Web application is running under IIS 7 in Integrated mode.</exception>
        /// <exception cref="T:System.InvalidOperationException">The current <see cref="T:System.Uri" /> instance is not an absolute instance.</exception>
        /// <exception cref="T:System.ArgumentException">The specified <see cref="UriPartial.Authority"/> is not valid.</exception>
        /// <exception cref="T:System.ArgumentNullException">Parent products are <see langword="null" />.</exception>
        /// <exception cref="T:System.NotSupportedException">The query collection is read-only.</exception>
        /// <exception cref="T:System.MemberAccessException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and permissions to access the constructor are missing.</exception>
        /// <exception cref="T:System.MissingMemberException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and that type does not have a public, parameterless constructor.</exception>
        public static IHtmlString OpenGraphProductGroup(this HtmlHelper htmlHelper, BundleContent content)
        {
            OpenGraphProductGroup openGraphContent = content.ToOpenGraphProductGroup();

            return(openGraphContent == null
                       ? MvcHtmlString.Empty
                       : htmlHelper.OpenGraph(openGraphMetadata: openGraphContent));
        }
Ejemplo n.º 3
0
        public void AddToCart_WhenItemIsBundleAndContainsPackage_ShouldAddContainedPackageToCart()
        {
            var bundle = new BundleContent
            {
                ContentLink = new ContentReference(1),
                Code        = "bundlecode"
            };

            var bundleEntry1 = new BundleEntry
            {
                Parent   = new ContentReference(2),
                Quantity = 1
            };

            var variant1 = new VariationContent
            {
                Code        = "variant1code",
                ContentLink = bundleEntry1.Parent
            };

            var bundleEntry2 = new BundleEntry
            {
                Parent   = new ContentReference(3),
                Quantity = 2
            };

            var package = new PackageContent
            {
                Code        = "packagecode",
                ContentLink = bundleEntry2.Parent
            };

            _referenceConverterMock.Setup(x => x.GetContentLink(variant1.Code)).Returns(variant1.ContentLink);
            _referenceConverterMock.Setup(x => x.GetContentLink(package.Code)).Returns(package.ContentLink);
            _referenceConverterMock.Setup(x => x.GetContentLink(bundle.Code)).Returns(bundle.ContentLink);

            _relationRepositoryMock.Setup(x => x.GetChildren <BundleEntry>(bundle.ContentLink))
            .Returns(() => new List <BundleEntry> {
                bundleEntry1, bundleEntry2
            });

            _contentLoaderMock.Setup(x => x.Get <EntryContentBase>(bundle.ContentLink)).Returns(bundle);
            _contentLoaderMock.Setup(x => x.Get <EntryContentBase>(variant1.ContentLink)).Returns(variant1);
            _contentLoaderMock.Setup(x => x.Get <EntryContentBase>(package.ContentLink)).Returns(package);

            _subject.AddToCart(_cart, bundle.Code, 1);

            Assert.Equal(bundleEntry1.Quantity + bundleEntry2.Quantity, _cart.GetAllLineItems().Sum(x => x.Quantity));
        }
 /// <summary>
 /// Gets all bundle entries for a bundle
 /// </summary>
 /// <param name="bundleContent">The bundle content to use</param>
 /// <returns>Collection of bundle entry references</returns>
 public static IEnumerable <ContentReference> GetBundleEntries(this BundleContent bundleContent)
 {
     return(bundleContent.GetBundleEntries(_relationRepository.Service));
 }
#pragma warning restore 649

        /// <summary>
        /// Gets all bundle entries for a bundle
        /// </summary>
        /// <param name="bundleContent">The bundle content to use</param>
        /// <param name="relationRepository">The relation repository</param>
        /// <returns>Collection of bundle entry references</returns>
        public static IEnumerable <ContentReference> GetBundleEntries(this BundleContent bundleContent, IRelationRepository relationRepository)
        {
            return(relationRepository.GetChildren <BundleEntry>(bundleContent.ContentLink).Select(r => r.Child));
        }