public Store ( Stream streamOut, string comments ) : void | ||
streamOut | Stream | An output stream to write the properties to. |
comments | string | Optional additional comment to include at the head of the output. |
return | void |
public void JavaPropertyWriter_shouldNotWriteTimestampIfFalse() { JavaProperties properties = new JavaProperties(); using (var stream = new MemoryStream()) { properties.Store(stream, false); string actual = Encoding.GetEncoding("iso-8859-1").GetString(stream.ToArray()); Assert.IsEmpty(actual); } }
public void JavaPropertyWriter_shouldWriteTimestampIfTrue() { JavaProperties properties = new JavaProperties(); using (var stream = new MemoryStream()) { properties.Store(stream, true); string actual = Encoding.GetEncoding("iso-8859-1").GetString(stream.ToArray()); Assert.That(actual, Does.StartWith("#")); } }
public void JavaPropertyWriter_shouldWriteComment() { String comment = "a comment"; JavaProperties properties = new JavaProperties(); using (var stream = new MemoryStream()) { properties.Store(stream, comment); string actual = Encoding.GetEncoding("iso-8859-1").GetString(stream.ToArray()); Assert.That(actual, Does.Contain(comment)); } }
public void JavaPropertyWriter_shouldEscapeExtendedCharsInValue() { JavaProperties properties = new JavaProperties(); properties.Add("Greeting", "Привет"); using (var stream = new MemoryStream()) { properties.Store(stream, null); string actual = Encoding.GetEncoding("iso-8859-1").GetString(stream.ToArray()); Assert.That(actual, Does.Contain("Greeting=\\u041F\\u0440\\u0438\\u0432\\u0435\\u0442")); } }
public void JavaPropertyWriter_shouldEscapeColonInValue() { JavaProperties properties = new JavaProperties(); properties.Add("first", ":anything"); properties.Add("second", "noth:ing"); properties.Add("third", "something:"); using (var stream = new MemoryStream()) { properties.Store(stream, null); string actual = Encoding.GetEncoding("iso-8859-1").GetString(stream.ToArray()); Assert.That(actual, Does.Contain("first=\\:anything")); Assert.That(actual, Does.Contain("second=noth\\:ing")); Assert.That(actual, Does.Contain("third=something\\:")); } }
public void JavaPropertyWriter_shouldEscapeEqualsInKey() { JavaProperties properties = new JavaProperties(); properties.Add("=first", "anything"); properties.Add("sec=ond", "nothing"); properties.Add("third=", "something"); using (var stream = new MemoryStream()) { properties.Store(stream, null); string actual = Encoding.GetEncoding("iso-8859-1").GetString(stream.ToArray()); Assert.That(actual, Does.Contain("\\=first=anything")); Assert.That(actual, Does.Contain("sec\\=ond=nothing")); Assert.That(actual, Does.Contain("third\\==something")); } }
public void TestJavaPropertyWriter() { const string filename = JavaTestDataDirectory + "mixed.properties"; const string outName = JavaOutputDirectory + "test-writer.properties"; FileStream inStream = null; FileStream outStream = null; try { // Read the mixed properties file. Console.WriteLine("Loading " + filename); inStream = File.OpenRead(filename); JavaProperties properties1 = new JavaProperties(); properties1.Load( inStream ); inStream.Close(); inStream = null; // Write it to a new file - using the JavaPropertiesWriter we are testing. outStream = File.OpenWrite(outName); properties1.Store(outStream, "Testing JavaPropertyWriter"); outStream.Flush(); outStream.Close(); outStream = null; // Now re-read the output file into a second set of properties inStream = File.OpenRead(outName); JavaProperties properties2 = new JavaProperties(); properties2.Load(inStream); // Now compare the values - find, compare and remove each value in turn. foreach (String name in properties2.Keys) { String value2 = properties2.GetProperty(name); if (properties1.ContainsKey(name)) { String value1 = properties1.GetProperty(name); if (value1 == null) { if (value2 != null) { Assert.Fail("Original value is null, new value is : \"" + value2 + "\""); } } else if (!value1.Equals(value2)) { Assert.Fail("Original value is \"" + value1 + "\", new value is : \"" + value2 + "\""); } properties1.Remove( name ); } else { Assert.Fail("Missing property: \"" + name + "\" (with value \"" + value2 + "\")"); } } if( properties1.Count > 0 ) { Assert.Fail( properties1.Count + " values missing from output file."); } } catch (Exception ex) { Assert.Fail(ex.Message); } finally { if (inStream != null) { inStream.Close(); } if (outStream != null) { outStream.Close(); } } }
public void TestJavaPropertyWriter() { string filename = JavaTestDataDirectory + "/mixed.properties"; string outName = JavaOutputDirectory + "/test-writer.properties"; FileStream inStream = null; FileStream outStream = null; try { // Read the mixed properties file. Console.WriteLine("Loading " + filename); inStream = File.OpenRead(filename); JavaProperties properties1 = new JavaProperties(); properties1.Load(inStream); inStream.Close(); inStream = null; // Write it to a new file - using the JavaPropertiesWriter we are testing. outStream = File.OpenWrite(outName); properties1.Store(outStream, "Testing JavaPropertyWriter"); outStream.Flush(); outStream.Close(); outStream = null; // Now re-read the output file into a second set of properties inStream = File.OpenRead(outName); JavaProperties properties2 = new JavaProperties(); properties2.Load(inStream); // Now compare the values - find, compare and remove each value in turn. foreach (String name in properties2.Keys) { String value2 = properties2.GetProperty(name); if (properties1.ContainsKey(name)) { String value1 = properties1.GetProperty(name); if (value1 == null) { if (value2 != null) { Assert.Fail("Original value is null, new value is : \"" + value2 + "\""); } } else if (!value1.Equals(value2)) { Assert.Fail("Original value is \"" + value1 + "\", new value is : \"" + value2 + "\""); } properties1.Remove(name); } else { Assert.Fail("Missing property: \"" + name + "\" (with value \"" + value2 + "\")"); } } if (properties1.Count > 0) { Assert.Fail(properties1.Count + " values missing from output file."); } } catch (Exception ex) { Assert.Fail(ex.Message); } finally { if (inStream != null) { inStream.Close(); } if (outStream != null) { outStream.Close(); } } }