static void Main(string[] args) { //bronze card ICart bronzeShopCart = new StoreCart(); IItem remote = new Item("LG", 150); CardHolder cardHolderBronze = new CardHolder("Anthony", "Hopkins"); bronzeShopCart.AddItem(remote); IDiscountCard bronzeCard = new BronzeCard(0, cardHolderBronze); string billBronze = CashDesk.Pay(bronzeShopCart, bronzeCard); Console.WriteLine(billBronze + Environment.NewLine); //silver card ICart silverShopCart = new StoreCart(); IItem playStation = new Item("PlayStation 5", 850); silverShopCart.AddItem(playStation); CardHolder cardHolderSilver = new CardHolder("Jake", "Gyllenhaal"); IDiscountCard silverCard = new SilverCard(600, cardHolderSilver); string billSilver = CashDesk.Pay(silverShopCart, silverCard); Console.WriteLine(billSilver + Environment.NewLine); //gold car ICart goldShopCart = new StoreCart(); goldShopCart.AddItem(new Item("Toy", 300)); goldShopCart.AddItem(new Item("Cooker", 700)); goldShopCart.AddItem(new Item("Pack-man", 300)); CardHolder cardHolderGold = new CardHolder("Christian", "Bale"); IDiscountCard goldenCard = new GoldCard(1300, cardHolderGold); string billGold = CashDesk.Pay(goldShopCart, goldenCard); Console.WriteLine(billGold + Environment.NewLine); Console.ReadLine(); }
public void TestNameTest(double balance, int year, double expected) { var goldCard = new GoldCard("", "", balance, year); double calcCouponValue = goldCard.CalcCouponValue(); Assert.AreEqual(expected, calcCouponValue); }
public static void Main() { Card.Card bronze = new BronzeCard(0); try { bronze.PrintResult(150); } catch (ImpossiblePurchase e) { Console.WriteLine(e); } Card.Card silver = new SilverCard(600); try { silver.PrintResult(850); } catch (ImpossiblePurchase e) { Console.WriteLine(e); } Card.Card gold = new GoldCard(1500); try { gold.PrintResult(1300); } catch (ImpossiblePurchase e) { Console.WriteLine(e); } }
// add more test cases so all rules are defined public void CalcCouponValue_should_calculate_correctly(double balance, double year, double expectedResult) { // arrange your test (sut == system under test) var sut = new GoldCard(null, null, balance, year); // act (execute the test) var actualResult = sut.CalcCouponValue(); // assert (verify that what you get is what you want) Assert.That(actualResult, Is.EqualTo(expectedResult); }
void AddCardData() { cards = new Card[6]; cards[0] = new GoldCard(); cards[1] = new AttackCard(); cards[2] = new MovementCard(); cards[3] = new TeleportCard(); cards[4] = new VisionCard(); cards[5] = new WallBreakCard(); }
private void Expore(ActionCard actionCard, GoldCard cardToOpen) { _client.SendMessage(new ExploreMessage { CardId = actionCard.Id, Coordinates = cardToOpen.Coordinates, SenderId = CurrentPlayer.Id, RoleType = CurrentPlayer.Role.Role }); }
static void Main(string[] args) { ISample sample1 = new Sample1(); sample1.SayHello("小明"); ISample sample2 = new Sample2(); sample2.SayHello("Mike"); ISample sample3 = new Sample3(); sample3.SayHello("山本桑"); Console.WriteLine("==== new 关键字 测试 ==="); AbstractSample sample3a = new Sample3(); sample3a.SayHello("山本桑"); sample3a.SayEnd(); Sample3 sample3b = new Sample3(); sample3b.SayHello("山本桑"); sample3b.SayEnd(); Console.WriteLine("==== override 与 new 的区别 ==="); Console.WriteLine("卡=普通卡!"); Card card1 = new NormalCard(); card1.LineUp(); card1.TakeMoney(); Console.WriteLine("卡=金卡!"); Card card2 = new GoldCard(); card2.LineUp(); card2.TakeMoney(); Console.WriteLine("金卡=金卡!"); GoldCard card3 = new GoldCard(); card3.LineUp(); card3.TakeMoney(); Console.ReadLine(); }
//[ExpectedException(typeof(ArgumentOutOfRangeException))] public void GivenGoldCard_WhenConstructingWithDiscountOutOfRange_ThenShouldThrow(int discount) { int cardId = 1; string name = "Customer1"; string address = "Address1"; string city = "City1"; decimal credit = 100; Assert.ThrowsException <ArgumentOutOfRangeException>(() => { GoldCard card = new GoldCard(cardId, name, address, city, credit, (decimal)discount); }); }
static void Main(string[] args) { Card bronze, silver, gold; bronze = new BronzeCard("Mickey", "Pierce", 1234, 0); silver = new SilverCard("Chandler", "Bing", 2345, 600); gold = new GoldCard("Marge", "Simpson", 3456, 1500); PayDesk.MakePayment(bronze, 150); PayDesk.MakePayment(silver, 850); PayDesk.MakePayment(gold, 1300); }
public void GoldCardMayHaveNegativeCredit() { int cardId = 1; string name = "Customer1"; string address = "Address1"; string city = "City1"; decimal credit = 100; decimal toPay = credit + 1000; decimal discount = 10; GoldCard card = new GoldCard(cardId, name, address, city, credit, discount); card.Pay(toPay); Assert.IsTrue(card.Credit < 0); }
protected override void Load(ContainerBuilder builder) { // this example taken as is from the Autofac wiki http://code.google.com/p/autofac/wiki/ComponentCreation builder.Register <CreditCard>((c, p) => { var result = new GoldCard("1"); if (p.Any()) { result.SomeProperty = "X"; } return(result); }); }
static void Main() { Console.WriteLine("Hello user, please enter your name:\n"); string name = Console.ReadLine(); Console.WriteLine($"Hello {name}, what card do you have?:\n1. Bronze\n2. Silver\n3. gold"); int idCard = Convert.ToInt32(Console.ReadLine()); double lastMonth; Console.WriteLine($"Hello {name}, how much did you spend last month?"); lastMonth = Convert.ToDouble(Console.ReadLine()); double price; switch (idCard) { case 1: BronzeCard karticaB = new BronzeCard(name, lastMonth); Console.WriteLine($"Okey {name}, we made you a card\nI hear you want to make a purchuse, how much is your total?"); price = Convert.ToDouble(Console.ReadLine()); karticaB.CalculateDiscount(); karticaB.makePurchase(price); break; case 2: SilverCard karticaS = new SilverCard(name, lastMonth); Console.WriteLine($"Okey {name}, we made you a card\nI hear you want to make a purchuse, how much is your total?"); price = Convert.ToDouble(Console.ReadLine()); karticaS.CalculateDiscount(); karticaS.makePurchase(price); break; case 3: GoldCard karticaG = new GoldCard(name, lastMonth); Console.WriteLine($"Okey {name}, we made you a card\nI hear you want to make a purchuse, how much is your total?"); price = Convert.ToDouble(Console.ReadLine()); karticaG.CalculateDiscount(); karticaG.makePurchase(price); break; default: break; } }
static void Main(string[] args) { var owner = new Owner("Dimitar", "Vasilev"); var bronzeCard = new BronzeCard(owner, 0); var secondOwner = new Owner("Ivan", "Ivanov"); var silverCard = new SilverCard(secondOwner, 600); var thirdOwner = new Owner("Desislava", "Vasileva"); var goldCard = new GoldCard(thirdOwner, 1500); PayDesk.Checkout(bronzeCard, 150); PayDesk.Checkout(silverCard, 850); PayDesk.Checkout(goldCard, 1300); }
public void GoldCard_WhenPaying_DiscountIsConsidered() { int cardId = 1; string name = "Customer1"; string address = "Address1"; string city = "City1"; decimal credit = 100; decimal toPay = 10; decimal discount = 10; decimal expectedToPay = toPay - (toPay * discount / 100); decimal expectedCredit = credit - expectedToPay; GoldCard card = new GoldCard(cardId, name, address, city, credit, discount); card.Pay(toPay); Assert.AreEqual(expectedCredit, card.Credit); }
static void Main() { try { var bronzeCard = new BronzeCard("George", 0); var silverCard = new SilverCard("Jenny", 600); var goldCard = new GoldCard("Peter", 1500); PayDesk.CalculatePurchaseInfo(bronzeCard, 150); PayDesk.CalculatePurchaseInfo(silverCard, 850); PayDesk.CalculatePurchaseInfo(goldCard, 1300); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static List <GoldCard> SetGoldCards(IGameSet gameSet, List <GoldCard> goldCards) { var shuffledCards = ShuffleCards(new List <Card>(goldCards)); var result = new List <GoldCard>(); foreach (var coordinate in gameSet.GoldCardCoordinates) { GoldCard card = (GoldCard)shuffledCards.Dequeue(); card.Coordinates = coordinate; card.GoldImage = card.ImagePath; card.ImagePath = ImagePaths.GoldBack; result.Add(card); } return(result); }
public void GivenANewGoldCard_WhenCreated_ThenTheCardRecordsCustomerNameAddressCityCustomerIdCredit() { int cardId = 1; string name = "Customer1"; string address = "Address1"; string city = "City1"; decimal credit = 100; decimal discount = 1; GoldCard card = new GoldCard(cardId, name, address, city, credit, discount); Assert.AreEqual(cardId, card.Id); Assert.AreEqual(name, card.CustomerName); Assert.AreEqual(address, card.CustomerAddress); Assert.AreEqual(city, card.CustomerCity); Assert.AreEqual(credit, card.Credit); Assert.AreEqual(discount, card.Discount); }
public static void main() { Cardholder cardholder = new Cardholder("Sigizmund", "Krzhizhanovsky"); Card card = new BronzeCard(cardholder); printInvoice(150, card); cardholder = new Cardholder("Julio", "Cortazar"); card = new SilverCard(cardholder); card.setTurnover(600); printInvoice(850, card); cardholder = new Cardholder("Hermann", "Hesse"); card = new GoldCard(cardholder); card.setTurnover(1500); printInvoice(1300, card); }
private static void TestingData() { Owner owner = new Owner("John", "Smith"); Console.WriteLine("Bronze Card test:"); var bronzeCard = new BronzeCard(0, owner); PayDesk.PrintInformation(bronzeCard, 150); Console.WriteLine("Silver Card test:"); var silverCard = new SilverCard(600, owner); PayDesk.PrintInformation(silverCard, 850); Console.WriteLine("Gold Card test:"); var goldCard = new GoldCard(1500, owner); PayDesk.PrintInformation(goldCard, 1300); }
static void Main(string[] args) { StudentAccount newStudentAccount = new StudentAccount("*****@*****.**", "Strada Posadei", "secret", Currency.EUR); Name name = new Name { firstName = "Mihai", lastName = "Nan" }; ICustomer Mihai = new Customer(name, newStudentAccount); ICard newCard = new GoldCard(name, CardService.MasterCard, "309"); newStudentAccount = new StudentAccount("*****@*****.**", "Strada Mihai Eminescu", "secret2", Currency.RON); name = new Name { firstName = "Andrei", lastName = "Lunca" }; ICustomer Lunca = new Customer(name, newStudentAccount); ICard newTitanCard = new TitanCard(name, CardService.Visa, "400"); Lunca.SelectAccount(0).AddCard(newTitanCard); Mihai.SelectAccount(0).AddCard(newCard); Mihai.SelectAccount(0).Deposit(100); Mihai.SelectAccount(0).Withdraw(50); Console.WriteLine(Mihai.SelectAccount(0).Balance); IAccount transferAccount = Lunca.SelectAccount(0); Mihai.SelectAccount(0).Transfer(20, transferAccount); Console.WriteLine(Mihai.SelectAccount(0).Balance); Customers.Add(Mihai); Customers.Add(Lunca); Menu.Welcome(); Menu.CreateAccount(); }
static void Main(string[] args) { var cashier = new Cashier(); var bronzeCard = new BronzeCard("Bronze", 0); var silverCard = new SilverCard("Silver", 600); var goldCard = new GoldCard("Gold", 1500); var receipts = new PurchaseInformaton[] { cashier.ProcessPurchase(150, bronzeCard), cashier.ProcessPurchase(850, silverCard), cashier.ProcessPurchase(1300, goldCard) }; foreach (var receipt in receipts) { Console.WriteLine(receipt); } }
protected override Card MakeProduct() { Card product = new GoldCard(); return(product); }
static void Main(string[] args) { //Generate cards List <ICard> myCards = new List <ICard>(); for (int i = 1; i < 9; i++) { for (int j = 1; j < 6; j++) { switch (j) { case 1: var red = new RedCard(i); myCards.Add(red); break; case 2: var blue = new BlueCard(i); myCards.Add(blue); break; case 3: var green = new GreenCard(i); myCards.Add(green); break; case 4: var yellow = new YellowCard(i); myCards.Add(yellow); break; case 5: var gold = new GoldCard(i); myCards.Add(gold); break; default: throw new InvalidOperationException("Suit is undefined!"); } } } Deck myDeck = new Deck(myCards); IGame myGame = new GameLowWin(myDeck); IPlayer player1 = new Player("player1"); IPlayer player2 = new Player("player2"); IPlayer player3 = new Player("player3"); IPlayer player4 = new PlayerWeak("player4"); IPlayer player5 = new PlayerWeak("player5"); myGame.AddPlayer(player1); myGame.AddPlayer(player2); myGame.AddPlayer(player3); myGame.AddPlayer(player4); myGame.AddPlayer(player5); myGame.DealAllPlayers(5); List <ICard> hand1 = player1.ShowHand(); List <ICard> hand2 = player2.ShowHand(); List <ICard> hand3 = player3.ShowHand(); List <ICard> hand4 = player4.ShowHand(); List <ICard> hand5 = player5.ShowHand(); Console.WriteLine("Hand for PLayer 1: "); foreach (var card in hand1) { Console.WriteLine($"{card.Suit} {card.Number}"); } Console.WriteLine("Hand for PLayer 2: "); foreach (var card in hand2) { Console.WriteLine($"{card.Suit} {card.Number}"); } Console.WriteLine("Hand for PLayer 3: "); foreach (var card in hand3) { Console.WriteLine($"{card.Suit} {card.Number}"); } Console.WriteLine("Hand for PLayer 4: "); foreach (var card in hand4) { Console.WriteLine($"{card.Suit} {card.Number}"); } Console.WriteLine("Hand for PLayer 5: "); foreach (var card in hand5) { Console.WriteLine($"{card.Suit} {card.Number}"); } Console.WriteLine("--------------------------------------------"); foreach (var player in myGame.Players) { Console.WriteLine($"Total value of {player.Name}'s hand is {player.TotalValue()}."); } Console.WriteLine("The winner(s):"); foreach (var winner in myGame.Winner()) { Console.Write($"{winner.Name}, "); } }
static void Main(string[] args) { #region Creational Patterns Calling #region Singleton //SingletonDemo SingletonObject = SingletonDemo.GetObject(); //SingletonObject.Print("Hello World"); //SingletonDemo SingletonObject1 = SingletonDemo.GetObject(); //SingletonObject1.Print("HELLO DUNYA"); //SingletonDemo SingletonObject2 = SingletonDemo.GetObject(); //SingletonObject2.Print("HELLO"); //Console.ReadLine(); #endregion #region Factory IPaymentCard card = null; Console.WriteLine("Please Select your card type"); string choice = Console.ReadLine(); switch (choice.ToLower()) { case "debit": card = new DebitCard(); PrintCardDetails(card); break; case "gold": card = new GoldCard(); PrintCardDetails(card); break; case "platinum": card = new PlatinumCard(); PrintCardDetails(card); break; default: card = null; PrintCardDetails(card); break; } #endregion #endregion #region Structural Patterns Calling #region Decorator ////Step 1: Define some dishes, and how many of each we can make //FreshSalad caesarSalad = new FreshSalad("Crisp romaine lettuce", "Freshly-grated Parmesan cheese", "House-made Caesar dressing"); //caesarSalad.Display(); //Pasta fettuccineAlfredo = new Pasta("Fresh-made daily pasta", "Creamly garlic alfredo sauce"); //fettuccineAlfredo.Display(); //Console.WriteLine("\nMaking these dishes available."); ////Step 2: Decorate the dishes; now if we attempt to order them once we're out of ingredients, we can notify the customer //Available caesarAvailable = new Available(caesarSalad, 3); //Available alfredoAvailable = new Available(fettuccineAlfredo, 4); ////Step 3: Order a bunch of dishes //caesarAvailable.OrderItem("John"); //caesarAvailable.OrderItem("Sally"); //caesarAvailable.OrderItem("Manush"); //alfredoAvailable.OrderItem("Sally"); //alfredoAvailable.OrderItem("Francis"); //alfredoAvailable.OrderItem("Venkat"); //alfredoAvailable.OrderItem("Diana"); //alfredoAvailable.OrderItem("Dennis"); //There won't be enough for this order. //caesarAvailable.Display(); //alfredoAvailable.Display(); //Console.ReadKey(); #endregion #region Adapter //Program p = new Program(); //p.getJson(); //Console.Read(); #endregion #endregion #region Behavioral Patterns Calling #region Chain Of Responsibility // Setup Chain of Responsibility //Approver Waqas = new Director(); //Approver Azeem = new VicePresident(); //Approver Raheel = new President(); //Waqas.SetSuccessor(Azeem); //Azeem.SetSuccessor(Raheel); //// Generate and process purchase requests //Purchase pr = new Purchase(2034, 350.00, "Assets"); //Waqas.ProcessRequest(pr); //pr = new Purchase(2035, 32590.10, "Servers"); //Waqas.ProcessRequest(pr); //pr = new Purchase(2036, 122100.00, "Property"); //Waqas.ProcessRequest(pr); //// Wait for user //Console.ReadKey(); #endregion #endregion }