public async Task <ActionResult <string> > Post(string drinkType, double money, int sugars, int extraHot) { try { var drinkService = new DrinkService(); var drink = new Drink { DrinkType = drinkType, Money = money, Sugars = sugars, ExtraHot = extraHot, }; var result = await drinkService.OrderAsync(drink); this.log.LogDebug(string.Format("{0}: {1} executed", System.DateTime.Now, System.Reflection.MethodBase.GetCurrentMethod().Name)); return(this.Ok(result)); } catch (Services.BadParametersException exception) { log.LogInformation(string.Format("{0}: {1}", System.DateTime.Now, exception.Message)); return(this.StatusCode(400, exception.Message)); } catch (System.Exception exception) { log.LogError(exception, string.Format("{0}: Error in {1}", System.DateTime.Now, System.Reflection.MethodBase.GetCurrentMethod().Name)); return(this.StatusCode(500)); } }
public void DrinkService_Order_DrinkWithoutData_2() { // Arrange var drinkService = new DrinkService(); var drink = new Drink(); // Act BadParametersException exception = Assert.Throws <BadParametersException>( delegate { drinkService.OrderAsync(drink).GetAwaiter().GetResult(); }); // Assert Assert.That(exception.Message, Is.EqualTo("The drink type should be tea, coffee or chocolate.")); }
public void DrinkService_Order_DrinkHotWithSugar(string drinkType, float money, int sugars, int extraHot) { // Arrange var drinkService = new DrinkService(); var drink = new Drink { DrinkType = drinkType, Money = money, Sugars = sugars, ExtraHot = extraHot, }; // Act string result = drinkService.OrderAsync(drink).Result; // Assert Assert.AreEqual(string.Format("You have ordered a {0} extra hot with {1} sugars(stick included).", drink.DrinkType.ToLower(), drink.Sugars), result); }
public void DrinkService_Order_DrinkColdWhithoutSugar(string drinkType, float money, int sugars, int extraHot) { // Arrange var drinkService = new DrinkService(); var drink = new Drink { DrinkType = drinkType, Money = money, Sugars = sugars, ExtraHot = extraHot, }; // Act string result = drinkService.OrderAsync(drink).Result; // Assert Assert.AreEqual(string.Format("You have ordered a {0}", drink.DrinkType.ToLower()), result); }
public void DrinkService_Order_BadNumberSugars(string drinkType, float money, int sugars, int extraHot) { // Arrange var drinkService = new DrinkService(); var drink = new Drink { DrinkType = drinkType, Money = money, Sugars = sugars, ExtraHot = extraHot, }; // Act BadParametersException exception = Assert.Throws <BadParametersException>( delegate { drinkService.OrderAsync(drink).GetAwaiter().GetResult(); }); // Assert Assert.AreEqual("The number of sugars should be between 0 and 2.", exception.Message); }
public void DrinkService_Order_InventedDrink() { // Arrange var drinkService = new DrinkService(); var drink = new Drink { DrinkType = "invented drink", Money = 0.8F, Sugars = 1, ExtraHot = 1, }; // Act BadParametersException exception = Assert.Throws <BadParametersException>( delegate { drinkService.OrderAsync(drink).GetAwaiter().GetResult(); }); // Assert Assert.AreEqual("The drink type should be tea, coffee or chocolate.", exception.Message); }
public void DrinkService_Order_MoneyNotEnought(string drinkType, float money, int sugars, int extraHot) { // Arrange var drinkService = new DrinkService(); var drink = new Drink { DrinkType = drinkType, Money = money, Sugars = sugars, ExtraHot = extraHot, }; // Act BadParametersException exception = Assert.Throws <BadParametersException>( delegate { drinkService.OrderAsync(drink).GetAwaiter().GetResult(); }); // Assert Assert.AreEqual( string.Format( "The {0} costs {1}.", drinkService.DrinkPrices.Single(x => x.Name.ToLower() == drink.DrinkType.ToLower()).Name, drinkService.DrinkPrices.Single(x => x.Name.ToLower() == drink.DrinkType.ToLower()).Price.ToString("N", new System.Globalization.CultureInfo("en-US"))), exception.Message); }