public void TestDuplicates() { FileStream fileStream = null; try { Console.WriteLine("Loading " + DuplicateTestFile); fileStream = new FileStream(DuplicateTestFile, FileMode.Open); JavaProperties properties = new JavaProperties(); properties.Load(fileStream); fileStream.Close(); Assert.AreEqual(properties.Count, 1); Assert.IsTrue("c".Equals(properties.GetProperty("a"))); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { if (fileStream != null) { fileStream.Close(); } } }
public void TestMissingProperty() { FileStream fileStream = null; try { Console.WriteLine("Loading " + EmptyTestFile); var defaults = new Dictionary <string, string> { { "test", "value" } }; fileStream = new FileStream(EmptyTestFile, FileMode.Open); JavaProperties properties = new JavaProperties(defaults); properties.Load(fileStream); fileStream.Close(); Assert.IsEmpty(properties); Assert.IsNull(properties.GetProperty("NonExistent")); Assert.AreEqual(defaults["test"], properties.GetProperty("test")); Assert.IsNull(properties.SetProperty("NonExistant", "a new value")); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { if (fileStream != null) { fileStream.Close(); } } }
public void TestDuplicates() { FileStream fileStream = null; try { Console.WriteLine("Loading " + DuplicateTestFile); fileStream = new FileStream(DuplicateTestFile, FileMode.Open); JavaProperties properties = new JavaProperties(); properties.Load(fileStream); fileStream.Close(); Assert.AreEqual( properties.Count, 1 ); Assert.IsTrue( "c".Equals(properties.GetProperty("a") ) ); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { if (fileStream != null) { fileStream.Close(); } } }
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(); } } }