public static bool IsOfColor(this BasePlate plate, Color color) { if (plate is SushiPlate) { SushiPlate sushiPlate = (SushiPlate)plate; return(sushiPlate.Color.Equals(color)); } return(false); }
public void PriceServiceShouldCalculateCorrectValuesForSinglePlate_Test() { // Arrange SushiPlate[] plates = new SushiPlate[] { greyPlate }; // Act decimal total = calculatorService.CalculateTotalPrice(plates); // Assert Assert.Equal(GREY_PLATE_PRICE, total); }
public void PriceServiceShouldCalculateCorrectValuesForMultiplePlates_Test() { // Arrange SushiPlate[] plates = new SushiPlate[] { greyPlate, greenPlate }; decimal expectedTotal = GREY_PLATE_PRICE + GREEN_PLATE_PRICE; // Act decimal total = calculatorService.CalculateTotalPrice(plates); // Assert Assert.Equal(expectedTotal, total); }
public void PriceServiceShouldCalculateCorrectValuesAsReqExample3_UsingLiteral_Test() { // Arrange SushiPlate[] plates = new SushiPlate[] { greyPlate, greenPlate, yellowPlate, redPlate, bluePlate }; decimal expectedTotal = 14.75m;// GREY_PLATE_PRICE * greyPlateQuantity; // Act decimal total = calculatorService.CalculateTotalPrice(plates); // Assert Assert.Equal(expectedTotal, total); }
public void PriceServiceShouldThrowExceptionWhenParamIsNull_Test() { // Arrange MethodInfo methodInfo = calculatorService.GetType().GetMethod("GetPlatePrice"); ParameterInfo[] parameterInfos = methodInfo.GetParameters(); ParameterInfo parameterInfo = parameterInfos[0]; string plateParamName = parameterInfo.Name; SushiPlate plate = null; // Act Action nullPlateMethodCall = () => this.calculatorService.GetPlatePrice(plate); // Assert ArgumentNullException argumentNullException = Assert.Throws <ArgumentNullException>(nullPlateMethodCall); Assert.Contains(plateParamName, argumentNullException.Message); }
public decimal GetPlatePrice(BasePlate plate) { if (plate == null) { throw new ArgumentNullException(nameof(plate)); } if (plate is SushiPlate) { SushiPlate sushiPlate = (SushiPlate)plate; switch (sushiPlate.Color) { case Color.Grey: return(4.95m); case Color.Green: return(3.95m); case Color.Yellow: return(2.95m); case Color.Red: return(1.95m); case Color.Blue: return(0.95m); default: throw new ArgumentOutOfRangeException(INVALID_ENUM_VALUE_EXCEPTION); } } else if (plate is SoupPlate) { return(2.5m); } else { throw new ArgumentException("No price definition available for the plate of type [" + plate.GetType().ToString() + "]"); } }