public void TestFileExists() { string filePath = "test" + _testCulture + ".properties"; string data = "testKey=testValue" + Environment.NewLine + Environment.NewLine; string fullTempPath = Path.GetTempPath() + filePath; File.WriteAllBytes(fullTempPath, Encoding.UTF8.GetBytes(data)); try { LocalizableMessageStorage messageStorage = new LocalizableMessageStorage(Path.GetTempPath(), FilePattern); File.Delete(Environment.CurrentDirectory + filePath); Assert.AreEqual(messageStorage.GetLocalizedMessage(_testCulture, "testKey"), "testValue", "Messages do not match the input to the file"); Assert.IsNull(messageStorage.GetLocalizedMessage(_testCulture, "IDoNotExist"), "Non-existent key should return null"); } catch(Exception ex) { Assert.Fail("LocalizableMessageStorage should not have thrown an exception: {0}", ex); } }
public void TestComments() { string filePath = "\\test" + _testCulture + ".properties"; string data = "#comment1" + Environment.NewLine + "//comment2" + Environment.NewLine + "--comment3" + Environment.NewLine + "testKey=testValue#--//" + Environment.NewLine + Environment.NewLine; string fullTempPath = Path.GetTempPath() + filePath; File.WriteAllBytes(fullTempPath, Encoding.UTF8.GetBytes(data)); try { LocalizableMessageStorage messageStorage = new LocalizableMessageStorage(Path.GetTempPath(), FilePattern); File.Delete(Environment.CurrentDirectory + filePath); Assert.AreEqual(messageStorage.GetLocalizedMessage(_testCulture, "testKey"), "testValue#--//", "Messages do not match the input to the file"); Assert.AreEqual(1, messageStorage.GetMessagesCountForLocale(_testCulture), "There should only have been one actual message in this file."); } catch (Exception ex) { Assert.Fail("LocalizableMessageStorage should not have thrown an exception: {0}", ex); } }
public void TestNewLineEscape() { string filePath = "\\test" + _testCulture + ".properties"; string stringValue = "Some Value/" + Environment.NewLine + " Another Value" + Environment.NewLine; string data = "key=" + stringValue; string fullTempPath = Path.GetTempPath() + filePath; File.WriteAllBytes(fullTempPath, Encoding.UTF8.GetBytes(data)); LocalizableMessageStorage messageStorage = new LocalizableMessageStorage(Path.GetTempPath(), FilePattern); File.Delete(Environment.CurrentDirectory + filePath); Assert.AreEqual(1, messageStorage.GetMessagesCountForLocale(_testCulture), "There should only have been one actual message in this file."); string expectedValue = "Some Value Another Value"; Assert.AreEqual(expectedValue, messageStorage.GetLocalizedMessage(_testCulture, "key")); }
public void TestSpecialCharacters() { string filePath = "\\test" + _testCulture + ".properties"; string stringValue = "Some Value <a href='test'>Another Value</a>" + Environment.NewLine; string data = "key=" + stringValue; string fullTempPath = Path.GetTempPath() + filePath; File.WriteAllBytes(fullTempPath, Encoding.UTF8.GetBytes(data)); LocalizableMessageStorage messageStorage = new LocalizableMessageStorage(Path.GetTempPath(), FilePattern); File.Delete(Environment.CurrentDirectory + filePath); Assert.AreEqual(1, messageStorage.GetMessagesCountForLocale(_testCulture), "There should only have been one actual message in this file."); string trimmedValue = stringValue.TrimEnd(Environment.NewLine.ToCharArray()); Assert.AreEqual(trimmedValue, messageStorage.GetLocalizedMessage(_testCulture, "key")); }
public void TestLocaleNonExistent() { LocalizableMessageStorage messageStorage = new LocalizableMessageStorage(Environment.CurrentDirectory, "blah"); try { CultureInfo testCulture = CultureInfo.GetCultures(CultureTypes.SpecificCultures)[0]; messageStorage.GetLocalizedMessage(testCulture, null); Assert.Fail("Non-existent culture should have thrown an UserLocaleNotSupportedException."); } catch(UserLocaleNotSupportedException) { } }