Exemple #1
0
        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."));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }