public void DbDiscountTest() { var dbDiscount = new DbDiscount { RatingUsersId = new List <string>() }; dbDiscount.RatingUsersId.Should().NotBeNull(); }
/// <summary> /// Updates tags from discount. /// </summary> /// <param name="dbDiscount"></param> /// <returns></returns> public async Task UpdateTags(DbDiscount dbDiscount) { if (dbDiscount == null) { return; } if (!dbDiscount.Tags.IsNullOrEmpty()) { var tagTranslations = dbDiscount.Tags.Select(dbDiscountTag => new TagTranslations { TagName = dbDiscountTag, Language = dbDiscount.Language }).ToList(); await UpsertTags(tagTranslations, tag => Builders <DbTag> .Update .Set(f => f.Name, tag.TagName) .Set(f => f.Language, tag.Language)); } if (!dbDiscount.Translations.IsEmpty()) { var tagOtherTranslations = new List <TagTranslations>(); foreach (var dbDiscountTranslation in dbDiscount.Translations) { var tags = dbDiscountTranslation.Tags; if (tags.IsNullOrEmpty()) { continue; } foreach (var tag in tags) { tagOtherTranslations.Add(new TagTranslations { TagName = tag, Language = dbDiscountTranslation.Language }); } } if (tagOtherTranslations.Count == 0) { return; } await UpsertTags(tagOtherTranslations, tag => Builders <DbTag> .Update .Set(f => f.Name, tag.TagName) .Set(f => f.Translations, new List <DbTag> { new() { Name = tag.TagName, Language = tag.Language } }));
public void ToDiscountInvalidGuidTest() { var dbDiscount = new DbDiscount() { Id = "invalid", Language = LanguageOption.En.ToString() }; dbDiscount.ToDiscount().Should().BeEquivalentTo(new Discount() { Id = Guid.Empty, Language = LanguageOption.Ru, }); }
/// <summary> /// Gets Discount entity from DbDiscount entity. /// </summary> /// <param name="value"></param> /// <returns></returns> public static Discount ToDiscount(this DbDiscount value) { if (value.IsEmpty()) { return(new Discount()); } try { return(new Discount { Id = new Guid(value.Id), Name = value.Name, Description = value.Description, AmountOfDiscount = value.AmountOfDiscount, StartDate = value.StartDate, EndDate = value.EndDate, Address = value.Address.ToAddress(), Company = value.Company.ToCompany(), WorkingDaysOfTheWeek = value.WorkingDaysOfTheWeek, Tags = value.Tags, PictureUrl = value.PictureUrl, Language = value.Language.ToLanguageOption(), Translations = value.Translations.ToTranslations(), RatingTotal = value.RatingTotal, ViewsTotal = value.ViewsTotal, SubscriptionsTotal = value.SubscriptionsTotal, UsersSubscriptionTotal = value.UsersSubscriptionTotal, FavoritesUsersId = value.FavoritesUsersId, UsersPromocodes = value.UsersPromocodes.ToUsersPromocodes(), PromocodeOptions = value.PromocodeOptions.ToPromocodeOptions(), CreateDate = value.CreateDate, LastChangeDate = value.LastChangeDate, UserCreateDate = value.UserCreateDate.ToUser(), UserLastChangeDate = value.UserLastChangeDate.ToUser(), Deleted = value.Deleted }); } catch { return(new Discount()); } }
public void ToDiscountTest() { var dbDiscount = new DbDiscount() { Id = "76c6f30b-288b-4424-b031-21921e550cba", Language = LanguageOption.En.ToString(), UsersPromocodes = new List <DbUserPromocodes>() }; dbDiscount.ToDiscount().Should().BeEquivalentTo(new Discount() { Id = Guid.Parse("76c6f30b-288b-4424-b031-21921e550cba"), Language = LanguageOption.En, UserCreateDate = new User(), UserLastChangeDate = new User(), UsersPromocodes = null }); }
public void ToDiscountFreeTest() { var dbDiscount = new DbDiscount(); dbDiscount.ToDiscount().Should().BeEquivalentTo(new Discount()); }
public void IsEmptyTest() { var dbDiscount = new DbDiscount(); dbDiscount.IsEmpty().Should().BeTrue(); }
/// <summary> /// Gets true when the DbDiscount entity or id property is Null or Empty otherwise false. /// </summary> /// <param name="value"></param> /// <returns></returns> public static bool IsEmpty(this DbDiscount value) => value == null || value.Id.IsNullOrEmpty();