public void ExpressoNoMilkNoSugarTest() { // Arrange double expectedPrice = 1.8; bool hasSugar = false; bool hasMilk = false; // act ITopping topping = new Topping(false, false); Drink actual = DrinkFactory.OrderDrink(DrinkType.Expresso, topping); Assert.AreEqual(expectedPrice, actual.Cost()); Assert.AreEqual(hasSugar, actual.HasSugar); Assert.AreEqual(hasMilk, actual.HasMilk); }
public void IceTeaMilkSugarTest() { // Arrange double expectedPrice = 2; bool hasSugar = true; bool hasMilk = false; // act ITopping topping = new Topping(true, true); Drink actual = DrinkFactory.OrderDrink(DrinkType.IceTea, topping); Assert.AreEqual(expectedPrice, actual.Cost()); Assert.AreEqual(hasSugar, actual.HasSugar); Assert.AreEqual(hasMilk, actual.HasMilk); }
public void ExpressoMilkSugarChocolateTest() { // Arrange double expectedPrice = 3.3; bool hasSugar = true; bool hasMilk = true; bool hasChocolate = true; // act ITopping topping = new Topping(true, true, true); Drink actual = DrinkFactory.OrderDrink(DrinkType.Expresso, topping); Assert.AreEqual(expectedPrice, actual.Cost()); Assert.AreEqual(hasSugar, actual.HasSugar); Assert.AreEqual(hasMilk, actual.HasMilk); Assert.AreEqual(hasChocolate, actual.HasChocolate); }
public void OrderDrinkTest(string type, int hasChocolate, int hasMilk, int hasSugar, double expectedCost, string errorMessage, string consoleMessage) { // Arrange Mock <IServiceLocator> moqServiceLocator = new Mock <IServiceLocator>(); Mock <IConsoleService> moqConsoleService = new Mock <IConsoleService>(); Mock <IFileSystemService> moqFileSystemService = new Mock <IFileSystemService>(); moqServiceLocator.Setup(msl => msl.GetConsoleService()).Returns(moqConsoleService.Object); moqServiceLocator.Setup(msl => msl.GetFileService()).Returns(moqFileSystemService.Object); ServiceLocatorWrapper.ServiceLocator = moqServiceLocator.Object; // Act Drink result = null; try { result = AcuCafe.AcuCafe.OrderDrink(type, hasMilk == 1, hasSugar == 1, hasChocolate == 1); } catch { } finally { // Assert if (errorMessage != null) { moqConsoleService.Verify(mcs => mcs.WriteLine(It.Is <string>(s => s.Equals("We are unable to prepare your drink."))), Times.Once); moqConsoleService.Verify(mcs => mcs.WriteLine(It.Is <string>(s => s.Equals(consoleMessage))), Times.Once); moqFileSystemService.Verify(mfs => mfs.WriteTextToPath(It.IsAny <string>(), It.Is <string>(s => s.Contains(errorMessage))), Times.Once); } else { moqConsoleService.Verify(mcs => mcs.WriteLine(It.Is <string>(s => s.Equals("We are unable to prepare your drink."))), Times.Never); moqConsoleService.Verify(mcs => mcs.WriteLine(It.Is <string>(s => s.Equals(consoleMessage))), Times.Once); // Verify cost of drink Assert.AreEqual(expectedCost, result.Cost()); } } }
public static async Task Main(string[] args) { try { ITopping topping = new Topping(false, false); Drink drink = DrinkFactory.OrderDrink(DrinkType.IceTea, topping); string result = await AcuCafe.AcuCafe.PrepareOrder(drink, topping.HasMilk); var cost = drink.Cost(); Console.WriteLine(result); Console.WriteLine($"The price is: {cost}"); } catch (Exception ex) { Console.WriteLine(ex.Message); string path = ConfigurationManager.AppSettings[Constants.FILE_PATH]; System.IO.File.WriteAllText(path, ex.ToString()); } Console.ReadLine(); }