[NUI] Update TCs of NUI.Devel.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / XamlBinding / TSBindingExpression.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Reflection;
7 using System.Collections.Generic;
8 using Tizen.NUI.Binding;
9
10 namespace Tizen.NUI.Devel.Tests
11 {
12     using tlog = Tizen.Log;
13
14     [TestFixture]
15     [Description("internal/XamlBinding/BindingExpression")]
16     public class InternalBindingExpressionTest
17     {
18         private const string tag = "NUITEST";
19         private string selfpath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "Test_View.xaml";
20
21         [SetUp]
22         public void Init()
23         {
24             tlog.Info(tag, "Init() is called!");
25         }
26
27         [TearDown]
28         public void Destroy()
29         {
30             tlog.Info(tag, "Destroy() is called!");
31         }
32
33         [Test]
34         [Category("P1")]
35         [Description("BindingExpression constructor")]
36         [Property("SPEC", "Tizen.NUI.BindingExpression.BindingExpression C")]
37         [Property("SPEC_URL", "-")]
38         [Property("CRITERIA", "CONSTR")]
39         public void BindingExpressionConstructor()
40         {
41             tlog.Debug(tag, $"BindingExpressionConstructor START");
42
43             var testingTarget = new BindingExpression(new TemplateBinding(), selfpath);
44             Assert.IsNotNull(testingTarget, "Can't create success object BindingExpression.");
45             Assert.IsInstanceOf<BindingExpression>(testingTarget, "Should return BindingExpression instance.");
46
47             tlog.Debug(tag, "Binding : " + testingTarget.Binding);
48
49             tlog.Debug(tag, $"BindingExpressionConstructor END");
50         }
51
52         [Test]
53         [Category("P2")]
54         [Description("BindingExpression constructor")]
55         [Property("SPEC", "Tizen.NUI.BindingExpression.BindingExpression C")]
56         [Property("SPEC_URL", "-")]
57         [Property("CRITERIA", "CONSTR")]
58         public void BindingExpressionConstructorNullBinding()
59         {
60             tlog.Debug(tag, $"BindingExpressionConstructorNullBinding START");
61
62             BindingBase binding = null;
63             try
64             {
65                 var testingTarget = new BindingExpression(binding, selfpath);
66             }
67             catch (ArgumentNullException)
68             {
69                 tlog.Debug(tag, $"BindingExpressionConstructorNullBinding END");
70                 Assert.Pass("Caught ArgumentNullException : Passed!");
71             }
72         }
73
74         [Test]
75         [Category("P2")]
76         [Description("BindingExpression constructor")]
77         [Property("SPEC", "Tizen.NUI.BindingExpression.BindingExpression C")]
78         [Property("SPEC_URL", "-")]
79         [Property("CRITERIA", "CONSTR")]
80         public void BindingExpressionConstructorNullPath()
81         {
82             tlog.Debug(tag, $"BindingExpressionConstructorNullPath START");
83
84             try
85             {
86                 var testingTarget = new BindingExpression(new TemplateBinding(), null);
87             }
88             catch (ArgumentNullException)
89             {
90                 tlog.Debug(tag, $"BindingExpressionConstructorNullPath END");
91                 Assert.Pass("Caught ArgumentNullException : Passed!");
92             }
93         }
94
95         [Test]
96         [Category("P1")]
97         [Description("BindingExpression Apply")]
98         [Property("SPEC", "Tizen.NUI.BindingExpression.Apply M")]
99         [Property("SPEC_URL", "-")]
100         [Property("CRITERIA", "MR")]
101         public void BindingExpressionApplyNullSource()
102         {
103             tlog.Debug(tag, $"BindingExpressionApplyNullSource START");
104
105             var testingTarget = new BindingExpression(new TemplateBinding(), selfpath);
106             Assert.IsNotNull(testingTarget, "Can't create success object BindingExpression.");
107             Assert.IsInstanceOf<BindingExpression>(testingTarget, "Should return BindingExpression instance.");
108
109             try
110             {
111                 testingTarget.Apply(false);
112             }
113             catch (Exception e)
114             {
115                 tlog.Debug(tag, e.Message.ToString());
116                 Assert.Fail("Caught Exception : Failed!");
117             }
118
119             tlog.Debug(tag, $"BindingExpressionApplyNullSource END");
120         }
121
122         [Test]
123         [Category("P1")]
124         [Description("BindingExpression Apply")]
125         [Property("SPEC", "Tizen.NUI.BindingExpression.Apply M")]
126         [Property("SPEC_URL", "-")]
127         [Property("CRITERIA", "MR")]
128         public void BindingExpressionApply()
129         {
130             tlog.Debug(tag, $"BindingExpressionApply START");
131
132             var testingTarget = new BindingExpression(new TemplateBinding(), selfpath);
133             Assert.IsNotNull(testingTarget, "Can't create success object BindingExpression.");
134             Assert.IsInstanceOf<BindingExpression>(testingTarget, "Should return BindingExpression instance.");
135
136             try
137             {
138                 using (View view = new View() { Color = Color.Red })
139                 {
140                     using (View preView = new View() { Color = Color.Cyan })
141                     {
142                         BindableProperty property = BindableProperty.Create("myProperty", typeof(string), typeof(View), null, BindingMode.OneWay,
143                                                   null, null, null, null, null);
144
145                         testingTarget.Apply(view, preView, property);
146                         testingTarget.Apply(true);
147                         testingTarget.Apply(false);
148                         testingTarget.Unapply();
149                     }
150                 }
151             }
152             catch (Exception e)
153             {
154                 tlog.Debug(tag, e.Message.ToString());
155                 Assert.Fail("Caught Exception : Failed!");
156             }
157
158             tlog.Debug(tag, $"BindingExpressionApply END");
159         }
160     }
161 }