public void TestPortSerialization() { var currentSettingsDir = ComponentSettings.GetSettingsDirectory("Bench"); // Try to invoke the ComponentSettings serializer/deserializer for connections // Important thing is that a TestPort is still a TestPort after serialization. ComponentSettings.SetSettingsProfile("Bench", "test1"); InstrumentSettings.Current.ToList(); TestPortInstrument Instr = new TestPortInstrument(); InstrumentSettings.Current.Add(Instr); RfConnection conn = new RfConnection() { Port1 = Instr.Port1, Port2 = Instr.Port2 }; ConnectionSettings.Current.Clear(); ConnectionSettings.Current.Add(conn); ComponentSettings.SaveAllCurrentSettings(); ComponentSettings.SetSettingsProfile("Bench", "test2"); InstrumentSettings.Current.ToList(); // make componentsettings reload. ComponentSettings.SetSettingsProfile("Bench", "test1"); var instr2 = InstrumentSettings.Current.OfType <TestPortInstrument>().First(); Assert.IsFalse(object.ReferenceEquals(instr2, Instr)); Instr = instr2; conn = ConnectionSettings.Current.OfType <RfConnection>().First(con => (con.Port1 is TestPort)); // Now try to serialize a test plan with a Port inside it. try { TestPlan plan = new TestPlan { }; plan.ChildTestSteps.Add(new TestPortStep() { SelectedPort = Instr.Port1 }); TestPlan newplan; using (var str = new MemoryStream(1000)) { plan.Save(str); str.Position = 0; newplan = TestPlan.Load(str, plan.Path); } TestPortStep step = (TestPortStep)newplan.ChildTestSteps.First(); Assert.IsTrue(step.SelectedPort is TestPort); } finally { // Cleanup ConnectionSettings.Current.Remove(conn); InstrumentSettings.Current.Remove(Instr); ComponentSettings.SaveAllCurrentSettings(); ComponentSettings.SetSettingsProfile("Bench", currentSettingsDir); } }
public static void SetSettingsDir(string dir) { ComponentSettings.PersistSettingGroups = false; string settingsSetDir = Path.Combine(ComponentSettings.SettingsDirectoryRoot, "Bench", dir); if (dir != "Default" && !Directory.Exists(settingsSetDir)) { Console.WriteLine("Could not find settings directory \"{0}\"", settingsSetDir); RunCliAction.Exit(ExitStatus.ArgumentError); } ComponentSettings.SetSettingsProfile("Bench", dir); log.TraceInformation("Settings: " + ComponentSettings.GetSettingsDirectory("Bench")); }