Example #1
0
        public void AddDeal(DealModel deal)
        {
            if (Deals.Contains(deal))
            {
                throw new InvalidOperationException("Deal already exist.");
            }

            Deals.Add(deal);
        }
Example #2
0
        public static CartItemModel Create(
            DealModel deal,
            DealOptionModel dealOption,
            List<DealAttributeModel> selectedAttributeValues)
        {
            var cartItemModel = new CartItemModel
            {
                Deal = deal,
                DealOption = dealOption,
                Quantity = 1
            };

            foreach (var attr in selectedAttributeValues)
            {
                cartItemModel.attributeValues.Add(attr);
            }

            cartItemModel.Key = Guid.NewGuid().ToString();

            return cartItemModel;
        }
Example #3
0
        public static CartItemModel CreateCartItem(
            DealModel deal = null,
            DealOptionModel dealOption = null,
            List<DealAttributeModel> dealAttributes = null)
        {
            if (deal == null && dealOption == null)
            {
                deal = CreateCompleteDeal();
                dealOption = deal.Options.First();
            }

            if (dealAttributes == null)
            {
                dealAttributes = new List<DealAttributeModel>();
                foreach (var attr in dealOption.Attributes)
                {
                    dealAttributes.Add(attr);
                }
            }

            return CartItemModel.Create(deal, dealOption, dealAttributes);
        }
Example #4
0
 private static void AssertModelEqualityWithDeal(
     CartItemViewModel viewModel,
     CartItemModel domainModel,
     DealModel dealModel)
 {
     viewModel.DealId.ShouldBeEquivalentTo(dealModel.Key);
     viewModel.DealThumbnailUrl.ShouldBeEquivalentTo(dealModel.Images.OrderBy(a => a.Order).First().RelativeUrl);
     viewModel.DealUrl.ShouldBeEquivalentTo(dealModel.CanonicalUrl);
     viewModel.Id.ShouldBeEquivalentTo(domainModel.Key);
 }
Example #5
0
 private bool Equals(DealModel other)
 {
     return Equals(options, other.options) && Equals(images, other.images) && string.Equals(ShortTitle, other.ShortTitle) && string.Equals(LongTitle, other.LongTitle) && string.Equals(ShortDescription, other.ShortDescription) && string.Equals(LongDescription, other.LongDescription) && RegularPrice.Equals(other.RegularPrice) && string.Equals(SKU, other.SKU) && DateAdded.Equals(other.DateAdded) && SpecialPrice.Equals(other.SpecialPrice) && StartTime.Equals(other.StartTime) && IsFeatured.Equals(other.IsFeatured) && string.Equals(CanonicalUrl, other.CanonicalUrl) && Equals(Key, other.Key) && Status == other.Status && string.Equals(Highlight, other.Highlight) && string.Equals(FinePrint, other.FinePrint) && EndTime.Equals(other.EndTime);
 }
Example #6
0
 private static string GenerateSKU(DealModel deal)
 {
     return RemoveSpecialCharacters(string.Concat(deal.ShortTitle, Guid.NewGuid().ToString()));
 }
Example #7
0
        private static string GenerateCanonicalUrl(DealModel deal)
        {
            var shortTitleWithPlaceholder = deal.ShortTitle.Replace(" ", "spaceplaceholder1");
            shortTitleWithPlaceholder += Guid.NewGuid().ToString();

            return RemoveSpecialCharacters(shortTitleWithPlaceholder).Replace("spaceplaceholder1", "-");
        }
Example #8
0
        public static DealModel Create(
            string shortTitle,
            string shortDescription,
            string longTitle,
            string longDescription,
            string finePrint,
            string highlight,
            DealType dealType)
        {
            var deal = new DealModel
            {
                ShortTitle = shortTitle,
                ShortDescription = shortDescription,
                LongTitle = longTitle,
                LongDescription = longDescription,
                FinePrint = finePrint,
                Highlight = highlight,
                DateAdded = DateTime.UtcNow,
                StartTime = DateTime.UtcNow,
                EndTime = DateTime.UtcNow.AddDays(7),
                IsFeatured = false,
                RegularPrice = 0,
                SpecialPrice = 0,
                Status = DealStatus.Draft,
                Key = Guid.NewGuid().ToString(),
                DealType = dealType
            };

            deal.CanonicalUrl = GenerateCanonicalUrl(deal);
            deal.SKU = GenerateSKU(deal);

            return deal;
        }
Example #9
0
        private static void AssertFrontEndSpecificDealEquality(FrontEndSpecificDeal deal, DealModel matchingDeal)
        {
            deal.Id.Should().BeEquivalentTo(matchingDeal.Key.ToString());
            deal.Fineprint.Should().BeEquivalentTo(matchingDeal.FinePrint);
            deal.Highlight.Should().BeEquivalentTo(matchingDeal.Highlight);

            deal.ShortTitle.Should().BeEquivalentTo(matchingDeal.ShortTitle);
            deal.ShortDescription.Should().BeEquivalentTo(matchingDeal.ShortDescription);
            deal.LongTitle.Should().BeEquivalentTo(matchingDeal.LongTitle);
            deal.LongDescription.Should().BeEquivalentTo(matchingDeal.LongDescription);

            deal.RegularPrice.Should().Be(matchingDeal.RegularPrice);
            deal.SpecialPrice.Should().Be(matchingDeal.SpecialPrice);
            deal.StartTime.Should().Be(matchingDeal.StartTime);
            deal.EndTime.Should().Be(matchingDeal.EndTime);

            matchingDeal.Images.Count().ShouldBeEquivalentTo(deal.ImageUrls.Count);
            foreach (var image in matchingDeal.Images)
            {
                Assert.IsTrue(deal.ImageUrls.Any(a => a.Contains(image.RelativeUrl)), string.Format("Image {0} is not found.", image.RelativeUrl));
            }

            foreach (var option in matchingDeal.Options)
            {
                var matchingOption =
                    deal.DealOptions.First(
                        d =>
                            d.ShortTitle.Equals(option.ShortTitle) && d.RegularPrice.Equals(option.RegularPrice) &&
                            d.SpecialPrice.Equals(option.SpecialPrice));

                foreach (var attribute in option.Attributes)
                {
                    Assert.IsTrue(matchingOption.DealAttributes.Any(att => attribute.Name.Equals(att.Name) && attribute.Value.Equals(att.Value)));
                }
            }
        }
Example #10
0
        private static void AssertFrontEndDealEquality(FrontEndDeal deal, DealModel matchingDeal)
        {
            deal.EndTime.Should().Be(matchingDeal.EndTime);
            deal.ShortTitle.Should().BeEquivalentTo(matchingDeal.ShortTitle);
            deal.ShortDescription.Should().BeEquivalentTo(matchingDeal.ShortDescription);
            deal.RegularPrice.Should().Be(matchingDeal.RegularPrice);
            deal.SpecialPrice.Should().Be(matchingDeal.SpecialPrice);
            deal.CanonicalUrl.Should().BeEquivalentTo(matchingDeal.CanonicalUrl);

            foreach (var image in matchingDeal.Images)
            {
                var extension = Path.GetExtension(image.RelativeUrl);
                var thumbPostfix = "_thumb" + extension;
                var thumbUrl = image.RelativeUrl.Replace(extension, thumbPostfix);

                Assert.IsTrue(deal.ThumbnailUrls.Any(d => d.EndsWith(thumbUrl)));
            }
        }
Example #11
0
 public void RemoveDeal(DealModel deal)
 {
     Deals.Remove(deal);
 }