public static ConfigData GetData() { if (instance != null) return instance; else { Stream s; ConfigData cd = new ConfigData(); BinaryFormatter bf = new BinaryFormatter(); if (File.Exists(ConfigData.FILENAME) && File.ReadAllLines(ConfigData.FILENAME).Length > 0) { s = File.Open(ConfigData.FILENAME, FileMode.OpenOrCreate); cd = (ConfigData)bf.Deserialize(s); } else { s = File.Open(ConfigData.FILENAME, FileMode.OpenOrCreate); bf.Serialize(s, cd); } s.Close(); instance = cd; return cd; } }
public void GetDataTest() { ConfigData expected = new ConfigData(); ConfigData actual; actual = Config.GetData(); // Both objects should have the same value Assert.AreEqual(expected.oauth_token, actual.oauth_token); Assert.AreEqual(expected.oauth_token_secret, actual.oauth_token_secret); Assert.AreEqual(expected.developer_mode, actual.developer_mode); // Check for file on disk Assert.IsTrue(File.Exists(ConfigData.FILENAME)); }
public void IsUserAuthenticatedTest() { // should return false for empty Config Data ConfigData target = new ConfigData(); Assert.IsFalse(target.IsUserAuthenticated()); target.oauth_token = "aasdoh0e9h8füin"; Assert.IsFalse(target.IsUserAuthenticated()); target.oauth_token = null; target.oauth_token_secret = "038tzhüi0hü0s8egspdfnpn++"; Assert.IsFalse(target.IsUserAuthenticated()); // should only work when both are set target.oauth_token = "aasdoh0e9h8füin"; Assert.IsTrue(target.IsUserAuthenticated()); }