[SystemSettings] Add SystemSettings.UnitTest (#679)
[platform/core/csapi/tizenfx.git] / test / Tizen.System.SystemSettings.UnitTest / SystemSettings.UnitTest / test / TSEmailAlertRingtoneChangedEventArgs.cs
1 using System.Threading.Tasks;
2 using System;
3 using System.Threading;
4 using Tizen.System;
5
6
7 namespace SystemSettingsUnitTest
8 {
9     //[TestFixture]
10     //[Description("Tizen.System.EmailAlertRingtoneChangedEventArgs Tests")]
11     public static class EmailAlertRingtoneChangedEventArgsTests
12     {
13         private static bool s_emailAlertRingtoneCallbackCalled = false;
14         private static readonly string s_emailAlertRingtoneValue = SystemSettingsTestInput.GetStringValue((int)Tizen.System.SystemSettingsKeys.EmailAlertRingtone);
15         ////[Test]
16         //[Category("P1")]
17         //[Description("Check EmailAlertRingtoneChangedEventArgs Value property")]
18         //[Property("SPEC", "Tizen.System.EmailAlertRingtoneChangedEventArgs.Value A")]
19         //[Property("SPEC_URL", "-")]
20         //[Property("CRITERIA", "PRO")]
21         //[Property("AUTHOR", "Aditya Aswani, a.aswani@samsung.com")]
22         public static async Task Value_PROPERTY_READ_ONLY()
23         {
24             try {
25                 LogUtils.StartTest();
26                 /*
27                  * PRECONDITION
28                  * 1. Assign event handler
29                  */
30                 Tizen.System.SystemSettings.EmailAlertRingtoneChanged += OnEmailAlertRingtoneChangedValue;
31
32                 string preValue = Tizen.System.SystemSettings.EmailAlertRingtone;
33                 Tizen.System.SystemSettings.EmailAlertRingtone = s_emailAlertRingtoneValue;
34                 await Task.Delay(2000);
35                 Assert.IsTrue(s_emailAlertRingtoneCallbackCalled, "Value_PROPERTY_READ_ONLY: EventHandler added. Not getting called");
36
37                 /*
38                  * POSTCONDITION
39                  * 1. Reset callback called flag
40                  * 2. Remove event handler
41                  * 3. Reset property value
42                  */
43                 s_emailAlertRingtoneCallbackCalled = false;
44                 Tizen.System.SystemSettings.EmailAlertRingtoneChanged -= OnEmailAlertRingtoneChangedValue;
45                 Tizen.System.SystemSettings.EmailAlertRingtone = preValue;
46                 LogUtils.WriteOK();
47             } catch (NotSupportedException) {
48                 bool isSupport = true;
49                 Information.TryGetValue<bool>("tizen.org/feature/systemsetting.notification_email", out isSupport);
50                 Assert.IsTrue(isSupport == false, "Invalid NotSupportedException");
51                 Tizen.Log.Debug("CS-SYSTEM-SETTINGS", ">>>>>> NotSupport(tizen.org/feature/systemsetting.notification_email)");
52                 LogUtils.NotSupport();
53             }
54         }
55         private static void OnEmailAlertRingtoneChangedValue(object sender, Tizen.System.EmailAlertRingtoneChangedEventArgs e)
56         {
57             s_emailAlertRingtoneCallbackCalled = true;
58             /* TEST CODE */
59             Assert.IsInstanceOf<string>(e.Value, "OnEmailAlertRingtoneChangedValue: EmailAlertRingtone not an instance of string");
60             Assert.IsTrue(s_emailAlertRingtoneValue.CompareTo(e.Value) == 0, "OnEmailAlertRingtoneChanged: The callback should receive the latest value for the property.");
61         }
62
63     }
64 }