public void GenerateSchedulePriorityTest() { //arrange ShiftTable shifts = new ShiftTable(); Shift shift1 = new Shift("", "", "Sunday", "7", "15", "Sion", "", ""); Shift shift2 = new Shift("", "", "Sunday", "15", "23", "Sion", "", ""); Shift shift3 = new Shift("", "", "Sunday", "23", "7", "Sion", "", ""); shifts.AddShift(shift1); shifts.AddShift(shift2); shifts.AddShift(shift3); ShiftTable options = new ShiftTable(); Shift option1 = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "Low", ""); Shift option2 = new Shift("123456789", "Polishuk", "Sunday", "15", "23", "Sion", "High", ""); Shift option3 = new Shift("123456789", "Polishuk", "Sunday", "23", "7", "Sion", "Low", ""); options.AddShift(option1); options.AddShift(option2); options.AddShift(option3); //act GenerateTable generator = new GenerateTable(options, shifts); ShiftTable schedule = generator.GenerateSchedule(); //assert Assert.AreEqual(schedule.GetAllShifts().Count, 1, "GenerateSchedulePriorityTest error: the number of shift do not mach expectation"); Assert.AreEqual(schedule.optionExists(option2), true, "GenerateSchedulePriorityTest error: the option do not exists"); }
public void divideLowOrHighTest() { //arrange Shift s1 = new Shift("", "", "Sunday", "7", "15", "", "High", ""); Shift s2 = new Shift("", "", "Thursday", "23", "3", "", "Low", ""); ShiftTable t1 = new ShiftTable(); t1.AddShift(s1); t1.AddShift(s2); GenerateTable gen = new GenerateTable(t1, null); ShiftTable high = gen.getHighPriorityOptions(); ShiftTable low = gen.getLowPriorityOptions(); //act bool result_low = low.shiftExists("Thursday", "23", "3"); bool result_high = high.shiftExists("Sunday", "7", "15"); //assert Assert.AreEqual(result_low, false, "divideLowOrHighTest error: the shift is high priotity, expected low"); Assert.AreEqual(result_high, true, "divideLowOrHighTest error: the shift is low priotity, expected high"); }
public string Generator(string tableName, string fieldName1, string dataType1, string fieldName2, string dataType2, string Parent) { try { if (Parent == null) //=> No Relation { var projectCollection = ProjectCollection.GlobalProjectCollection; string projPath = "~/BlogIT.Web.csproj"; var p = projectCollection.LoadProject(Server.MapPath(projPath)); string projItem1 = "~/Entities/" + tableName + ".cs"; GenerateTable genTable = new GenerateTable(tableName); genTable.AddFields(fieldName1, dataType1, fieldName2, dataType2); genTable.GenerateCSharpCode(Server.MapPath(projItem1)); p.AddItem("Compile", Server.MapPath(projItem1)); p.Save(); string projItem2 = "~/Mapping/" + tableName + "Map.cs"; GenerateMap genMap = new GenerateMap(tableName); genMap.AddConstructor(fieldName1, fieldName2, tableName); genMap.GenerateCSharpCode(Server.MapPath(projItem2)); p.AddItem("Compile", Server.MapPath(projItem2)); p.Save(); ProjectCollection.GlobalProjectCollection.UnloadProject(p); p.Build(); NHibernate.OpenSession(); } else if (Parent != null)//=> Relation To Parent { var projectCollection = ProjectCollection.GlobalProjectCollection; string projPath = "~/MVCNHibernate.csproj"; var p = projectCollection.LoadProject(Server.MapPath(projPath)); string fileNameEn = "~/Entities/" + tableName + ".cs"; GenerateTable genTable = new GenerateTable(tableName); genTable.RelationalAddFields(tableName, fieldName1, dataType1, fieldName2, dataType2, Parent); genTable.GenerateCSharpCode(Server.MapPath(fileNameEn)); string projItem1 = "~/Entities/" + tableName + ".cs"; p.AddItem("Compile", Server.MapPath(projItem1)); p.Save(); string fileNameMap = "~/Mapping/" + tableName + "Map.cs"; GenerateMap genMap = new GenerateMap(tableName); genMap.RelationalAddConstructor(fieldName1, fieldName2, tableName, Parent); genMap.GenerateCSharpCode(Server.MapPath(fileNameMap)); string projItem2 = "~/Mapping/" + tableName + "Map.cs"; p.AddItem("Compile", Server.MapPath(projItem2)); p.Save(); //ProjectCollection.GlobalProjectCollection.UnloadProject(p); ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); p.Build(); NHibernate.OpenSession(); } return("Database generated Successfully "); } catch { return("Database did not generate Successfully "); } }
protected void GenerateScheduleButton_Click(object sender, EventArgs e) { GT = new GenerateTable(shiftOptionsTable, weeklyShiftTable); weeklyShiftTable = GT.GenerateSchedule(); setNames(); foreach (Shift sh in weeklyShiftTable.GetAllShifts()) { string day = sh.getDay().Trim(); string begin = sh.getBegin_Time().Trim(); string name = sh.getName().Trim(); int index = 0; switch (day) { case "Sunday": index = 1; break; case "Monday": index = 2; break; case "Tusday": index = 3; break; case "Wednsday": index = 4; break; case "Thursday": index = 5; break; case "Friday": index = 6; break; case "Saturday": index = 7; break; } int j; int k; bool found = false; for (j = 0; j < WeeklyScheduleGrid.Rows.Count; j++) { if (WeeklyScheduleGrid.Rows[j].Cells[0].Text.Split('-')[0].Trim().Equals(begin)) { while (WeeklyScheduleGrid.Rows[j].Cells[0].Text.Split('-')[0].Trim().Equals(begin) && j < WeeklyScheduleGrid.Rows.Count-1) { if (!selectedIndexes[j, index]) { found = true; break; } j++; } break; } } if (found) { for (k = 0; k < ((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).Items.Count; k++) { if (!((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).Items[k].Text.Trim().Equals(name)) continue; ((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).SelectedIndex = k; ((DropDownList)WeeklyScheduleGrid.Rows[j].Cells[index].Controls[0]).ForeColor = System.Drawing.Color.DeepPink; selectedIndexes[j, index] = true; break; } } } }
public void GenerateScheduleSimpleTest1() { //arrange ShiftTable shifts = new ShiftTable(); Shift shift = new Shift("", "", "Sunday", "7", "15", "Sion", "", ""); shifts.AddShift(shift); ShiftTable options = new ShiftTable(); Shift option = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "", ""); options.AddShift(option); //act GenerateTable generator = new GenerateTable(options, shifts); ShiftTable schedule = generator.GenerateSchedule(); //assert Assert.AreEqual(schedule.GetAllShifts().Count, 1, "GenerateScheduleSimpleTest1 error: the number of shift do not mach expectation"); Assert.AreEqual(schedule.optionExists(option),true, "GenerateScheduleSimpleTest1 error: the option do not exists"); }
public void GenerateScheduleTest() { //arrange ShiftTable shifts = new ShiftTable(); Shift shift1 = new Shift("", "", "Sunday", "7", "15", "Sion", "", ""); Shift shift2 = new Shift("", "", "Sunday", "15", "23", "Sion", "", ""); Shift shift3 = new Shift("", "", "Sunday", "23", "7", "Sion", "", ""); Shift shift4 = new Shift("", "", "Monday", "7", "15", "Sion", "", ""); Shift shift5 = new Shift("", "", "Monday", "15", "23", "Sion", "", ""); Shift shift6 = new Shift("", "", "Monday", "23", "7", "Sion", "", ""); Shift shift7 = new Shift("", "", "Tuesday", "7", "15", "Sion", "", ""); Shift shift8 = new Shift("", "", "Tuesday", "15", "23", "Sion", "", ""); Shift shift9 = new Shift("", "", "Tuesday", "23", "7", "Sion", "", ""); Shift shift10 = new Shift("", "", "Wednesday", "7", "15", "Sion", "", ""); Shift shift11 = new Shift("", "", "Wednesday", "15", "23", "Sion", "", ""); Shift shift12 = new Shift("", "", "Wednesday", "23", "7", "Sion", "", ""); shifts.AddShift(shift1); shifts.AddShift(shift2); shifts.AddShift(shift3); shifts.AddShift(shift4); shifts.AddShift(shift5); shifts.AddShift(shift6); shifts.AddShift(shift7); shifts.AddShift(shift8); shifts.AddShift(shift9); shifts.AddShift(shift10); shifts.AddShift(shift11); shifts.AddShift(shift12); ShiftTable options = new ShiftTable(); Shift option1 = new Shift("123456789", "Polishuk", "Sunday", "7", "15", "Sion", "Low", ""); Shift option2 = new Shift("123456789", "Polishuk", "Sunday", "15", "23", "Sion", "High", ""); Shift option3 = new Shift("123456789", "Polishuk", "Sunday", "23", "7", "Sion", "High", ""); Shift option4 = new Shift("111222333", "Humi", "Sunday", "7", "15", "Sion", "High", ""); Shift option5 = new Shift("111222333", "Humi", "Monday", "7", "15", "Sion", "High", ""); Shift option6 = new Shift("111222333", "Humi", "Tuesday", "7", "15", "Sion", "High", ""); Shift option7 = new Shift("222333444", "Soli", "Wednesday", "7", "23", "Sion", "High", ""); Shift option8 = new Shift("222333444", "Soli", "Wednesday", "22", "7", "Sion", "High", ""); Shift option9 = new Shift("222333444", "Soli", "Wednesday", "7", "7", "Sion", "High", ""); Shift option10 = new Shift("333444555", "Kozo", "Wednesday", "7", "15", "Sion", "High", ""); Shift option11 = new Shift("333444555", "Kozo", "Wednesday", "15", "23", "Sion", "High", ""); Shift option12 = new Shift("333444555", "Kozo", "Wednesday", "23", "7", "Sion", "High", ""); Shift option13 = new Shift("444555666", "Tkuma", "Monday", "7", "15", "Sion", "High", ""); Shift option14 = new Shift("444555666", "Tkuma", "Monday", "15", "23", "Sion", "High", ""); options.AddShift(option1); options.AddShift(option2); options.AddShift(option3); options.AddShift(option4); options.AddShift(option5); options.AddShift(option6); //options.AddShift(option7); options.AddShift(option8); //options.AddShift(option9); options.AddShift(option10); options.AddShift(option11); options.AddShift(option12); options.AddShift(option13); options.AddShift(option14); //act GenerateTable generator = new GenerateTable(options, shifts); ShiftTable schedule = generator.GenerateSchedule(); //assert Assert.AreEqual(schedule.GetAllShifts().Count, 7, "GenerateScheduleTest error: the number of shift do not mach expectation"); Assert.AreEqual(schedule.optionExists(option2), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option4), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option5), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option6), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option10), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option12), true, "GenerateScheduleTest error: the option do not exists"); Assert.AreEqual(schedule.optionExists(option14), true, "GenerateScheduleTest error: the option do not exists"); }