public static void SaveToFile(String filePath, KspObject kspObjTree) { var craftToken = KspObjectWriter.WriteObject(kspObjTree); var craftString = KspTokenWriter.WriteToken(craftToken, new StringBuilder()).ToString(); using (var textWriter = new StreamWriter(File.Create(filePath), Encoding.UTF8)) { textWriter.Write(craftString); } }
public void ReturnsEmptyObjectForEmptyFile() { // given var textIn = ""; // when var tokenIn = KspTokenReader.ReadToken(textIn); var kspObject = KspObjectReader.ReadObject(tokenIn); var tokenOut = KspObjectWriter.WriteObject(kspObject); var textOut = KspTokenWriter.WriteToken(tokenOut, new StringBuilder()).ToString(); // then Assert.That(textOut, Is.EqualTo(textIn)); }
public void CanReadAndWriteKspObjectsFromSaveFileString() { // given var textIn = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("KSPPartRemover.Tests.Resources.Refuel at Minmus.in.sfs")).ReadToEnd(); // when var tokenIn = KspTokenReader.ReadToken(textIn); var kspObject = KspObjectReader.ReadObject(tokenIn); var tokenOut = KspObjectWriter.WriteObject(kspObject); var textOut = KspTokenWriter.WriteToken(tokenOut, new StringBuilder()).ToString(); // then Assert.That(textOut, Is.EqualTo(textIn)); }
private String KspObjToString(KspObject obj) { var token = KspObjectWriter.WriteObject(obj); return(KspTokenWriter.WriteToken(token, new StringBuilder()).ToString()); }