public static IMainDish CreateMainDish(FoodInformation foodInformation) { IMainDish mainDish = null; switch (foodInformation.Name.ToUpper()) { case "SCHABOWY Z FRYTKAMI": mainDish = new ShnitzelFries(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "SCHABOWY Z ZIEMNIAKAMI": mainDish = new ShnitzelPotato(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "SCHABOWY Z RYŻEM": mainDish = new ShnitzelRice(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "RYBA Z FRYTKAMI": mainDish = new FishFries(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "PLACEK PO WĘGIERSKU": mainDish = new HungarianCake(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; } return(mainDish); }
// Funkcja odpalana przy kliknięciu w dodatek. Tworzy dynamicznie nowy label umieszczany na innym panelu i blokuje dodawanie wybranego dodatku. private void AddElementClickEvent(object sender, EventArgs e) { if (uiFlpToppingsChoosen.Controls.Count >= MaximumAddElement) { MessageBox.Show(Resources.NotAddMoreToppings, Resources.Attention, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Label lbl = (Label)sender; lbl.Enabled = false; Label label = new Label(); label.AutoSize = true; label.MouseClick += new MouseEventHandler(RemovePizzaElementClickEvent); label.MouseHover += new EventHandler(RemoveColorPizzaElementClickEvent); label.MouseLeave += new EventHandler(RemoveLeavePizzaElementClickEvent); FoodInformation food = (FoodInformation)lbl.Tag; _actualPrice += food.Price; uiTxtPrice.Text = _actualPrice.ToString("C", _cultureInfo); label.Text = string.Format("x {0} {1}", food.Name, food.Price.ToString("C", _cultureInfo)); label.Tag = food; uiFlpToppingsChoosen.Controls.Add(label); }
public static IPizza CreatePizza(FoodInformation foodInformation) { IPizza pizza = null; switch (foodInformation.Name.ToUpper()) { case "MARGHERITTA": pizza = new Margheritta(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "VEGETARIANA": pizza = new Vegetariana(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "VENECIA": pizza = new Venecia(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "TOSCA": pizza = new Tosca(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; } return(pizza); }
public static IMainDish CreateAddToMainDish(IMainDish mainDish, FoodInformation foodInformation) { switch (foodInformation.Name.ToUpper()) { case "BAR SAŁATKOWY": mainDish = new Salad(mainDish, foodInformation.Name, foodInformation.Price); break; case "ZESTAW SOSÓW": mainDish = new Sauce(mainDish, foodInformation.Name, foodInformation.Price); break; } return(mainDish); }
public static ISoup CreateSoup(FoodInformation foodInformation) { ISoup soup = null; switch (foodInformation.Name.ToUpper()) { case "POMIDOROWA": soup = new TomatoSoup(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "ROSÓŁ": soup = new ChickenSoup(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; } return(soup); }
public static IDrink CreateDrink(FoodInformation foodInformation) { IDrink drink = null; switch (foodInformation.Name.ToUpper()) { case "KAWA": drink = new Coffee(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "HERBATA": drink = new Tea(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; case "COLA": drink = new Cola(foodInformation.ID, foodInformation.Name, foodInformation.Price); break; } return(drink); }
public static IPizza CreateAddToPizza(IPizza pizza, FoodInformation foodInformation) { switch (foodInformation.Name.ToUpper()) { case "PODWÓJNY SER": pizza = new DoubleCheese(pizza, foodInformation.Name, foodInformation.Price); break; case "SALAMI": pizza = new Salami(pizza, foodInformation.Name, foodInformation.Price); break; case "SZYNKA": pizza = new Ham(pizza, foodInformation.Name, foodInformation.Price); break; case "PIECZARKI": pizza = new Mushroom(pizza, foodInformation.Name, foodInformation.Price); break; } return(pizza); }
// Zdarzenie odpowiedzialne za usuwanie dodatków, których jednak nie chcemy zamówić. Gdy usuniemy dodatek z panelu wyboru znów staje się on aktywny. private void RemovePizzaElementClickEvent(object sender, EventArgs e) { Label lbl = (Label)sender; if (!lbl.IsDisposed) { FoodInformation foodInformation = (FoodInformation)lbl.Tag; _actualPrice -= foodInformation.Price; uiTxtPrice.Text = _actualPrice.ToString("C", _cultureInfo); lbl.Dispose(); foreach (Control control in uiFlpAddToppings.Controls) { Label label = (Label)control; FoodInformation food2 = (FoodInformation)label.Tag; if (food2.ID == foodInformation.ID) { label.Enabled = true; label.ForeColor = Color.Black; } } } }
//测试权值正向修改 public async System.Threading.Tasks.Task Test2Async() { //weatherservice var weatherRootToReturn = new WeatherRoot(); weatherRootToReturn.main = new Main(); weatherRootToReturn.main.temp = "29"; weatherRootToReturn.main.humidity = "30"; var weatherServiceMock = new Mock <IWeatherService>(); weatherServiceMock.Setup(w => w.GetWeatherAsync()).ReturnsAsync(weatherRootToReturn); var mockWeatherService = weatherServiceMock.Object; // loadjsonservice List <FoodInformation> fi = new List <FoodInformation>(); for (int i = 1; i <= 40; i++) { FoodInformation food = new FoodInformation(); food.Name = i.ToString(); food.Weight = new List <int>(); for (int j = 0; j < 6; j++) { food.Weight.Add(i); } fi.Add(food); } var loadJsonServiceMock = new Mock <ILoadJsonService>(); loadJsonServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(fi); var mockLoadJsonServiceMock = loadJsonServiceMock.Object; //userchoiceservice var userChoiceServiceMock = new Mock <IUserChoiceService>(); userChoiceServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(new List <Log>()); var mockUserChoiceService = userChoiceServiceMock.Object; //userfacorservice var userFavorServiceMock = new Mock <IUserFavorService>(); userFavorServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(new List <FoodWeightChange>()); var mockUserFavorService = userFavorServiceMock.Object; //log var logServiceMock = new Mock <ILogService>(); logServiceMock.Setup(w => w.GetLogs()).Returns(new List <Log>()); var mockLogSerivce = logServiceMock.Object; var foodFavorSerivce = new Mock <IFoodFavorService>(); var mockFoodFavorService = foodFavorSerivce.Object; IRecommendationService ir = new RecommendationService(mockWeatherService, mockLoadJsonServiceMock, mockUserFavorService, mockLogSerivce, mockFoodFavorService); ir.InitRecommendationAsync(); List <FoodInformation> ff = await ir.ReFlashAsync(); List <int> reason = new List <int>(); for (int i = 0; i <= 5; i++) { reason.Add(1); } ir.ChangeWeight("10", reason, false); var fd = ir.GetFoodInfs(); Assert.AreEqual(fd[9].Weight[1], 14); //List<FoodInformation> ff = await ir.ReFlashAsync(); }
public async System.Threading.Tasks.Task Test6Async() { //weatherservice var weatherRootToReturn = new WeatherRoot(); weatherRootToReturn.main = new Main(); weatherRootToReturn.main.temp = "29"; weatherRootToReturn.main.humidity = "30"; var weatherServiceMock = new Mock <IWeatherService>(); weatherServiceMock.Setup(w => w.GetWeatherAsync()).ReturnsAsync(weatherRootToReturn); var mockWeatherService = weatherServiceMock.Object; // loadjsonservice List <FoodInformation> fi = new List <FoodInformation>(); for (int i = 1; i <= 40; i++) { FoodInformation food = new FoodInformation(); food.Name = i.ToString(); food.Weight = new List <int>(); for (int j = 0; j < 6; j++) { food.Weight.Add(i); } fi.Add(food); } var loadJsonServiceMock = new Mock <ILoadJsonService>(); loadJsonServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(fi); var mockLoadJsonServiceMock = loadJsonServiceMock.Object; //userchoiceservice var userChoiceServiceMock = new Mock <IUserChoiceService>(); userChoiceServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(new List <Log>()); var mockUserChoiceService = userChoiceServiceMock.Object; //userfacorservice var userFavorServiceMock = new Mock <IUserFavorService>(); userFavorServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(new List <FoodWeightChange>()); var mockUserFavorService = userFavorServiceMock.Object; //log var logServiceMock = new Mock <ILogService>(); logServiceMock.Setup(w => w.GetLogs()).Returns(new List <Log>()); var mockLogSerivce = logServiceMock.Object; //foodFavorSerivce var foodFavorSerivce = new Mock <IFoodFavorService>(); var mockFoodFavorService = foodFavorSerivce.Object; IRecommendationService ir = new RecommendationService(mockWeatherService, mockLoadJsonServiceMock, mockUserFavorService, mockLogSerivce, mockFoodFavorService); ir.InitRecommendationAsync(); Vector vector = new Vector(); vector.Humidity = -1; vector.Temperature = 1; List <Vector> vectors = new List <Vector>(); vectors.Add(vector); int[] k = { 0 }; List <int> p = new List <int>(k); Assert.AreEqual(ir.GetCos(vectors), p); }
public async System.Threading.Tasks.Task Test13Async() { //weatherservice var weatherRootToReturn = new WeatherRoot(); weatherRootToReturn.main = new Main(); weatherRootToReturn.main.temp = "29"; weatherRootToReturn.main.humidity = "30"; var weatherServiceMock = new Mock <IWeatherService>(); weatherServiceMock.Setup(w => w.GetWeatherAsync()).ReturnsAsync(weatherRootToReturn); var mockWeatherService = weatherServiceMock.Object; // loadjsonservice List <FoodInformation> fi = new List <FoodInformation>(); for (int i = 0; i <= 40; i++) { FoodInformation food = new FoodInformation(); food.Name = i.ToString(); food.Weight = new List <int>(); for (int j = 0; j < 6; j++) { food.Weight.Add(i); } fi.Add(food); } var loadJsonServiceMock = new Mock <ILoadJsonService>(); loadJsonServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(fi); var mockLoadJsonServiceMock = loadJsonServiceMock.Object; //userchoiceservice var userChoiceServiceMock = new Mock <IUserChoiceService>(); userChoiceServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(new List <Log>()); var mockUserChoiceService = userChoiceServiceMock.Object; //userfacorservice var userFavorServiceMock = new Mock <IUserFavorService>(); userFavorServiceMock.Setup(w => w.ReadJsonAsync()).ReturnsAsync(new List <FoodWeightChange>()); var mockUserFavorService = userFavorServiceMock.Object; //log var logServiceMock = new Mock <ILogService>(); List <Log> localLog = new List <Log>(); for (int i = 0; i < 9; i++) { Log log = new Log(); log.FoodName = i.ToString(); log.Date = new DateTime(2016, 6, 1); int[] t = { 1, 1 }; log.WeatherList = new List <int>(t); int[] t1 = { -1, -1, 2, 2, 2, 2 }; log.WeightChangeList = new List <int>(t1); localLog.Add(log); } logServiceMock.Setup(w => w.GetLogs()).Returns(localLog); var mockLogSerivce = logServiceMock.Object; //foodFavorSerivce var foodFavorSerivce = new Mock <IFoodFavorService>(); var mockFoodFavorService = foodFavorSerivce.Object; IRecommendationService ir = new RecommendationService(mockWeatherService, mockLoadJsonServiceMock, mockUserFavorService, mockLogSerivce, mockFoodFavorService); ir.InitRecommendationAsync(); // mockOneDriveService var oneDriveService = new Mock <IOneDriveService>(); List <Log> k = new List <Log>(); for (int i = 0; i <= 10; i++) { Log log = new Log(); log.FoodName = i.ToString(); log.Date = new DateTime(2016, 6, 2); int[] t = { 1, 1 }; log.WeatherList = new List <int>(t); int[] t2 = { 1, 1, 1, 1, 1, 1 }; log.WeightChangeList = new List <int>(t2); k.Add(log); } oneDriveService.Setup(w => w.LoadLogAsync()).ReturnsAsync(k); oneDriveService.Setup(w => w.LoadFoodWeightAsync()).ReturnsAsync(new List <FoodWeightChange>()); var mockOneDriveService = oneDriveService.Object; //mockLastTimeCommitService var lastTimeCommitService = new Mock <ILastTimeCommitService>(); DateTime dt = new DateTime(2016, 4, 1); lastTimeCommitService.Setup(w => w.ReadJsonAsync()).ReturnsAsync(dt); var mockLastTimeCommitService = lastTimeCommitService.Object; MaintenanceService maintenanceService = new MaintenanceService(ir, mockUserChoiceService, mockUserFavorService, mockOneDriveService, mockLastTimeCommitService, mockLogSerivce, mockFoodFavorService); await maintenanceService.MaintenanceAsync(); }