public void GetUrl_WhenVariationHasNoCode_ShouldReturnBaseUrl()
        {
            var variant = new VariationContent();

            var result = variant.GetUrl(_relationRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal <string>(_url, result);
        }
        public void GetUrl_WhenVariationHasCode_ShouldReturnUrlWithQuery()
        {
            var variant = new VariationContent {
                Code = "code"
            };

            var result = variant.GetUrl(_relationRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal <string>(_url + "?variationCode=" + variant.Code, result);
        }
        public void GetUrl_WhenNoRelationExists_ShouldReturnEmptyString()
        {
            _relationRepositoryMock
            .Setup(x => x.GetParents <ProductVariation>(It.IsAny <ContentReference>()))
            .Returns(Enumerable.Empty <ProductVariation>());

            var variant = new VariationContent();

            var result = variant.GetUrl(_relationRepositoryMock.Object, _urlResolverMock.Object);

            Assert.Equal <string>(string.Empty, result);
        }
 /// <summary>
 /// Converts the <param name="content"></param> to an <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphProductItem"/>.
 /// </summary>
 /// <param name="content">The content.</param>
 /// <param name="openGraphCondition">The open graph condition.</param>
 /// <returns>The <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphProductItem"/> 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.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.NotSupportedException">The query collection is read-only.</exception>
 /// <exception cref="T:System.ArgumentNullException">Parent products are <see langword="null" />.</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 OpenGraphProductItem ToOpenGraphProductItem(
     this VariationContent content,
     OpenGraphCondition openGraphCondition)
 {
     return(new OpenGraphProductItem(
                title: content.DisplayName,
                new OpenGraphImage(content.GetDefaultAsset <IContentMedia>()),
                content.GetOpenGraphAvailability(),
                condition: openGraphCondition,
                content.GetOpenGraphCurrencies(),
                retailerItemId: content.Code,
                content.GetUrl()));
 }
Exemplo n.º 5
0
        private ProductViewModel CreateProductViewModel(ProductContent product, VariationContent variation)
        {
            if (variation == null)
            {
                return(null);
            }

            ContentReference productContentReference;

            if (product != null)
            {
                productContentReference = product.ContentLink;
            }
            else
            {
                productContentReference = variation.GetParentProducts(_relationRepository).FirstOrDefault();
                if (ContentReference.IsNullOrEmpty(productContentReference))
                {
                    return(null);
                }
            }
            var market   = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            var originalPrice   = _pricingService.GetCurrentPrice(variation.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(variation, market, currency, originalPrice.Value) : (Money?)null;

            var image = variation.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return(new ProductViewModel
            {
                DisplayName = product != null ? product.DisplayName : variation.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = variation.GetUrl(),
                Brand = brand,
                IsAvailable = originalPrice.HasValue
            });
        }
Exemplo n.º 6
0
        private ProductViewModel CreateProductViewModel(ProductContent product, VariationContent variation)
        {
            if (variation == null)
            {
                return null;
            }

            ContentReference productContentReference;
            if (product != null)
            {
                productContentReference = product.ContentLink;
            }
            else
            {
                productContentReference = variation.GetParentProducts(_relationRepository).FirstOrDefault();
                if (ContentReference.IsNullOrEmpty(productContentReference))
                {
                    return null;
                }
            }
            var market = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            var originalPrice = _pricingService.GetCurrentPrice(variation.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(variation, market, currency, originalPrice.Value) : (Money?)null;

            var image = variation.GetAssets<IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return new ProductViewModel
            {
                DisplayName = product != null ? product.DisplayName : variation.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = variation.GetUrl(),
                Brand = brand,
                IsAvailable = originalPrice.HasValue
            };
        }