コード例 #1
0
        public void Test_OperatorInequality_NotOk()
        {
            ICoffee c1 = _factory.CreateCoffee("Espresso");
            ICoffee c2 = _factory.CreateCoffee("Espresso");

            Assert.IsFalse(c1 != c2);
        }
コード例 #2
0
        public void Test_GetHashCode_NotOk()
        {
            ICoffee c1 = _factory.CreateCoffee("Espresso");
            ICoffee c2 = _factory.CreateCoffee("Cappuccino");

            Assert.AreNotEqual(c1.GetHashCode(), c2.GetHashCode());
        }
コード例 #3
0
        public void Test_OperatorInequality_Ok()
        {
            ICoffee c1 = _factory.CreateCoffee("Espresso");
            ICoffee c2 = _factory.CreateCoffee("Cappuccino");

            Assert.IsTrue(c1 != c2);
        }
コード例 #4
0
ファイル: ShoppingCart.cs プロジェクト: pdimova/coffee-shop
        public void AddToCart(ICoffee orderedCofee)
        {
            var isAvailable = cartRepository.IsCartItemAvailable(shoppingCartId, orderedCofee.Id);

            ICart cartItem;

            if (!isAvailable)
            {
                cartItem                   = cartFactory.CreateCart();
                cartItem.CoffeeId          = orderedCofee.Id;
                cartItem.CoffeeDescription = orderedCofee.FullDescription;
                cartItem.CoffeeCost        = orderedCofee.Cost();
                cartItem.ShoppingCartId    = this.shoppingCartId;
                cartItem.Count             = 1;

                cartRepository.Add(cartItem);
            }
            else
            {
                // Pls refactor
                cartItem = cartRepository.GetCartItemByCoffeeId(shoppingCartId, orderedCofee.Id);

                cartItem.Count++;

                cartRepository.Update(cartItem);
            }
        }
コード例 #5
0
        public void Test_Equals_Ok()
        {
            ICoffee c1 = _factory.CreateCoffee("Espresso");
            ICoffee c2 = _factory.CreateCoffee("Espresso");

            Assert.IsTrue(c1.Equals(c2));
        }
コード例 #6
0
        bool CheckState(ICoffee chosenCoffee)
        {
            if (this.water < chosenCoffee.water)
            {
                Console.WriteLine("Sorry, not enough water!");
                return(false);
            }

            if (this.milk < chosenCoffee.milk)
            {
                Console.WriteLine("Sorry, not enough milk!");
                return(false);
            }

            if (this.beans < chosenCoffee.beans)
            {
                Console.WriteLine("Sorry, not enough coffee beans!");
                return(false);
            }

            if (this.cups < 1)
            {
                Console.WriteLine("Sorry, not enough disposable cups of coffee!");
                return(false);
            }

            else
            {
                Console.WriteLine("I have enough resources, making you a coffee!");
                return(true);
            }
        }
コード例 #7
0
        public ICoffee CaptureAddOns(ICoffee coffee)
        {
            var done = false;

            while (!done)
            {
                DisplayAddOnMenu();

                var optionSelected = Console.ReadLine();
                if (optionSelected == "0")
                {
                    done = true;
                }
                else
                {
                    int.TryParse(optionSelected.ToString(), out int selected);

                    if (Enum.IsDefined(typeof(AddOnType), selected))
                    {
                        var addOnType = (AddOnType)selected;
                        coffee = addOnFactory.Create(coffee, addOnType);
                    }
                    else
                    {
                        Console.WriteLine("Invalid option. Press any key to continue...");
                        Console.ReadKey();
                        continue;
                    }
                }
            }

            return(coffee);
        }
コード例 #8
0
 public EspressoShotDecorator(ICoffee decoratedCoffee)
 {
     _decoratedCoffee = decoratedCoffee;
     Cost            += .55M;
     decoratedCoffee.Ingredients.ForEach(x => Ingredients.Add(x));
     Ingredients.Add("Espresso");
 }
