public void LoadTest() { var p = new MockPlanning(); var firstTask = new MockTask(); var secondTask = new MockTask(); int index = 10; p.currentDayIndex = index; p.SetContent(new List <IWeek> { new IWeek(new List <AbstractDay> { new Day(new List <AbstractTask> { firstTask }), new Day(), new Day(), new Day(), new Day(), new Day(), new Day(), }), new IWeek(new List <AbstractDay> { new Day(new List <AbstractTask> { secondTask }), new Day(), new Day(), new Day(), new Day(), new Day(), new Day(new List <AbstractTask> { new MockTask() }), }) }); var rm = new ConsoleRoadmap(p); rm.ShowRoadmap(); var loader = new PlanningLoader(); var json = loader.GetJson(p); AbstractPlanning loadedPlanningMemory = loader.LoadFromJson(json, typeof(MockPlanning)); Assert.IsNotNull(loadedPlanningMemory); Assert.IsNotNull(loadedPlanningMemory.GetDays()); string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Loaded planning test.json"; loader.Save(path, loadedPlanningMemory); AbstractPlanning loadedPlanningWithFile = loader.Load(path, typeof(MockPlanning)); Assert.IsNotNull(loadedPlanningWithFile); Assert.IsNotNull(loadedPlanningMemory.GetDays()); File.Delete(path); Assert.AreEqual(index, p.currentDayIndex); }
public override string GetJson(AbstractPlanning p) { if (p.weeks == null) { if (AbstractPlanning.LOG_SAVE) { Console.WriteLine("Getting json mode : Saving"); } p.weeks = new List <IWeek>(); var allDays = p.GetDays(); // Console.WriteLine("Days to save : " + allDays.Count); var dayIndex = 0; for (int i = 0; i < p.GetWeekCount(); i++) { var days = new List <AbstractDay>(); for (int j = 0; j < 7 && dayIndex < allDays.Count; j++) { days.Add(allDays[dayIndex]); dayIndex++; } // If the week is not complete, fill it with empty days p.weeks.Add(new IWeek(days)); } } else { Console.WriteLine("Getting json mode : Loading"); var allDays = p.GetDays(); if (allDays == null) { p.SetContent(p.weeks); } } return(JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto })); }