PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Tools/MPRepository/MPRepository.Tests/ItemTests.cs

https://github.com/jcaroon/MediaPortal-1
C# | 227 lines | 167 code | 39 blank | 21 comment | 5 complexity | d315dc49700b3f421663fe1b2536dccd MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. #region Copyright (C) 2005-2009 Team MediaPortal
  2. /*
  3. * Copyright (C) 2005-2009 Team MediaPortal
  4. * http://www.team-mediaportal.com
  5. *
  6. * This Program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This Program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Make; see the file COPYING. If not, write to
  18. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. */
  22. #endregion
  23. using System;
  24. using System.Collections.Generic;
  25. using Iesi.Collections.Generic;
  26. using System.Text;
  27. using NHibernate;
  28. using NHibernate.Criterion;
  29. using MPRepository.Items;
  30. using MPRepository.Support;
  31. using MPRepository.Controller;
  32. using NUnit.Framework;
  33. namespace MPRepository.Tests
  34. {
  35. [TestFixture]
  36. public class ItemTests
  37. {
  38. [Test]
  39. public void TestTagsAdd()
  40. {
  41. string[,] tags =
  42. {
  43. { "video", "video tag" },
  44. { "music", "music tag" },
  45. { "picture", "picture tag" },
  46. { "test1", "test tag" },
  47. };
  48. using (ISession session = DatabaseHelper.GetCurrentSession())
  49. {
  50. using (ITransaction transaction = session.BeginTransaction())
  51. {
  52. for (int i = 0; i <= tags.GetUpperBound(0); i++)
  53. {
  54. MPTag tag = new MPTag();
  55. tag.Name = tags[i,0];
  56. tag.Description = tags[i,1];
  57. session.SaveOrUpdate(tag);
  58. }
  59. transaction.Commit();
  60. }
  61. }
  62. }
  63. [Test]
  64. public void TestTagsParse()
  65. {
  66. //string tagsList = "video,music,test2,test3";
  67. string tagsList = "video,music,test1";
  68. MPRSession session = MPRController.StartSession();
  69. ISet<MPTag> tags = MPRController.GetTags(session, tagsList);
  70. Assert.That(tags.Count, Is.EqualTo(3));
  71. foreach (MPTag tag in tags)
  72. {
  73. System.Console.WriteLine("{0} : {1}", tag.Id, tag.Name);
  74. }
  75. MPRController.EndSession(session, true);
  76. }
  77. [Test]
  78. public void TestTypeAdd()
  79. {
  80. string[,] types =
  81. {
  82. { "Codecs", "Different multimedia codecs." },
  83. { "Drivers", "Drivers for different hardware" },
  84. { "HTPC Customization", "Customize your HTPC the way you like it" },
  85. { "Plugins", "Plugins for extended functionality" },
  86. { "Skins", "Download skins to make Media Portal look the way YOU want it." },
  87. { "System Utilities", "System utillties to aid your way." },
  88. };
  89. using (ISession session = DatabaseHelper.GetCurrentSession())
  90. {
  91. using (ITransaction transaction = session.BeginTransaction())
  92. {
  93. for (int i = 0; i <= types.GetUpperBound(0); i++)
  94. {
  95. MPItemType type = new MPItemType();
  96. type.Name = types[i, 0];
  97. type.Description = types[i, 1];
  98. session.SaveOrUpdate(type);
  99. }
  100. transaction.Commit();
  101. }
  102. }
  103. }
  104. [Test]
  105. public void TestCategoryAdd()
  106. {
  107. string[,] categories =
  108. { // type, category, description
  109. { "Codecs", "Audio", "Codecs for audio" },
  110. { "Codecs", "Video", "Codecs for video" },
  111. { "Codecs", "Audio & Video", "Codecs for both audio and video" },
  112. { "Plugins", "Audio/Radio", "Plugins for audio" },
  113. { "Plugins", "Automation", "Automating MediaPortal tasks" },
  114. { "Plugins", "EPG/TV", "EPG - Electronic Program Guide programs/grabbers" },
  115. { "Plugins", "Web", "Web stuff for Media Portal" },
  116. { "Plugins", "Video/Movies", "Plugins for video" },
  117. { "Skins", "16:10", "Skins created to use on a 16:10 (widescreen) television/monitor." },
  118. { "Skins", "16:9", "Skins created to use on a 16:9 (widescreen) television/monitor." },
  119. { "Skins", "4:3", "Skins created to use on a 4:3(non-widescreen) television/monitor." },
  120. { "Skins", "Tools", "Skin tools" },
  121. };
  122. using (ISession session = DatabaseHelper.GetCurrentSession())
  123. {
  124. using (ITransaction transaction = session.BeginTransaction())
  125. {
  126. string prevType = null;
  127. MPItemType mptype = null;
  128. for (int i = 0; i <= categories.GetUpperBound(0); i++)
  129. {
  130. string type = categories[i, 0];
  131. if (type != prevType)
  132. { // load new type
  133. mptype = session
  134. .CreateQuery("from MPItemType mptype where mptype.Name=?")
  135. .SetString(0, type)
  136. .UniqueResult<MPItemType>();
  137. prevType = type;
  138. }
  139. Assert.NotNull(mptype);
  140. Assert.That(mptype.Name, Is.EqualTo(type));
  141. MPCategory category = new MPCategory();
  142. category.Type = mptype;
  143. category.Name = categories[i, 1];
  144. category.Description = categories[i, 2];
  145. session.SaveOrUpdate(category);
  146. }
  147. transaction.Commit();
  148. }
  149. }
  150. }
  151. [Test]
  152. public void TestGetAllTypes()
  153. {
  154. MPRSession session = MPRController.StartSession();
  155. IList<MPItemType> types = MPRController.RetrieveAll<MPItemType>(session);
  156. foreach (MPItemType type in types)
  157. {
  158. System.Console.WriteLine("{0} : {1} : {2}", type.Id, type.Name, type.Description);
  159. }
  160. MPRController.EndSession(session, true);
  161. }
  162. [Test]
  163. public void GetCategoriesForType()
  164. {
  165. Int64 typeId = 4;
  166. MPRSession session = MPRController.StartSession();
  167. IList<MPCategory> categories = MPRController.RetrieveByForeignKey<MPCategory>(session, "Type", typeId);
  168. foreach (MPCategory category in categories)
  169. {
  170. System.Console.WriteLine("{0}:{1}:{2};", category.Id, category.Name, category.Description);
  171. }
  172. MPRController.EndSession(session, true);
  173. }
  174. [Test]
  175. public void GetCategoriesForIdList()
  176. {
  177. MPRSession session = MPRController.StartSession();
  178. List<Int64> ids = new List<Int64>();
  179. ids.Add(5); ids.Add(7); ids.Add(8);
  180. IList<MPCategory> categories = MPRController.RetrieveByIdList<MPCategory>(session, ids);
  181. Assert.That(categories.Count, Is.EqualTo(3));
  182. foreach (MPCategory category in categories)
  183. {
  184. System.Console.WriteLine("{0} : {1} : {2}", category.Id, category.Name, category.Description);
  185. }
  186. }
  187. }
  188. }