public void PreferenceSet_Set_ThrowsOnReadOnlyPreference_Test() { // Arrange var prefs = new InMemoryPreferenceSet(); // Act & Assert Assert.Throws <InvalidOperationException>(() => prefs.Set(Preference.ApplicationPath, String.Empty)); }
public void PreferenceSet_Get_ThrowsOnDataTypeMismatch_Test() { // Arrange var prefs = new InMemoryPreferenceSet(); // Act & Assert Assert.Throws <ArgumentException>(() => prefs.Get <int>(Preference.CacheFolder)); }
public void PreferenceSet_Set_ThrowsOnDataTypeMismatch_Test() { // Arrange var prefs = new InMemoryPreferenceSet(); // Act & Assert Assert.Throws <ArgumentException>(() => prefs.Set(Preference.ClientRetrievalTask, String.Empty)); }
public void PreferenceSet_Set_StringAsEnum_Test() { // Arrange var data = new PreferenceData(); var prefs = new InMemoryPreferenceSet(data); // Act prefs.Set(Preference.BonusCalculation, BonusCalculation.Default); // Assert Assert.AreEqual("Default", data.ApplicationSettings.BonusCalculation); }
public void PreferenceSet_Set_String_Test() { var data = new PreferenceData(); var prefs = new InMemoryPreferenceSet(data); prefs.Set(Preference.EmailReportingFromAddress, (string)null); Assert.AreEqual(null, data.Email.FromAddress); prefs.Set(Preference.EmailReportingFromAddress, "*****@*****.**"); Assert.AreEqual("*****@*****.**", data.Email.FromAddress); prefs.Set(Preference.EmailReportingFromAddress, "*****@*****.**"); Assert.AreEqual("*****@*****.**", data.Email.FromAddress); }
public void PreferenceSet_RoundTripEncryptedPreference_Test() { // Arrange const string value = "fizzbizz"; var data = new PreferenceData(); var prefs = new InMemoryPreferenceSet(data); // Act prefs.Set(Preference.WebGenPassword, value); // Assert Assert.AreNotEqual(value, data.WebDeployment.FtpServer.Password); Assert.AreEqual(value, prefs.Get <string>(Preference.WebGenPassword)); }
public void PreferenceSet_Get_StringAsEnum_Test() { // Arrange var data = new PreferenceData(); data.ApplicationSettings.BonusCalculation = "DownloadTime"; var prefs = new InMemoryPreferenceSet(data); // Act var value = prefs.Get <BonusCalculation>(Preference.BonusCalculation); // Assert Assert.AreEqual(BonusCalculation.DownloadTime, value); }
public void PreferenceSet_Get_StringAsEnum_ReturnsEnumDefaultWhenParsingFails_Test() { // Arrange var data = new PreferenceData(); data.ApplicationSettings.BonusCalculation = "Foo"; var prefs = new InMemoryPreferenceSet(data); // Act var value = prefs.Get <BonusCalculation>(Preference.BonusCalculation); // Assert Assert.AreEqual(BonusCalculation.Default, value); }
public void PreferenceSet_Get_NullStringAsEnum_ReturnsEnumDefaultWhenParsingFails_Test() { // Arrange var data = new PreferenceData(); data.WebDeployment.FtpMode = null; var prefs = new InMemoryPreferenceSet(data); // Act var value = prefs.Get <FtpMode>(Preference.WebGenFtpMode); // Assert Assert.AreEqual(FtpMode.Default, value); }
public void PreferenceSet_Get_Collection_Benchmark() { var prefs = new InMemoryPreferenceSet(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { // ReSharper disable once UnusedVariable var obj = prefs.Get <IEnumerable <Color> >(Preference.GraphColors); } sw.Stop(); Debug.WriteLine("Get Collection: {0}ms", sw.ElapsedMilliseconds); }
public void PreferenceSet_Get_NullCollection_Benchmark() { var prefs = new InMemoryPreferenceSet(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { // ReSharper disable once UnusedVariable var obj = prefs.Get <ICollection <string> >(Preference.FormColumns); } sw.Stop(); Debug.WriteLine("Get Null Collection: {0}ms", sw.ElapsedMilliseconds); }
public void PreferenceSet_Get_Class_Benchmark() { var prefs = new InMemoryPreferenceSet(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { // ReSharper disable once UnusedVariable var obj = prefs.Get <ClientRetrievalTask>(Preference.ClientRetrievalTask); } sw.Stop(); Debug.WriteLine("Get Class: {0}ms", sw.ElapsedMilliseconds); }
public void PreferenceSet_Set_ValueType_Test() { var data = new PreferenceData(); var prefs = new InMemoryPreferenceSet(data); prefs.Set(Preference.FormSplitterLocation, (object)null); Assert.AreEqual(0, data.MainWindowState.SplitterLocation); prefs.Set(Preference.FormSplitterLocation, "60"); Assert.AreEqual(60, data.MainWindowState.SplitterLocation); prefs.Set(Preference.FormSplitterLocation, 120); Assert.AreEqual(120, data.MainWindowState.SplitterLocation); prefs.Set(Preference.FormSplitterLocation, 360); Assert.AreEqual(360, data.MainWindowState.SplitterLocation); }
public void PreferenceSet_Get_ValueType_Benchmark() { var prefs = new InMemoryPreferenceSet(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { // ReSharper disable once UnusedVariable var obj = prefs.Get <int>(Preference.FormSplitterLocation); } sw.Stop(); Debug.WriteLine("Get ValueType: {0}ms", sw.ElapsedMilliseconds); }
public void PreferenceSet_Get_String_Benchmark() { var prefs = new InMemoryPreferenceSet(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { // ReSharper disable once UnusedVariable var obj = prefs.Get <string>(Preference.CacheFolder); } sw.Stop(); Debug.WriteLine("Get String: {0}ms", sw.ElapsedMilliseconds); }
public void PreferenceSet_Set_Collection_Test() { var data = new PreferenceData(); var prefs = new InMemoryPreferenceSet(data); prefs.Set(Preference.FormColumns, (List <string>)null); Assert.AreEqual(null, data.MainWindowGrid.Columns); var enumerable = (IEnumerable <string>) new[] { "a", "b", "c" }; prefs.Set(Preference.FormColumns, enumerable); Assert.AreEqual(3, data.MainWindowGrid.Columns.Count); Assert.AreNotSame(enumerable, data.MainWindowGrid.Columns); var collection = (ICollection <string>) new[] { "a", "b", "c" }; prefs.Set(Preference.FormColumns, collection); Assert.AreEqual(3, data.MainWindowGrid.Columns.Count); Assert.AreNotSame(collection, data.MainWindowGrid.Columns); }
public void PreferenceSet_Set_Class_Test() { var data = new PreferenceData(); var prefs = new InMemoryPreferenceSet(data); ClientRetrievalTask task = null; prefs.Set(Preference.ClientRetrievalTask, task); Assert.AreEqual(null, data.ClientRetrievalTask); task = new ClientRetrievalTask(); prefs.Set(Preference.ClientRetrievalTask, task); Assert.AreNotSame(task, data.ClientRetrievalTask); task = new ClientRetrievalTask { Enabled = false }; prefs.Set(Preference.ClientRetrievalTask, task); Assert.AreNotSame(task, data.ClientRetrievalTask); }
public void PreferenceSet_PreferenceChanged_Test() { // Arrange var prefs = new InMemoryPreferenceSet(); object sender = null; PreferenceChangedEventArgs args = null; prefs.PreferenceChanged += (s, e) => { sender = s; args = e; }; // Act prefs.Set(Preference.ColorLogFile, false); // Assert Assert.AreSame(prefs, sender); Assert.AreEqual(Preference.ColorLogFile, args.Preference); }
public void PreferenceSet_Get_Test() { var prefs = new InMemoryPreferenceSet(); // value type Assert.AreEqual(360, prefs.Get <int>(Preference.FormSplitterLocation)); // underlying string is null Assert.AreEqual(String.Empty, prefs.Get <string>(Preference.EmailReportingFromAddress)); // string Assert.AreEqual("logcache", prefs.Get <string>(Preference.CacheFolder)); // class var task1 = prefs.Get <ClientRetrievalTask>(Preference.ClientRetrievalTask); var task2 = prefs.Get <ClientRetrievalTask>(Preference.ClientRetrievalTask); Assert.AreNotSame(task1, task2); Assert.AreEqual(new ClientRetrievalTask(), task1); // underlying collection is null Assert.IsNull(prefs.Get <ICollection <string> >(Preference.FormColumns)); // collection var graphColors1 = prefs.Get <IEnumerable <Color> >(Preference.GraphColors); var graphColors2 = prefs.Get <IEnumerable <Color> >(Preference.GraphColors); Assert.AreNotSame(graphColors1, graphColors2); }