Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUnit.Framework;
- using System;
- using System.Collections.Generic;
- using OpenQA.Selenium.Firefox;
- using OpenQA.Selenium.Support.UI;
- using OpenQA.Selenium;
- namespace GenericsVsAggregationForCustomElementsImplementation
- {
- namespace ViaInheritance
- {
- namespace core
- {
- public interface IElement
- {
- string Describe();
- }
- public class Element : IElement
- {
- public string Describe()
- {
- return "described";
- }
- }
- public interface ICollection<out T> where T : IElement, new()
- {
- T this [int index] { get; }
- }
- public class Collection<T> : ICollection<T> where T : IElement, new()
- {
- public T this [int index]
- {
- get
- {
- return new T();
- }
- }
- }
- }
- namespace tests
- {
- namespace straightforward
- {
- using core;
- public class MyElement : Element
- {
- public string Select()
- {
- return "selected";
- }
- }
- [TestFixture]
- public class Test
- {
- [Test]
- public void TestCase()
- {
- ICollection<MyElement> myElements = new Collection<MyElement>();
- Assert.AreEqual("described",myElements[1].Describe());
- Assert.AreEqual("selected", myElements[1].Select());
- ICollection<Element> elements = myElements;
- Assert.AreEqual("described", elements[1].Describe());
- }
- }
- }
- namespace withsteps
- {
- using core;
- public class MyElement : Element
- {
- public string Select()
- {
- return "selected";
- }
- }
- public class MyElementsList
- {
- public ICollection<MyElement> elements()
- {
- return new Collection<MyElement>();
- }
- public string Describe(int index)
- {
- return elements()[index].Describe();
- }
- public string Select(int index)
- {
- return elements()[index].Select();
- }
- }
- [TestFixture]
- public class Test
- {
- [Test]
- public void TestCase()
- {
- MyElementsList myElementsList = new MyElementsList();
- Assert.AreEqual("described",myElementsList.Describe(1));
- Assert.AreEqual("selected", myElementsList.Select(1));
- ICollection<Element> elements = myElementsList.elements();
- Assert.AreEqual("described", elements[1].Describe());
- }
- }
- }
- }
- }
- namespace ViaAggregation
- {
- namespace core
- {
- public interface IElement
- {
- string Describe();
- }
- public class Element : IElement
- {
- public string Describe()
- {
- return "described";
- }
- }
- public interface ICollection
- {
- IElement this [int index] { get; }
- }
- public class Collection : ICollection
- {
- public IElement this [int index]
- {
- get
- {
- return new Element();
- }
- }
- }
- }
- namespace tests
- {
- namespace straightforward
- {
- using core;
- public class MyElement
- {
- public IElement Element;
- public MyElement(IElement element)
- {
- this.Element = element;
- }
- public string Select()
- {
- return "selected";
- }
- }
- [TestFixture]
- public class Test
- {
- [Test]
- public void TestCase()
- {
- ICollection elements = new Collection();
- Assert.AreEqual("described", elements[1].Describe());
- Assert.AreEqual("selected", new MyElement(elements[1]).Select());
- //...
- }
- }
- }
- namespace withsteps
- {
- using core;
- public class MyElement
- {
- public IElement Element;
- public MyElement(IElement element)
- {
- this.Element = element;
- }
- public string Select()
- {
- return "selected";
- }
- }
- public class MyElementsList
- {
- public ICollection elements()
- {
- return new Collection();
- }
- public string Describe(int index)
- {
- return elements()[index].Describe();
- }
- public string Select(int index)
- {
- return new MyElement(elements()[index]).Select();
- }
- }
- [TestFixture]
- public class Test
- {
- [Test]
- public void TestCase()
- {
- MyElementsList myElementsList = new MyElementsList();
- Assert.AreEqual("described",myElementsList.Describe(1));
- Assert.AreEqual("selected", myElementsList.Select(1));
- ICollection elements = myElementsList.elements();
- Assert.AreEqual("described", elements[1].Describe());
- }
- }
- }
- }
- }
- namespace ViaDynamicProxyingNotFinishedImplementation
- {
- public interface IElement
- {
- string Describe();
- }
- public class Element : IElement
- {
- public string Describe()
- {
- return "described";
- }
- }
- public interface ICollection<out T> where T : IElement, new()
- {
- T this [int index] { get; }
- }
- public class Collection<T> : ICollection<T> where T : IElement, new()
- {
- public T this [int index]
- {
- get
- {
- return new T();
- }
- }
- public Collection<Element> ToCollectionOfElements()
- {
- return this as Collection<Element>;
- }
- }
- public class MyElement : Element
- {
- public string Select()
- {
- return "selected";
- }
- }
- [TestFixture]
- public class Test
- {
- [Test]
- public static void TestCase(Test instance)
- {
- //new WebDriverWait(new FirefoxDriver(), TimeSpan.FromSeconds(1))
- //.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.Id("")));
- //typeof(Element).GetConstructor(new Type[]{}).Invoke(new object[] {})
- ICollection<MyElement> myElements = new Collection<MyElement>();
- Assert.AreEqual("described",myElements[1].Describe());
- Assert.AreEqual("selected", myElements[1].Select());
- ICollection<Element> elements = myElements;
- Assert.AreEqual("described", elements[1].Describe());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement