Ejemplo n.º 1
0
 public void CreateStock(int barId, double quantity, Ingredient ingredient, int measurementId)
 {
     barController.CreateStock(barId, quantity, ingredient, measurementId);
 }
Ejemplo n.º 2
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");
        }