public void AddDeal(DealModel deal) { if (Deals.Contains(deal)) { throw new InvalidOperationException("Deal already exist."); } Deals.Add(deal); }
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; }
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); }
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); }
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); }
private static string GenerateSKU(DealModel deal) { return RemoveSpecialCharacters(string.Concat(deal.ShortTitle, Guid.NewGuid().ToString())); }
private static string GenerateCanonicalUrl(DealModel deal) { var shortTitleWithPlaceholder = deal.ShortTitle.Replace(" ", "spaceplaceholder1"); shortTitleWithPlaceholder += Guid.NewGuid().ToString(); return RemoveSpecialCharacters(shortTitleWithPlaceholder).Replace("spaceplaceholder1", "-"); }
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; }
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))); } } }
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))); } }
public void RemoveDeal(DealModel deal) { Deals.Remove(deal); }