/src/Framework/Tests/Persistence/Sources/ContentSourceTests.cs

https://github.com/lundbeck/n2cms · C# · 223 lines · 178 code · 45 blank · 0 comment · 0 complexity · e2dd99830a2a30f15b17edaa2020f0f1 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NUnit.Framework;
  6. using N2.Persistence.Sources;
  7. using N2.Persistence;
  8. namespace N2.Tests.Persistence.Sources
  9. {
  10. [TestFixture]
  11. public class ContentSourceTests
  12. {
  13. [Test]
  14. public void DatabaseSource_IsOrderedLast()
  15. {
  16. ContentSource cs = new ContentSource(new Fakes.FakeSecurityManager(), new SourceBase[] { new DatabaseSource(null, null), new ActiveContentSource() });
  17. Assert.That(cs.Sources.Last(), Is.TypeOf<DatabaseSource>());
  18. }
  19. [Test]
  20. public void DatabaseSource_IsOrdered_AfterInterfaceSource()
  21. {
  22. ContentSource cs = new ContentSource(new Fakes.FakeSecurityManager(), new SourceBase[] {
  23. new DatabaseSource(null, null),
  24. new TestSource()
  25. });
  26. Assert.That(cs.Sources.Last(), Is.TypeOf<DatabaseSource>());
  27. }
  28. [Test]
  29. public void Get_IsDelegated_ToSources()
  30. {
  31. ContentSource cs = CreateSource();
  32. Assert.Throws<MarkerException>(() => cs.Get(1));
  33. }
  34. [Test]
  35. public void AppendChildren_IsDelegated_ToSources()
  36. {
  37. ContentSource cs = CreateSource();
  38. Assert.Throws<MarkerException>(() => cs.AppendChildren(Enumerable.Empty<ContentItem>(), new Query()));
  39. }
  40. [Test]
  41. public void Copy_IsDelegated_ToSources()
  42. {
  43. ContentSource cs = CreateSource();
  44. Assert.Throws<MarkerException>(() => cs.Copy(new TestSourceItem(), new TestSourceItem()));
  45. }
  46. [Test]
  47. public void Delete_IsDelegated_ToSources()
  48. {
  49. ContentSource cs = CreateSource();
  50. Assert.Throws<MarkerException>(() => cs.Delete(new TestSourceItem()));
  51. }
  52. [Test]
  53. public void GetChildren_IsDelegated_ToSources()
  54. {
  55. ContentSource cs = CreateSource();
  56. Assert.Throws<MarkerException>(() => cs.GetChildren(new Query()));
  57. }
  58. [Test]
  59. public void GetSource_IsDelegated_ToSources()
  60. {
  61. ContentSource cs = CreateSource();
  62. Assert.Throws<MarkerException>(() => cs.GetSource(new TestSourceItem()));
  63. }
  64. [Test]
  65. public void HasChildren_IsDelegated_ToSources()
  66. {
  67. ContentSource cs = CreateSource();
  68. Assert.Throws<MarkerException>(() => cs.HasChildren(new Query()));
  69. }
  70. [Test]
  71. public void IsProvidedBy_IsDelegated_ToSources()
  72. {
  73. ContentSource cs = CreateSource();
  74. Assert.Throws<MarkerException>(() => cs.IsProvidedBy(new TestSourceItem()));
  75. }
  76. [Test]
  77. public void Move_IsDelegated_ToSources()
  78. {
  79. ContentSource cs = CreateSource();
  80. Assert.Throws<MarkerException>(() => cs.Move(new TestSourceItem(), new TestSourceItem()));
  81. }
  82. [Test]
  83. public void ResolvePath_IsDelegated_ToSources()
  84. {
  85. ContentSource cs = CreateSource();
  86. Assert.Throws<MarkerException>(() => cs.ResolvePath("/hello/world"));
  87. }
  88. [Test]
  89. public void ResolvePath_FromStartingPoint_IsDelegated_ToSources()
  90. {
  91. ContentSource cs = CreateSource();
  92. Assert.Throws<MarkerException>(() => cs.ResolvePath(new TestSourceItem(), "/hello/world"));
  93. }
  94. [Test]
  95. public void Save_FromStartingPoint_IsDelegated_ToSources()
  96. {
  97. ContentSource cs = CreateSource();
  98. Assert.Throws<MarkerException>(() => cs.Save(new TestSourceItem()));
  99. }
  100. private static ContentSource CreateSource()
  101. {
  102. ContentSource cs = new ContentSource(new Fakes.FakeSecurityManager(), new SourceBase[] {
  103. new DatabaseSource(null, null),
  104. new TestSource()
  105. });
  106. return cs;
  107. }
  108. class TestSourceItem : ContentItem, IActiveContent
  109. {
  110. public void Save()
  111. {
  112. throw new NotImplementedException();
  113. }
  114. public void Delete()
  115. {
  116. throw new NotImplementedException();
  117. }
  118. public void MoveTo(ContentItem destination)
  119. {
  120. throw new NotImplementedException();
  121. }
  122. public ContentItem CopyTo(ContentItem destination)
  123. {
  124. throw new NotImplementedException();
  125. }
  126. }
  127. class MarkerException : Exception
  128. {
  129. }
  130. class TestSource : SourceBase
  131. {
  132. public TestSource()
  133. {
  134. BaseContentType = typeof(IActiveContent);
  135. }
  136. public override bool ProvidesChildrenFor(ContentItem parent)
  137. {
  138. throw new MarkerException();
  139. }
  140. public override N2.Web.PathData ResolvePath(ContentItem startingPoint, string path)
  141. {
  142. throw new MarkerException();
  143. }
  144. public override N2.Web.PathData ResolvePath(string path)
  145. {
  146. throw new MarkerException();
  147. }
  148. public override IEnumerable<ContentItem> AppendChildren(IEnumerable<ContentItem> previousChildren, Query query)
  149. {
  150. throw new MarkerException();
  151. }
  152. public override bool IsProvidedBy(ContentItem item)
  153. {
  154. throw new MarkerException();
  155. }
  156. public override ContentItem Get(object id)
  157. {
  158. throw new MarkerException();
  159. }
  160. public override void Save(ContentItem item)
  161. {
  162. throw new MarkerException();
  163. }
  164. public override void Delete(ContentItem item)
  165. {
  166. throw new MarkerException();
  167. }
  168. public override ContentItem Move(ContentItem source, ContentItem destination)
  169. {
  170. throw new MarkerException();
  171. }
  172. public override ContentItem Copy(ContentItem source, ContentItem destination)
  173. {
  174. throw new MarkerException();
  175. }
  176. }
  177. }
  178. }