public void Valid_IngredientCategory_Create()
        {
            //Arrange
            Ingredient i = new Ingredient()
            {
                Name = "Test New Ingredient"
            };

            //Act
            var result = (RedirectToRouteResult)objController.Create(i);

            //Assert
            _listIngredientserviceMock.Verify(m => m.Create(i), Times.Once);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
Example #2
0
        public void IngredientCreate()
        {
            //setup
            int preCount = TestHelper.CountTable("Ingredients");

            preCount = preCount + 1;
            Ingredient ingredient = new Ingredient()
            {
                Name = "TestCreate", Measurable = true, Alch = 20
            };

            //act
            controller.Create(ingredient);
            int postCount = TestHelper.CountTable("Ingredients");

            //assert
            Assert.AreEqual(preCount, postCount, "Ingredient was not created successfully");
        }
Example #3
0
        public void barCreateStock()
        {
            IngredientController ingredientController = new IngredientController();
            DrinkController      drinkController      = new DrinkController();
            //setup
            Ingredient vodka = new Ingredient
            {
                Name       = "TestVodka",
                Measurable = true,
                Alch       = 37.5
            };

            Ingredient juice = new Ingredient
            {
                Name       = "TestJuice",
                Measurable = false,
                Alch       = 0
            };

            vodka = ingredientController.Create(vodka);
            juice = ingredientController.Create(juice);

            ManagerController mc      = new ManagerController();
            Manager           manager = new Manager("TestName", "TestPhonenumber", "TestEmail", "TestUsername", null);
            Manager           m       = mc.CreateManager(manager, "TestPassword");

            Country country = LocationDB.Instance.getCountryById(1);

            if (country is null)
            {
                Assert.Fail("Country is null");
            }
            Zipcode zip = LocationDB.Instance.findZipById(1);
            Address a   = new Address("TestVej", zip);

            zip.Country = country;
            a.Zipcode   = zip;
            Bar bar = new Bar
            {
                Address     = a,
                Email       = "TestBarEmail",
                Name        = "TestBarName",
                PhoneNumber = "TestBarP",
                Username    = "******"
            };
            Bar Createdbar = controller.Create(bar, m.Id, "TestPassword");

            ICollection <Measurement> measurements = new DrinkController().FindAllMeasurements();
            var allStocks          = controller.GetAllStocks(bar.ID);
            int precount           = allStocks.Count;
            int preVodkaStockCount = allStocks.Where(e => e.Ingredient.Equals(vodka)).Count();
            int preJuiceStockCount = allStocks.Where(e => e.Ingredient.Equals(juice)).Count();

            //act
            controller.CreateStock(Createdbar.ID, 20, vodka, measurements.FirstOrDefault().Id);

            preVodkaStockCount++;   //Just creted one vodka. so we increment
            precount++;             // Just created one more stock in the DB so we increment

            controller.CreateStock(Createdbar.ID, 20, juice, null);
            precount++;           //Just created one juice, so we increment
            preJuiceStockCount++; // Just craeted one juice so we increment

            List <Stock> stocksFound = controller.GetAllStocks(bar.ID);
            //assert
            bool success = (stocksFound.Where(e => e.Ingredient.Equals(vodka))).Count() == preVodkaStockCount &&
                           stocksFound.Count() == precount;


            Assert.IsTrue(success, "Stock measurable was not created successfully");
            int actual = stocksFound.Where(e => e.Ingredient.Equals(juice)).Count();


            success = (actual == preJuiceStockCount && stocksFound.Count() == precount);

            Assert.IsTrue(success, "Stock not mreasurable was not created successfully");
        }
Example #4
0
        private void FillDataToTheDataBase()
        {
            #region Make bar
            BarController     bc      = new BarController();
            ManagerController mc      = new ManagerController();
            Manager           manager = new Manager("TestName", "TestPhonenumber", "TestEmail", "TestUsername", null);
            Manager           m       = mc.CreateManager(manager, "TestPassword");

            Country country = LocationDB.Instance.getCountryById(1);
            if (country is null)
            {
                Assert.Fail("Country is null");
            }
            Zipcode zip = LocationDB.Instance.findZipById(1);
            Address a   = new Address("TestVej", zip);
            zip.Country = country;
            a.Zipcode   = zip;

            Bar bar = new Bar
            {
                Address     = a,
                Email       = "TestBarEmail",
                Name        = "TestBarName",
                PhoneNumber = "TestBarP",
                Username    = "******"
            };
            this.bar = bc.Create(bar, m.Id, "TestPassword");
            #endregion

            IngredientController ingredientController = new IngredientController();

            List <Drink> drinks = new List <Drink>();


            Ingredient vodka = new Ingredient
            {
                Name       = "TestVodka",
                Measurable = true,
                Alch       = 37.5
            };

            Ingredient juice = new Ingredient
            {
                Name       = "TestJuice",
                Measurable = true,
                Alch       = 0
            };

            TestVodkaIngre = ingredientController.Create(vodka);
            TestJuiceIngre = ingredientController.Create(juice);


            quantifiedIngredientVodka = new QuantifiedIngredient
            {
                Quantity    = 6,
                Ingredient  = ingredientController.Find("TestVodka").First(), //We would like it to throw an exception here, as it's a test
                Measurement = ingredientController.FindMeasurement("cl")
            };

            quantifiedIngredientJuice = new QuantifiedIngredient
            {
                Quantity    = 2,
                Ingredient  = ingredientController.Find("TestJuice").First(), //We would like it to throw an exception here, as it's a test
                Measurement = ingredientController.FindMeasurement("cl")
            };

            Drink drinkVodkaJuice = new Drink
            {
                Recipe = "TestVodkaJuiceRecipe",
                Names  = new List <string>()
                {
                    "TestName1", "TestName2"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientJuice, quantifiedIngredientVodka
                }
            };

            Drink drinkVodka = new Drink
            {
                Recipe = "TestVodkaRecipe",
                Names  = new List <string>()
                {
                    "TestNameVodka"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientVodka
                }
            };

            Drink drinkJuice = new Drink
            {
                Recipe = "TestJuiceRecipe",
                Id     = 3,
                Names  = new List <string>()
                {
                    "TestJuice", "TestAppelsinjuice"
                },
                Ingredients = new List <QuantifiedIngredient>()
                {
                    quantifiedIngredientJuice
                }
            };

            TestVodka      = controller.Create(drinkVodka);
            TestJuice      = controller.Create(drinkJuice);
            TestVodkaJuice = controller.Create(drinkVodkaJuice);
        }