Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. using NUnit.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using OpenQA.Selenium.Firefox;
  5. using OpenQA.Selenium.Support.UI;
  6. using OpenQA.Selenium;
  7.  
  8. namespace GenericsVsAggregationForCustomElementsImplementation
  9. {
  10. namespace ViaInheritance
  11. {
  12. namespace core
  13. {
  14. public interface IElement
  15. {
  16. string Describe();
  17. }
  18.  
  19. public class Element : IElement
  20. {
  21. public string Describe()
  22. {
  23. return "described";
  24. }
  25. }
  26.  
  27. public interface ICollection<out T> where T : IElement, new()
  28. {
  29. T this [int index] { get; }
  30. }
  31.  
  32. public class Collection<T> : ICollection<T> where T : IElement, new()
  33. {
  34. public T this [int index]
  35. {
  36. get
  37. {
  38. return new T();
  39. }
  40. }
  41. }
  42. }
  43.  
  44. namespace tests
  45. {
  46. namespace straightforward
  47. {
  48. using core;
  49.  
  50. public class MyElement : Element
  51. {
  52. public string Select()
  53. {
  54. return "selected";
  55. }
  56. }
  57.  
  58. [TestFixture]
  59. public class Test
  60. {
  61. [Test]
  62. public void TestCase()
  63. {
  64.  
  65. ICollection<MyElement> myElements = new Collection<MyElement>();
  66. Assert.AreEqual("described",myElements[1].Describe());
  67. Assert.AreEqual("selected", myElements[1].Select());
  68.  
  69. ICollection<Element> elements = myElements;
  70. Assert.AreEqual("described", elements[1].Describe());
  71. }
  72. }
  73. }
  74.  
  75. namespace withsteps
  76. {
  77. using core;
  78.  
  79. public class MyElement : Element
  80. {
  81. public string Select()
  82. {
  83. return "selected";
  84. }
  85. }
  86.  
  87. public class MyElementsList
  88. {
  89. public ICollection<MyElement> elements()
  90. {
  91. return new Collection<MyElement>();
  92. }
  93.  
  94. public string Describe(int index)
  95. {
  96. return elements()[index].Describe();
  97. }
  98.  
  99. public string Select(int index)
  100. {
  101. return elements()[index].Select();
  102. }
  103. }
  104.  
  105. [TestFixture]
  106. public class Test
  107. {
  108. [Test]
  109. public void TestCase()
  110. {
  111.  
  112. MyElementsList myElementsList = new MyElementsList();
  113. Assert.AreEqual("described",myElementsList.Describe(1));
  114. Assert.AreEqual("selected", myElementsList.Select(1));
  115.  
  116. ICollection<Element> elements = myElementsList.elements();
  117. Assert.AreEqual("described", elements[1].Describe());
  118. }
  119. }
  120. }
  121. }
  122. }
  123.  
  124. namespace ViaAggregation
  125. {
  126. namespace core
  127. {
  128. public interface IElement
  129. {
  130. string Describe();
  131. }
  132.  
  133. public class Element : IElement
  134. {
  135. public string Describe()
  136. {
  137. return "described";
  138. }
  139. }
  140.  
  141. public interface ICollection
  142. {
  143. IElement this [int index] { get; }
  144. }
  145.  
  146. public class Collection : ICollection
  147. {
  148. public IElement this [int index]
  149. {
  150. get
  151. {
  152. return new Element();
  153. }
  154. }
  155. }
  156. }
  157.  
  158. namespace tests
  159. {
  160. namespace straightforward
  161. {
  162. using core;
  163.  
  164. public class MyElement
  165. {
  166. public IElement Element;
  167.  
  168. public MyElement(IElement element)
  169. {
  170. this.Element = element;
  171. }
  172.  
  173. public string Select()
  174. {
  175. return "selected";
  176. }
  177. }
  178.  
  179. [TestFixture]
  180. public class Test
  181. {
  182. [Test]
  183. public void TestCase()
  184. {
  185. ICollection elements = new Collection();
  186. Assert.AreEqual("described", elements[1].Describe());
  187.  
  188. Assert.AreEqual("selected", new MyElement(elements[1]).Select());
  189.  
  190. //...
  191. }
  192. }
  193. }
  194.  
  195. namespace withsteps
  196. {
  197. using core;
  198.  
  199. public class MyElement
  200. {
  201. public IElement Element;
  202.  
  203. public MyElement(IElement element)
  204. {
  205. this.Element = element;
  206. }
  207.  
  208. public string Select()
  209. {
  210. return "selected";
  211. }
  212. }
  213.  
  214. public class MyElementsList
  215. {
  216. public ICollection elements()
  217. {
  218. return new Collection();
  219. }
  220.  
  221. public string Describe(int index)
  222. {
  223. return elements()[index].Describe();
  224. }
  225.  
  226. public string Select(int index)
  227. {
  228. return new MyElement(elements()[index]).Select();
  229. }
  230. }
  231.  
  232. [TestFixture]
  233. public class Test
  234. {
  235. [Test]
  236. public void TestCase()
  237. {
  238. MyElementsList myElementsList = new MyElementsList();
  239. Assert.AreEqual("described",myElementsList.Describe(1));
  240.  
  241. Assert.AreEqual("selected", myElementsList.Select(1));
  242.  
  243. ICollection elements = myElementsList.elements();
  244. Assert.AreEqual("described", elements[1].Describe());
  245. }
  246. }
  247. }
  248. }
  249. }
  250.  
  251. namespace ViaDynamicProxyingNotFinishedImplementation
  252. {
  253. public interface IElement
  254. {
  255. string Describe();
  256. }
  257.  
  258. public class Element : IElement
  259. {
  260. public string Describe()
  261. {
  262. return "described";
  263. }
  264. }
  265.  
  266. public interface ICollection<out T> where T : IElement, new()
  267. {
  268. T this [int index] { get; }
  269. }
  270.  
  271. public class Collection<T> : ICollection<T> where T : IElement, new()
  272. {
  273. public T this [int index]
  274. {
  275. get
  276. {
  277. return new T();
  278. }
  279. }
  280.  
  281. public Collection<Element> ToCollectionOfElements()
  282. {
  283. return this as Collection<Element>;
  284. }
  285. }
  286.  
  287.  
  288. public class MyElement : Element
  289. {
  290. public string Select()
  291. {
  292. return "selected";
  293. }
  294. }
  295.  
  296. [TestFixture]
  297. public class Test
  298. {
  299. [Test]
  300. public static void TestCase(Test instance)
  301. {
  302. //new WebDriverWait(new FirefoxDriver(), TimeSpan.FromSeconds(1))
  303. //.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.Id("")));
  304. //typeof(Element).GetConstructor(new Type[]{}).Invoke(new object[] {})
  305. ICollection<MyElement> myElements = new Collection<MyElement>();
  306. Assert.AreEqual("described",myElements[1].Describe());
  307. Assert.AreEqual("selected", myElements[1].Select());
  308.  
  309. ICollection<Element> elements = myElements;
  310. Assert.AreEqual("described", elements[1].Describe());
  311. }
  312. }
  313. }
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement