public void XmlPreferencesProvider_Load_FromConfigFile_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); // write a config.xml file var data = new PreferenceData { ApplicationVersion = applicationVersion }; data.ApplicationSettings.CacheFolder = "foo"; using (var fileStream = new FileStream(Path.Combine(artifacts.Path, "config.xml"), FileMode.Create, FileAccess.Write)) using (var xmlWriter = XmlWriter.Create(fileStream, new XmlWriterSettings { Indent = true })) { var serializer = new DataContractSerializer(typeof(PreferenceData)); serializer.WriteObject(xmlWriter, data); } var prefs = Create(artifacts.Path, applicationVersion); // Act prefs.Load(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); Assert.AreEqual("foo", prefs.Get <string>(Preference.CacheFolder)); } }
public void XmlPreferencesProvider_Load_LoadsDefaultsWhenNoConfigXmlOrUserSettingsExists_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); var prefs = Create(artifacts.Path, applicationVersion); Assert.IsFalse(File.Exists(configPath)); // Act prefs.Load(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); } }
public void PreferenceSet_Reset_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); var prefs = Create(artifacts.Path, applicationVersion); Assert.IsFalse(File.Exists(configPath)); // Act prefs.Reset(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); } }
public void XmlPreferencesProvider_Load_ExecutesPreferenceUpgrades_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); var prefs = new TestPreferenceUpgradeXmlPreferencesProvider(artifacts.Path, applicationVersion); Assert.IsFalse(File.Exists(configPath)); // Act prefs.Load(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); Assert.AreEqual("https://apps.foldingathome.org/psummary.json", prefs.Get <string>(Preference.ProjectDownloadUrl)); } }
public void XmlPreferencesProvider_Load_LoadsDefaultsWhenConfigXmlReadFails_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); // write a config.xml file that will fail to read File.WriteAllText(configPath, String.Empty); var prefs = Create(artifacts.Path, applicationVersion); // Act prefs.Load(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); } }
public void PreferenceSet_Load_MigratesFromUserSettings_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); var prefs = new TestMigrateFromUserSettingsPreferenceSet(artifacts.Path, applicationVersion); Assert.IsFalse(File.Exists(configPath)); // Act prefs.Load(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); Assert.AreEqual("Foo", prefs.Get <string>(Preference.StanfordId)); } }
public void PreferenceSet_Load_ExecutesPreferenceUpgrades_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string configPath = Path.Combine(artifacts.Path, "config.xml"); var prefs = new TestPreferenceUpgradePreferenceSet(artifacts.Path, applicationVersion); Assert.IsFalse(File.Exists(configPath)); // Act prefs.Load(); // Assert Assert.IsTrue(File.Exists(configPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); Assert.AreEqual("http://assign.stanford.edu/api/project/summary", prefs.Get <string>(Preference.ProjectDownloadUrl)); } }
public void XmlPreferencesProvider_ConstructorArgumentValues_Test() { // Arrange using (var artifacts = new ArtifactFolder()) { const string applicationVersion = "1.0.0.0"; string applicationPath = Environment.CurrentDirectory; // Act var prefs = new XmlPreferencesProvider(applicationPath, artifacts.Path, applicationVersion); // Assert Assert.AreEqual(applicationPath, prefs.ApplicationPath); Assert.AreEqual(applicationPath, prefs.Get <string>(Preference.ApplicationPath)); Assert.AreEqual(artifacts.Path, prefs.ApplicationDataFolderPath); Assert.AreEqual(artifacts.Path, prefs.Get <string>(Preference.ApplicationDataFolderPath)); Assert.AreEqual(applicationVersion, prefs.ApplicationVersion); Assert.AreEqual(applicationVersion, prefs.Get <string>(Preference.ApplicationVersion)); string cacheDirectory = Path.Combine(artifacts.Path, "logcache"); Assert.AreEqual(cacheDirectory, prefs.Get <string>(Preference.CacheDirectory)); } }