static void Main(string[] args) { Console.WriteLine("Chain of Responsibility"); Console.WriteLine("Fashion Shop Example"); var discountApplier = new DiscountApplier(); AddDiscounts(discountApplier); var shirt = new Shirt(discountApplier, 10m); var jeans = new Jeans(discountApplier, 30m); var sunglasses = new Sunglasses(discountApplier, 35m); PrintPrice(); void PrintPrice() { var sw = new Stopwatch(); sw.Start(); while (sw.ElapsedMilliseconds < 20000) { Console.SetCursorPosition(0, 3); Console.WriteLine($"\r{shirt._name} price: $ {shirt.Price} "); Console.WriteLine($"\r{jeans._name} price: $ {jeans.Price} "); Console.WriteLine($"\r{sunglasses._name} price: $ {sunglasses.Price} "); Thread.Sleep(500); } sw.Stop(); } }
public void Should_notify_user_when_apply_discount() { List <User> users = new List <User> { new User() }; var notifier = new VerifyNotifier();; DiscountApplier discountApplier = new DiscountApplier(notifier, users); var item = new Item(); discountApplier.Apply(item, 20); Assert.IsTrue(notifier.IsCalledForAll(users)); }
public void Should_notify_user_when_apply_discount() { List <User> users = new List <User> { new User(), new User() }; var notifier = Substitute.For <INotifier>(); DiscountApplier discountApplier = new DiscountApplier(notifier, users); var item = new Item(); discountApplier.Apply(item, 20); users.ForEach( user => notifier.Received().Notify(user)); }
private static void AddDiscounts(DiscountApplier discountApplier) { var firstPurchaseDiscount = new FirstPurchaseDiscount(discountApplier); firstPurchaseDiscount.Add(); var flashSale = new FlashSale(discountApplier, 5000); flashSale.Add(); var dailySale = new DailySale(discountApplier); dailySale.Add(); }
public void Should_Notify_twice_when_having_two_users_to_notify() { List <User> users = new List <User> { new User(), new User() }; var notifier = Substitute.For <INotifier>(); DiscountApplier discountApplier = new DiscountApplier(notifier, users); var item = new Item(); discountApplier.Apply(item, 20); notifier.Received(users.Count).Notify(Arg.Any <User>()); }
public void Should_Notify_twice_when_having_two_users_to_notify() { List <User> users = new List <User> { new User(), new User() }; var notifier = new CounterNotifier();; DiscountApplier discountApplier = new DiscountApplier(notifier, users); var item = new Item(); discountApplier.Apply(item, 20); Assert.AreEqual(users.Count, notifier.CallCount); }
public void TestProperyPatternAgainstOldStyleCode() { ZonalClient[] clients = new[] { new ZonalClient { Purchases = 141, Zone = Zones.Z2, Company = Companies.C1 }, new ZonalClient { Purchases = 14, Zone = Zones.Z3, Company = Companies.C2 }, new ZonalClient { Purchases = 400, Zone = Zones.Z2, Company = Companies.C3 }, new ZonalClient { Purchases = 600, Zone = Zones.Z3, Company = Companies.C2 }, new ZonalClient { Purchases = 55, Zone = Zones.Z1, Company = Companies.C1 } }; var applier = new DiscountApplier(); Assert.All(clients, c => Assert.Equal(applier.OldStyle(c), applier.PropertyPattern(c))); }
public Sunglasses(DiscountApplier discountApplier, decimal price) : base(discountApplier) { _price = price; _name = ItemNames.Sunglasses; }
public Shirt(DiscountApplier discountApplier, decimal price) : base(discountApplier) { _price = price; _name = ItemNames.Shirt; }
public Jeans(DiscountApplier discountApplier, decimal price) : base(discountApplier) { _price = price; _name = ItemNames.Jeans; }
public Item(DiscountApplier discountApplier) { _discountApplier = discountApplier; }