protected override ICoffee CreateCoffee(string coffeeType, CoffeSizeType size) { if (!this.strategies.ContainsKey(coffeeType)) { throw new ArgumentNullException(); } return this.strategies[coffeeType](size); }
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)); }
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>()); }
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>()); }
public Coffee(string description, CoffeSizeType size) { // TODO: check for null this.Description = description; this.Size = size; }
public Espresso(CoffeSizeType size) : base("Espresso", size) { }
public Americano(CoffeSizeType size) : base("Americano", size) { }
public Cappuccino(CoffeSizeType size) : base("Cappuccino", size) { }
public Ristretto(CoffeSizeType size) : base("Ristretto", size) { }
public Latte(CoffeSizeType size) : base("Latte", size) { }
public Doppio(CoffeSizeType size) : base("Doppio", size) { }
public ICoffee ExposedCreateCoffee(string coffeeType, CoffeSizeType size) { return(base.CreateCoffee(coffeeType, size)); }
// abstract factory method protected abstract ICoffee CreateCoffee(string coffeeType, CoffeSizeType size);