2bbcb8959b3265cbfe6b46d3a97fd3d169649c7d
[platform/core/csapi/media-content.git] / tct-mediacontent-tizen-tests / src / Testcase / TSTag.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Threading.Tasks;
4 using TestFramework;
5 using Tizen.Content.MediaContent;
6
7 namespace TizenTest.MediaInformationT
8 {
9     [TestFixture]
10     [Description("Tizen.Content.MediaContent.Tag Tests")]
11     class TSTag
12     {
13                 private static string TAG = "TCT";
14         private static string _mediaTag = "ut.xyz.tagTest";
15         static Tag _myTag = null;
16         static MediaInformation _myMedia;
17         [SetUp]
18         public static void Init()
19         {
20         }
21
22         [TearDown]
23         public static void Destroy()
24         {
25             //LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for each TEST");
26         }
27         [Test]
28         [Category("P1")]
29         [Description("Test for Tag Properties Getter ...")]
30         [Property("SPEC", " Tizen.Content.MediaContent.Tag.Id A")]
31         [Property("SPEC_URL", "-")]
32         [Property("CRITERIA", "PRO")]
33         [Property("AUTHOR", "Praveen Kumar Gattu, gattu.p@samsung.com")]
34         public static void TagId_READ()
35         {
36                          _mediaTag = "TAGSUPER5";
37                          Tag tag = new Tag(_mediaTag);
38             try
39             {
40                                 Tizen.Log.Info(TAG, "Executing TC:TagId_READ");
41                  ContentManager.Database.Insert(tag);
42                 int id = tag.Id;
43                 Tizen.Log.Info(TAG, "Executing TC:TagId_READ Id" + id);
44                 LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Executing TC:TagId_READ Name : "+ id);
45                 ContentManager.Database.Delete(tag);
46                 Tizen.Log.Info(TAG, "Executing TC:TagId_READ delete");
47             }
48             catch (Exception e)
49             {
50                                 LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Executing TC:TagName_READ Name : "+ e.Message);
51                                 Tizen.Log.Info(TAG, "Executing TC:TagId_READ delete "+ e.Message);
52                 Assert.Fail();
53             }
54         }
55
56         [Test]
57         [Category("P1")]
58         [Description("Test for Tag Properties Getter ...")]
59         [Property("SPEC", " Tizen.Content.MediaContent.Tag.Name A")]
60         [Property("SPEC_URL", "-")]
61         [Property("CRITERIA", "PRO")]
62         [Property("AUTHOR", "Praveen Kumar Gattu, gattu.p@samsung.com")]
63         public static void TagName_READ()
64         {
65                          _mediaTag = "TAGSUPER3";
66                          Tag tag = new Tag(_mediaTag);
67             try
68             {
69                                 Tizen.Log.Info(TAG, "Executing TC:TagName_READ");
70                 ContentManager.Database.Insert(tag);
71                 string name =  tag.Name;
72                 Tizen.Log.Info(TAG, "Executing TC:TagName_READ Name : "+ name);
73                 LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Executing TC:TagName_READ Name : "+ name);
74                 ContentManager.Database.Delete(tag);
75                 if (name.CompareTo(_mediaTag) != 0)
76                     Assert.Fail();
77
78             }
79             catch (Exception e)
80             {
81                                 Tizen.Log.Info(TAG, "Executing TC:TagName_READ Name : "+ e.Message);
82                                 LogUtils.write(LogUtils.DEBUG, LogUtils.TAG, "Executing TC:TagName_READ Name : "+ e.Message);
83                 Assert.Fail();
84             }
85         }
86
87         [Test]
88         [Category("P1")]
89         [Description("Test for Tag add/remove Methods ...")]
90         [Property("SPEC", " Tizen.Content.MediaContent.Tag.AddItem M")]
91         [Property("SPEC_URL", "-")]
92         [Property("CRITERIA", "MR")]
93         [Property("AUTHOR", "Praveen Kumar Gattu, gattu.p@samsung.com")]
94         public static async Task TagAddAndRemoveItem_CHECK_RESULT()
95         {
96             int tagCount = 0;
97             try
98             {
99                            _mediaTag = "TAGSUPERCOUNT";
100                             Tag tag = new Tag(_mediaTag);
101                                 Tizen.Log.Info(TAG, "Executing TC:TagAddAndRemoveItem_CHECK_RESULT");
102                 ContentManager.Database.Insert(tag);
103                 IEnumerable<MediaInformation> list = await ContentManager.Database.SelectAsync<MediaInformation>(null);
104                 foreach(MediaInformation info in list)
105                 {
106                     _myMedia = info;
107                     tagCount = info.GetTagCount(null);
108                     Tizen.Log.Info(TAG, "Executing TC:TagAddAndRemoveItem_CHECK_RESULT tagCount " + tagCount );
109                     tag.AddItem(info);
110                     ContentManager.Database.Update(tag);
111                     int newTagCount = info.GetTagCount(null);
112                     Tizen.Log.Info(TAG, "Executing TC:TagAddAndRemoveItem_CHECK_RESULT tagCount " + newTagCount );
113                     Assert.IsTrue(tagCount+1 == info.GetTagCount(null), "After Adding new Tag , tag count be incremented.");
114                     break;
115                 }
116                 tag.RemoveItem(_myMedia);
117                 ContentManager.Database.Update(tag);
118                 Assert.IsTrue(tagCount == _myMedia.GetTagCount(null), "After Removing new Tag , tag count should be same.");
119                 ContentManager.Database.Delete(tag);
120                 Assert.Pass();
121             }
122             catch (Exception e)
123             {
124                                 Tizen.Log.Info(TAG, "Executing TC:TagAddAndRemoveItem_CHECK_RESULT exception " + e.Message);
125                 Assert.Fail();
126             }
127         }
128
129     }
130 }