コード例 #9
0
        private void ShowMessageBoxCreateCoffee(ICoffee coffee)
        {
            string createdCoffeeMessage = "Coffee Created: " + coffee.Description +
                                          "\nCost: " + Math.Round(coffee.Cost, 2) + " euros";

            MessageBox.Show(createdCoffeeMessage, "Coffee Ordered", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #10
0
        public IAddOnDecorator Create(ICoffee coffee, AddOnType addOnType)
        {
            switch (addOnType)
            {
            case AddOnType.Milk:
                return(new MilkDecorator(coffee));

            case AddOnType.Chocolate:
                return(new ChocolateDecorator(coffee));

            case AddOnType.Cinnamon:
                return(new CinnamonDecorator(coffee));

            case AddOnType.WhippedCream:
                return(new WhippedCreamDecorator(coffee));

            case AddOnType.Ice:
                return(new IceDecorator(coffee));

            case AddOnType.Caramel:
                return(new CaramelDecorator(coffee));

            case AddOnType.Water:
                return(new WaterDecorator(coffee));

            default:
                throw new ArgumentException(nameof(addOnType));
            }
        }
コード例 #11
0
        public void Test_Equals_NotOk()
        {
            ICoffee c1 = _factory.CreateCoffee("Espresso");
            ICoffee c2 = _factory.CreateCoffee("Cappuccino");

            Assert.IsFalse(c1.Equals(c2));
        }
コード例 #12
0
        public void ConstructorShouldThrowArgumentNullException_WhenNullParameterIsPassed()
        {
            //Arrange
            ICoffee coffeeMock = null;

            //Act & Assert
            Assert.That(() => new FinalOrderViewModel(coffeeMock), Throws.InstanceOf <ArgumentNullException>());
        }
コード例 #13
0
        public void CinnamonClass_Countructor_ShouldThrowArgumentNullExceptionWhenNoParameterIsProvided()
        {
            // Arrange
            ICoffee coffee = null;

            // Act & Assert
            Assert.That(() => new Cinnamon(coffee), Throws.ArgumentNullException.With.Message.Contains("coffee"));
        }
コード例 #14
0
 static void ShowCoffeeCreated(ICoffee coffee)
 {
     Console.Write(
         "\n" +
         "\nCoffee Created: {0}" +
         "\nCost: {1} euros"
         , coffee.Description, Math.Round(coffee.Cost, 2));
 }
コード例 #15
0
 static ICoffee CreateCoffee(CoffeFactory factory, ICoffee coffee, string[] condimentsSelected)
 {
     foreach (string condiment in condimentsSelected)
     {
         coffee = factory.AddCondiment(coffee, condiment);                                              //Creates the coffe with the selected condiments
     }
     return(coffee);
 }
コード例 #16
0
ファイル: Milk.cs プロジェクト: pdimova/coffee-shop
        public Milk(ICoffee coffee)
        {
            if (coffee == null)
            {
                throw new ArgumentNullException(nameof(coffee));
            }

            this.coffee = coffee;
        }
コード例 #17
0
        public WhippedCream(ICoffee coffee)
        {
            if (coffee == null)
            {
                throw new ArgumentNullException(nameof(coffee));
            }

            this.coffee = coffee;
        }
コード例 #18
0
 // Sequence of basic steps is implemented as template method.
 public void Brew(ICoffee coffee)
 {
     Grind();
     coffee.Prepare();
     TurnOnMachine();
     Wait();
     coffee.AddExtras();
     Serve();
 }
コード例 #19
0
        public override bool Equals(object obj)
        {
            if (obj is ICoffee)
            {
                ICoffee other = obj as ICoffee;
                return(Kind == other.Kind &&
                       Strength == other.Strength &&
                       Size == other.Size);
            }

            return(false);
        }
コード例 #20
0
        public FinalOrderViewModel(ICoffee coffee)
        {
            if (coffee == null)
            {
                throw new ArgumentNullException();
            }

            this.coffee = coffee;

            this.FullDescription = coffee.FullDescription;
            this.Price           = coffee.Cost();
        }
コード例 #21
0
 private void addSoy_Click(object sender, EventArgs e)
 {
     if (currentCoffee != null)
     {
         currentCoffee = new Soy(currentCoffee);
         UpdateSelection();
     }
     else
     {
         MessageBox.Show("Please select a coffee type first");
     }
 }
コード例 #22
0
        public ICoffee AddCondiment(ICoffee aCoffee, string aType)
        {
            switch (aType)
            {
            case "Steamed Milk": return(AddSteamedMilk(aCoffee));

            case "Mocha": return(AddMocha(aCoffee));

            case "Soy": return(AddSoy(aCoffee));

            case "Whip": return(AddWhip(aCoffee));
            }
            throw new Exception();
        }
コード例 #23
0
        static void Main(string[] args)
        {
            RandomNameGenerator rng     = new RandomNameGenerator();
            ICoffeeFactory      factory = new CoffeeFactory();

            for (int i = 0; i < 1000; i++)
            {
                ICoffee c1 = factory.CreateCoffee(nameof(Cappuccino));
                c1.Serve(rng.GetRandomName());
                ICoffee c2 = factory.CreateCoffee(nameof(Espresso));
                c2.Serve(rng.GetRandomName());
                ICoffee c3 = factory.CreateCoffee(nameof(LatteDoppio));
                c3.Serve(rng.GetRandomName());
                ICoffee c4 = factory.CreateCoffee(nameof(LatteGrande));
                c4.Serve(rng.GetRandomName());
                ICoffee c5 = factory.CreateCoffee(nameof(LatteTriplo));
                c5.Serve(rng.GetRandomName());
            }
        }
コード例 #24
0
 private void finishCreation_Click(object sender, EventArgs e)
 {
     if (currentCoffee != null)
     {
         string desc = currentCoffee.getDescription();
         if (desc.Substring(desc.Length - 5, 5) == "with ")
         {
             beveragesSoldLb.Items.Add("Sold plain " + desc.Substring(0, desc.Length - 6) + " for " + currentCoffee.getCost());
         }
         else
         {
             beveragesSoldLb.Items.Add("Sold " + desc.Substring(0, currentCoffee.getDescription().Length - 2) + " for " + currentCoffee.getCost());
         }
         currentCoffee = null;
     }
     else
     {
         MessageBox.Show("There is no coffee selected.");
     }
 }
コード例 #25
0
 public MilkDecorator(ICoffee coffee) : base(coffee)
 {
     _description = "Milk";
     _price       = 4;
 }
コード例 #26
0
 public MilkDecorator(ICoffee coffee) : base(coffee)
 {
 }
コード例 #27
0
ファイル: Mocha.cs プロジェクト: Fasp96/CoffeeMachine
 public Mocha(ICoffee aCoffee) : base(aCoffee)
 {
 }
コード例 #28
0
 public ICoffee Execute(ICoffee coffee)
 {
     return coffee.AddMilk();
 }
コード例 #29
0
 public SugarDecorator(ICoffee decoratedCoffee)
 {
     _decoratedCoffee = decoratedCoffee;
 }
コード例 #30
0
 public CoffeeCreamer(ICoffee coffeeToVend) : base(coffeeToVend)
 {
     this._coffeeToVend = coffeeToVend;
 }
コード例 #31
0
 public WhippedCreamDecorator(ICoffee decoratedCoffee)
     : base(decoratedCoffee)
 {
 }
コード例 #32
0
ファイル: EspressoDecorator.cs プロジェクト: dtdimi/Siege
 public EspressoShotDecorator(ICoffee decoratedCoffee)
     : base(decoratedCoffee)
 {
 }
コード例 #33
0
 public ICoffee Execute(ICoffee coffee)
 {
     return coffee.AddSugar();
 }
コード例 #34
0
ファイル: DecoratorTests.cs プロジェクト: adamjmoon/Siege
 public CoffeeWrapper(ICoffee coffee)
 {
     this.Coffee = coffee;
 }
コード例 #35
0
 protected IngredientDecorator(ICoffee decoratedCoffee)
 {
     _decoratedCoffee = decoratedCoffee;
 }
コード例 #36
0
 public ICoffee Execute(ICoffee coffee)
 {
     return _func(coffee);
 }
コード例 #37
0
 public string asks4Coffee(ICoffee someone)
 {
     return($"{name} {lastName} asks for a coffee.\n{someone.prepareCoffee()}");
 }
コード例 #38
0
 public CaramelDecorator(ICoffee coffee)
 {
     this.caramel = new Caramel();
     this.Coffee  = coffee;
 }
コード例 #39
0
 public MilkDecorator(ICoffee decoratedCoffee)
 {
     _decoratedCoffee = decoratedCoffee;
 }