예제 #1
0
        protected override ICoffee CreateCoffee(string coffeeType, CoffeSizeType size)
        {
            if (!this.strategies.ContainsKey(coffeeType))
            {
                throw new ArgumentNullException();
            }

            return this.strategies[coffeeType](size);
        }
예제 #2
0
        public void DoppioClass_CostMethod_ShouldReturnCorrectPriceBasedOnCoffeSize(CoffeSizeType coffeeSize)
        {
            // Arrange
            var basePrice    = 2.50m;
            var expectedCost = basePrice + (((int)coffeeSize / 100) * basePrice);

            // Act
            var obj = new Doppio(coffeeSize);

            // Assert
            Assert.That(obj.Cost(), Is.EqualTo(expectedCost));
        }
예제 #3
0
        public void CreateCoffee_ShouldThrowArgumentNullException_WhenInvalidParameterPassed()
        {
            // Arange
            var           condimentsStrategiesMock = new Mock <IDictionary <string, Func <ICoffee, ICoffee> > >();
            var           coffeetypeStrategiesMock = new Mock <IDictionary <string, Func <CoffeSizeType, ICoffee> > >();
            string        coffeeType = "Espresso";
            CoffeSizeType size       = CoffeSizeType.Medium;

            coffeetypeStrategiesMock.Setup(d => d.ContainsKey(coffeeType)).Returns(false);

            var plovdivStore = new PlovdivCoffeeStoreFake(condimentsStrategiesMock.Object, coffeetypeStrategiesMock.Object);

            //Act & Assert
            Assert.That(() => plovdivStore.ExposedCreateCoffee(coffeeType, size), Throws.InstanceOf <ArgumentNullException>());
        }
예제 #4
0
        public void CreateCoffee_ShouldReturnICoffeeObject_WhenValidParameterPassed()
        {
            // Arange
            var           condimentsStrategiesMock = new Mock <IDictionary <string, Func <ICoffee, ICoffee> > >();
            var           coffeetypeStrategiesMock = new Mock <IDictionary <string, Func <CoffeSizeType, ICoffee> > >();
            string        coffeeType           = "Espresso";
            CoffeSizeType size                 = CoffeSizeType.Medium;
            Func <CoffeSizeType, ICoffee> func = s => new Espresso(s);

            coffeetypeStrategiesMock.Setup(d => d.ContainsKey(coffeeType)).Returns(true);
            coffeetypeStrategiesMock.Setup(d => d[coffeeType]).Returns(func);

            var plovdivStore = new PlovdivCoffeeStoreFake(condimentsStrategiesMock.Object, coffeetypeStrategiesMock.Object);
            // Act
            var result = plovdivStore.ExposedCreateCoffee(coffeeType, size);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.InstanceOf <ICoffee>());
        }
예제 #5
0
 public Coffee(string description, CoffeSizeType size)
 {
     // TODO: check for null
     this.Description = description;
     this.Size        = size;
 }
예제 #6
0
 public Espresso(CoffeSizeType size) : base("Espresso", size)
 {
 }
예제 #7
0
 public Americano(CoffeSizeType size) : base("Americano", size)
 {
 }
예제 #8
0
 public Cappuccino(CoffeSizeType size) : base("Cappuccino", size)
 {
 }
예제 #9
0
 public Ristretto(CoffeSizeType size) : base("Ristretto", size)
 {
 }
예제 #10
0
 public Latte(CoffeSizeType size) : base("Latte", size)
 {
 }
예제 #11
0
 public Doppio(CoffeSizeType size) : base("Doppio", size)
 {
 }
예제 #12
0
 public ICoffee ExposedCreateCoffee(string coffeeType, CoffeSizeType size)
 {
     return(base.CreateCoffee(coffeeType, size));
 }
예제 #13
0
 // abstract factory method
 protected abstract ICoffee CreateCoffee(string coffeeType, CoffeSizeType size);