public string GetIP(string greenhouseID) { GreenhouseDBContext db = new GreenhouseDBContext(); foreach (Greenhouse greenhouse in db.Greenhouses) { if (greenhouse.GreenhouseID == greenhouseID) { return(greenhouse.IP + ":" + greenhouse.Port); } } /* * string databaseConnectionString = "";//TODO databaseconnection string * SqlConnection databaseConnection = new SqlConnection(databaseConnectionString); * SqlCommand command = new SqlCommand("SELECT * FROM greenhouse WHERE greenhouse_id = " + greenhouseID); * * SqlDataReader reader = command.ExecuteReader(); * string greenhouseIP = reader.GetString(3); * int greenhousePort = reader.GetInt32(4); * * return greenhouseIP + ":" + greenhousePort; */ //return "127.0.0.1" + ":" + "8081"; //DUMMY CONNECTION return(""); }
public void IPAddress() { // Arrange int startPort = 0; int newPort = 0; int sendPort = 8097; foreach (Greenhouse greenhouse in db.Greenhouses) { if (greenhouse.GreenhouseID == greenhouse.GreenhouseID) { startPort = greenhouse.Port; } } db.SaveChanges(); // Act client.sendIPAddress(8097); Thread.Sleep(1000); // Assert db = new GreenhouseDBContext(); foreach (Greenhouse greenhouse in db.Greenhouses) { if (greenhouse.GreenhouseID == greenhouse.GreenhouseID) { newPort = greenhouse.Port; } } db.SaveChanges(); Assert.AreNotEqual(startPort, newPort); Assert.AreEqual(sendPort, newPort); }
public static void MyClassInitialize(TestContext testContext) { db = new GreenhouseDBContext(); scheduleID = "UnitTestSchedule"; foreach (Schedule block in db.Schedules) { if (block.ScheduleID == scheduleID) { db.Schedules.Remove(block); } } db.SaveChanges(); }
public void datalog(string greenHouseID, DateTime timeofreading, Nullable <double> internalTemperature, Nullable <double> externalTemperature, Nullable <double> humidity, Nullable <double> waterlevel) { GreenhouseDBContext db = new GreenhouseDBContext(); Datalog datalog = new Datalog(); datalog.Greenhouse_ID = greenHouseID; datalog.TimeOfReading = timeofreading; datalog.InternalTemperature = (float)internalTemperature; datalog.ExternalTemperature = (float)externalTemperature; datalog.Humidity = (float)humidity; datalog.Waterlevel = (float)waterlevel; db.Datalogs.Add(datalog); db.SaveChanges(); }
public void MyTestInitialize() { db = new GreenhouseDBContext(); greenhouse = new Greenhouse(); greenhouse.GreenhouseID = "UnitTesting"; greenhouse.IP = "127.0.0.1"; greenhouse.Password = "******"; greenhouse.Port = 8070; db.Greenhouses.Add(greenhouse); db.SaveChanges(); client = new ClientMock(greenhouse.IP, greenhouse.Port); client.ID = greenhouse.GreenhouseID; client.ListenForCommunication(); }
internal JObject fetchSchedule(string greenHouseID) { GreenhouseDBContext db = new GreenhouseDBContext(); Greenhouse greenhouse = new Greenhouse(); GreenhouseSchedule greenhouseSchedule = null; foreach (GreenhouseSchedule schedule in db.GreenhouseSchedules) { if (schedule.GreenhouseID == greenHouseID) { greenhouseSchedule = schedule; } } db.SaveChanges(); JObject jsonSchedule = new JObject(); JObject daySchedule = new JObject(); if (greenhouseSchedule != null) { foreach (GreenhouseWeb.Models.Schedule schedule in db.Schedules) { if (schedule.ScheduleID == greenhouseSchedule.ScheduleID) { JObject block = new JObject(); block.Add("temperature", schedule.InternalTemperature); block.Add("humidity", schedule.Humidity); block.Add("waterlevel", schedule.WaterLevel); block.Add("light_blue", schedule.BlueLight); block.Add("light_red", schedule.RedLight); daySchedule.Add("block" + schedule.Blocknumber, block); } } db.SaveChanges(); } jsonSchedule.Add("day1", daySchedule); jsonSchedule.Add("procedure", "applySchedule"); jsonSchedule.Add("days", 1); return(jsonSchedule); }
public static void MyClassInitialize(TestContext testContext) { db = new GreenhouseDBContext(); scheduleID = "UnitTestSchedule"; wrongScheduleID = "UnitTestSchedule1"; blueLight = 20; redLight = 30; temperature = 40; humidity = 50; waterlevel = 10; for (int blockNumber = 1; blockNumber < 13; blockNumber++) { Schedule schedule = new Schedule(); schedule.ScheduleID = scheduleID; schedule.Blocknumber = blockNumber; schedule.BlueLight = blueLight; schedule.RedLight = redLight; schedule.InternalTemperature = temperature; schedule.Humidity = humidity; schedule.WaterLevel = waterlevel; db.Schedules.Add(schedule); db.SaveChanges(); } foreach (Schedule block in db.Schedules) { if (block.ScheduleID == wrongScheduleID) { db.Schedules.Remove(block); } } db.SaveChanges(); }
internal void setIPAddress(string id, string ip, string port) { GreenhouseDBContext db = new GreenhouseDBContext(); Greenhouse greenhouse = new Greenhouse(); String password = ""; bool changes = true; foreach (Greenhouse item in db.Greenhouses) { if (item.GreenhouseID == id) { if (!(item.IP == ip && item.Port == int.Parse(port))) { password = item.Password; db.Greenhouses.Remove(item); } else { changes = false; } } } if (changes) { db.SaveChanges(); greenhouse.GreenhouseID = id; greenhouse.IP = ip; greenhouse.Port = int.Parse(port); greenhouse.Password = password; db.Greenhouses.Add(greenhouse); db.SaveChanges(); } }
public static void MyClassInitialize(TestContext testContext) { db = new GreenhouseDBContext(); }
public void Startup() { // Arrange GreenhouseSchedule greenhouseSchedule = new GreenhouseSchedule(); greenhouseSchedule.GreenhouseID = greenhouse.GreenhouseID; greenhouseSchedule.ScheduleID = scheduleID; greenhouseSchedule.StartDate = DateTime.Parse("Thu, 17 Aug 2000 23:32:32 GMT", System.Globalization.CultureInfo.InvariantCulture); db.GreenhouseSchedules.Add(greenhouseSchedule); db.SaveChanges(); int startPort = 0; int newPort = 0; int sendPort = 8521; foreach (Greenhouse greenhouse in db.Greenhouses) { if (greenhouse.GreenhouseID == greenhouse.GreenhouseID) { startPort = greenhouse.Port; } } db.SaveChanges(); JObject expected = new JObject(); blocks = new Schedule[12]; for (int i = 1; i < 13; i++) { Schedule schedule = new Schedule(); schedule.Blocknumber = i; schedule.BlueLight = 20; schedule.RedLight = 20; schedule.InternalTemperature = 20; schedule.Humidity = 20; schedule.WaterLevel = 20; schedule.ScheduleID = scheduleID; blocks[i - 1] = schedule; } db.Schedules.AddRange(blocks); db.SaveChanges(); // Act JObject response = client.sendStartupMessage(sendPort); // Assert db = new GreenhouseDBContext(); bool scheduleIsCorrect = true; JObject day = (JObject)response.GetValue("day1"); for (int i = 1; i < 13; i++) { JObject block = (JObject)day.GetValue("block" + i); if (blocks[i - 1].BlueLight != (double)block.GetValue("light_blue")) { scheduleIsCorrect = false; break; } if (blocks[i - 1].RedLight != (double)block.GetValue("light_red")) { scheduleIsCorrect = false; break; } if (blocks[i - 1].InternalTemperature != (double)block.GetValue("temperature")) { scheduleIsCorrect = false; break; } if (blocks[i - 1].Humidity != (double)block.GetValue("humidity")) { scheduleIsCorrect = false; break; } if (blocks[i - 1].WaterLevel != (double)block.GetValue("waterlevel")) { scheduleIsCorrect = false; break; } } Assert.IsTrue(scheduleIsCorrect); foreach (Greenhouse greenhouse in db.Greenhouses) { if (greenhouse.GreenhouseID == greenhouse.GreenhouseID) { newPort = greenhouse.Port; } } db.SaveChanges(); Assert.AreNotEqual(startPort, newPort); Assert.AreEqual(sendPort, newPort); }