public IOrderProcess GetProductRuleInstance(ProductType productType) { IOrderProcess orderRule; switch (productType) { case ProductType.PhysicalProduct: orderRule = new PhysicalProductRule(); break; case ProductType.Book: orderRule = new BookRule(); break; case ProductType.Membership: orderRule = new MembershipRule(); break; case ProductType.MembershipUpgrade: orderRule = new MembershipUpgradeRule(); break; case ProductType.Video: orderRule = new VideoRule(); break; default: orderRule = new NewProductRule(); break; } return(orderRule); }
private void ExecuteSaveCommand() { if (string.IsNullOrWhiteSpace(Host)) { return; } SqlHelper.Conn.Open(); var book = SqlHelper.First <BookRule>("Host = @host", new SqliteParameter("@host", Host)); if (book == null) { book = new BookRule(); } book.Host = Host; book.NameStart = NameStart; book.NameEnd = NameEnd; book.AuthorStart = AuthorStart; book.AuthorEnd = AuthorEnd; book.CoverStart = CoverStart; book.CoverEnd = CoverEnd; book.DescriptionStart = DescriptionStart; book.DescriptionEnd = DescriptionEnd; book.ListStart = ListStart; book.ListEnd = ListEnd; book.TitleStart = TitleStart; book.TitleEnd = TitleEnd; book.ContentStart = ContentStart; book.ContentEnd = ContentEnd; book.Save(); SqlHelper.Conn.Close(); }
/// <summary> /// 从源码里获取 book /// </summary> /// <param name="html"></param> /// <param name="rule"></param> /// <returns></returns> public static Book GetBook(string html, BookRule rule) { return(new Book() { Name = NarrowText(html, rule.TitleStart, rule.TitleEnd), Author = NarrowText(html, rule.AuthorStart, rule.AuthorEnd), Description = NarrowText(html, rule.DescriptionStart, rule.DescriptionEnd) }); }
static void Main(string[] args) { Order order = new Order(); string returnMessage = string.Empty; Console.WriteLine("Enter Order Type for Which Payment Done :\n" + "1 for Physical Product\n" + "2 for Book\n" + "3 for New Membership\n" + "4 for Upgrade MemberShip\n" + "5 for Membership OR Upgrade\n" + "6 For VideoLearning\n" + "7 for Physical Product OR Book\n"); int orderVal = int.Parse(Console.ReadLine()); order.OrderType = orderVal; switch (orderVal) { case 1: PhysicalProductRule phyProdRule = new PhysicalProductRule(); returnMessage = phyProdRule.ExecuteRule(order); break; case 2: BookRule bookRule = new BookRule(); returnMessage = bookRule.ExecuteRule(order); break; case 3: NewMembershipRule newMembership = new NewMembershipRule(); returnMessage = newMembership.ExecuteRule(order); break; case 4: UpgradeMemberShipRule upgradeMember = new UpgradeMemberShipRule(); returnMessage = upgradeMember.ExecuteRule(order); break; case 5: MembershipORUpgradeRule membershipORUpgrade = new MembershipORUpgradeRule(); returnMessage = membershipORUpgrade.ExecuteRule(order); break; case 6: VideoLearningRule videoLearning = new VideoLearningRule(); returnMessage = videoLearning.ExecuteRule(order); break; case 7: PhysicalProductORBookRule physicalProductORBookRule = new PhysicalProductORBookRule(); returnMessage = physicalProductORBookRule.ExecuteRule(order); break; } Console.WriteLine("{0}", returnMessage); Console.Read(); }
public List <TypeOfActionAgainstRule> ExcuteRule(TypeOfRuleEnum rule) { var video = new VideoRule(null, rule); var newMemberShip = new NewMemberShip(video, rule); var upgradeMemberShip = new UpgradeMemberShip(newMemberShip, rule); var book = new BookRule(upgradeMemberShip, rule); var ruleChain = new PhysicalProductRule(book, rule); return(ruleChain.VerifyRuleAndProcess()); }
/// <summary> /// 根据目录网址获取章节 /// </summary> /// <param name="url"></param> /// <param name="rule"></param> /// <returns></returns> public static async Task <BookChapter> GetChapterAsync(string url, BookRule rule) { var html = await HttpHelper.GetAsync(url); return(new BookChapter() { Name = NarrowText(html, rule.TitleStart, rule.TitleEnd), Content = HtmlToText(NarrowText(html, rule.ContentStart, rule.ContentEnd)), Url = url }); }
public void SatifyIfItemTypeBook() { var item = new Item { Id = 1, ItemType = ItemType.Book, Name = "Some Book" }; var bookRule = new BookRule(); var actual = bookRule.IsApplicable(item); Assert.True(actual); }
public void GeneratesACommissionForAgent() { var item = new Item { Id = 1, ItemType = ItemType.Book, Name = "someProduct" }; var rule = new BookRule(); var actual = rule.Apply(item); Assert.Contains("Commission payment generated for Agent", actual.Activity); }
public void GeneratesAPackageSlipForShipping() { var item = new Item { Id = 1, ItemType = ItemType.Book, Name = "someProduct" }; var rule = new BookRule(); var actual = rule.Apply(item); Assert.Contains("Duplicate Slip generated for Royalty Dept", actual.Activity); }
public void ApplicationReturnsARuleLog() { var item = new Item { Id = 1, ItemType = ItemType.Book, Name = "someProduct" }; var rule = new BookRule(); var actual = rule.Apply(item); Assert.IsType(typeof(RuleLog), actual); Assert.Equal("Book Rule", actual.RuleName); }
public void ApplysForBook() { var item = new Item { Id = 1, ItemType = ItemType.Book, Name = "someProduct" }; var rule = new BookRule(); var actual = rule.Apply(item); Assert.NotNull(actual); Assert.IsType(typeof(RuleLog), actual); }
public void Add_Book_Rule() { Payment payment = new Payment(); payment.PaymentType = Enum_PaymentType.PhysicalProduct; payment.ProductName = "Harry Potter Book"; payment.IsBook = true; IRule rule = new BookRule(); ruleManager.AddRule(rule); var ruleResult = ruleManager.ExecuteRules(payment); bool isBookRuleApplied = ruleResult.Contains("Packing Slip for Royalty Department"); Assert.IsTrue(isBookRuleApplied); }
private int CheckRuleInserted(string key, EfRepository <BookRule> bookruleContext) { int inserted = -1; var keyCheck = (from k in bookruleContext.Table where k.Name == key select k).FirstOrDefault(); if (keyCheck == null) { BookRule bookRule = new BookRule(); bookRule.Name = key; bookruleContext.Insert(bookRule); inserted = bookRule.Id; } else { inserted = keyCheck.Id; } return(inserted); }
public void Add_Book_And_Physical_Rule() { Payment payment = new Payment(); payment.PaymentType = Enum_PaymentType.PhysicalProduct; payment.ProductName = "Harry Potter Book"; payment.IsBook = true; IRule rule = new BookRule(); ruleManager.AddRule(rule); // Both rule so that both rules will be added to rule result; rule = new PhysicalProductRule(); ruleManager.AddRule(rule); var ruleResult = ruleManager.ExecuteRules(payment); bool isBookRuleApplied = ruleResult.Contains("Packing Slip for Royalty Department"); Assert.IsTrue(isBookRuleApplied); bool isPhysicalRuleApplied = ruleResult.Contains("Generate Packing Slip"); Assert.IsTrue(isPhysicalRuleApplied); }
/// <summary> /// 下载直接保存不返回 /// </summary> /// <param name="html"></param> /// <param name="book"></param> /// <param name="rule"></param> /// <returns></returns> public static async Task GetBookChapterAsync(string html, Book book, BookRule rule) { var i = 1; html = NarrowText(html, rule.ListStart, rule.ListEnd); var matches = Regex.Matches(html, @"<a[^<>]+?href=""?(?<href>[^""<>\s]+)[^<>]*>(?<title>[\s\S]+?)</a>"); foreach (Match match in matches) { var chapter = await GetChapterAsync(HttpHelper.GetAbsolute(book.Url, match.Groups["href"].Value), rule); if (string.IsNullOrWhiteSpace(chapter.Name)) { chapter.Name = match.Groups["title"].Value; } chapter.BookId = book.Id; chapter.Position = i; chapter.Save(); i++; } book.Count = i - 1; book.Save(); }
/// <summary> /// 根据目录代码获取章节 /// </summary> /// <param name="html"></param> /// <param name="baseUrl"></param> /// <param name="rule"></param> /// <returns></returns> public static async Task <List <BookChapter> > GetBookChapterAsync(string html, string baseUrl, BookRule rule) { return(await GetBookChapterAsync(html, new Uri(baseUrl), rule)); }
public static async Task <List <BookChapter> > GetBookChapterAsync(string html, Uri baseUrl, BookRule rule) { var chapters = new List <BookChapter>(); html = NarrowText(html, rule.ListStart, rule.ListEnd); var matches = Regex.Matches(html, @"<a[^<>]+?href=""?(?<href>[^""<>\s]+)[^<>]*>(?<title>[\s\S]+?)</a>"); foreach (Match match in matches) { var chapter = await GetChapterAsync(HttpHelper.GetAbsolute(baseUrl, match.Groups["href"].Value), rule); if (string.IsNullOrWhiteSpace(chapter.Name)) { chapter.Name = match.Groups["title"].Value; } chapters.Add(chapter); } return(chapters); }
public BookRuleTest() { mockPackingSlip = new Mock <IPackingSlip>(); mockCommission = new Mock <ICommission>(); bookRule = new BookRule(); }
public static async Task <List <BookChapter> > GetBookChapterAsync(string url, BookRule rule) { var html = await HttpHelper.GetAsync(url); return(await GetBookChapterAsync(html, url, rule)); }