I’m again here to ask I can solve the possibility of loading and saving a testplan not form / to a file but from an XML formatted string.
The purpose is to store test plans in a database available for multiple test systems. I could save the string in a temporary file and then apply the Load and Save functions of the TestPlan class, but I would like to know if there is a direct way without using a file.
Thanks for your help
There is an overload of TestPlan.Load and TestPlan.Save which takes a Stream. You can use those for any situation where you don’t have an actual file.
The best candidate to do this is
TestPlan.Load(Stream stream, string path)
but I code this with no success
// create a memory stream froma string // xml is a string xml-formatted byte byteArray = Encoding.ASCII.GetBytes(xml); MemoryStream stream = new MemoryStream(byteArray); // Load test plan from string (path is null) var testPlan = TestPlan.Load(stream, null); // To check if all is OK save in a new memory stream MemoryStream stream2 = new MemoryStream(); testPlan.Save(stream2); // convert stream to string StreamReader reader = new StreamReader(stream2); string text = reader.ReadToEnd(); Console.WriteLine(text);
Nothing in text
Hmm, I think you should rewind stream2 before reading from it with the stream reader.
//... MemoryStream stream2 = new MemoryStream(); testPlan.Save(stream2); // set stream2 position to the beginning for the stream2.Seek(0, SeekOrigin.Set); // convert stream to string StreamReader reader = new StreamReader(stream2); // ...
GREET!!! It’s works