Exemplo n.º 1
0
 public void TestCopyTo_Copies()
 {
     StringAdapter list = new StringAdapter("Hello");
     char[] output = new char[list.Count];
     list.CopyTo(output, 0);
     Assert.AreEqual("Hello", new String(output), "The values were not copied.");
 }
Exemplo n.º 2
0
 public void TestCopyTo_Copies_StartingAtArrayIndex()
 {
     StringAdapter list = new StringAdapter("Hello");
     char[] output = new char[list.Count + 2];
     output[0] = 'a';
     output[1] = 'a';
     list.CopyTo(output, 2);
     Assert.AreEqual("aaHello", new String(output), "The values were not copied.");
 }
Exemplo n.º 3
0
        private IAdapter GetAdapter(XElement element)
        {
            string adapterType = GetAttribute(element, "Type");
            string adapterName = GetAttribute(element, "Name");

            IAdapter adapter = null;

            var channelElement = element.Element("Channel");
            if (channelElement == null)
            {
                throw new ElementNotFoundException("Channel elemnt not found.");
            }

            var interpreterElement = element.Element("Interpreter");
            if (interpreterElement == null)
            {
                throw new ElementNotFoundException("Interpreter elemnt not found.");
            }

            if (adapterType == "ByteArrayAdapter")
            {
                IChannel<byte[]> channel = (IChannel<byte[]>)GetChannel(channelElement);
                IInterpreter<byte[]> interpreter = (IInterpreter<byte[]>)GetInterpreter(interpreterElement);

                adapter = new ByteArrayAdapter(adapterName, channel, interpreter);
            }
            else if (adapterType == "StringAdapter")
            {
                IChannel<string> channel = (IChannel<string>)GetChannel(channelElement);
                IInterpreter<string> interpreter = (IInterpreter<string>)GetInterpreter(interpreterElement);

                adapter = new StringAdapter(adapterName, channel, interpreter);
            }
            else
            {
                throw new UnknownElementException("Unknown adapter type:" + adapterType);
            }

            _adapterObjects[_currentAdapterName].Add(adapter.Name, adapter);

            return adapter;
        }
Exemplo n.º 4
0
 public void TestCtor_SetsUnderlyingString()
 {
     const string value = "Hello";
     StringAdapter list = new StringAdapter(value);
     Assert.AreSame(value, list.Value, "The backing field was not set.");
     Assert.AreEqual(value.Length, list.Count, "The counts did not match.");
     Assert.IsTrue(((ICollection<char>)list).IsReadOnly, "The list should have been read-only.");
 }
Exemplo n.º 5
0
 public void TestContains_ValueDoesNotExists_ReturnsFalse()
 {
     StringAdapter list = new StringAdapter("Hello");
     bool result = list.Contains('r');
     Assert.IsFalse(result, "The character should not have been found.");
 }
Exemplo n.º 6
0
 public void TestContains_ValueExists_ReturnsTrue()
 {
     StringAdapter list = new StringAdapter("Hello");
     bool result = list.Contains('e');
     Assert.IsTrue(result, "The character should have been found.");
 }
Exemplo n.º 7
0
 public void TestAdd_Throws()
 {
     IList<char> list = new StringAdapter("Hello");
     list.Add('a');
 }
Exemplo n.º 8
0
 public void TestClear_Throws()
 {
     IList<char> list = new StringAdapter("Hello");
     list.Clear();
 }
Exemplo n.º 9
0
 public void TestInsert_Throws()
 {
     IList<char> list = new StringAdapter("Hello");
     list.Insert(0, 'a');
 }
Exemplo n.º 10
0
 public void TestRemove_Throws()
 {
     IList<char> list = new StringAdapter("Hello");
     list.Remove('e');
 }
Exemplo n.º 11
0
 public void TestIndexOf_ValueNotFound_ReturnsNegativeOne()
 {
     StringAdapter list = new StringAdapter("Hello");
     int index = list.IndexOf('r');
     Assert.AreEqual(-1, index, "The wrong index was returned.");
 }
Exemplo n.º 12
0
 public void TestIndexOf_ValueFound_ReturnsFirst()
 {
     StringAdapter list = new StringAdapter("Hello, Yellow");
     int index = list.IndexOf('e');
     Assert.AreEqual(1, index, "The wrong index was returned.");
 }
Exemplo n.º 13
0
 public void TestIndexer_Setter_Throws()
 {
     string value = "Hello";
     StringAdapter list = new StringAdapter(value);
     list[0] = 'a';
 }
Exemplo n.º 14
0
 public void TestIndexer_Getter_ReturnsCharacter()
 {
     string value = "Hello";
     StringAdapter list = new StringAdapter(value);
     Assert.AreEqual(list[2], value[2], "The index returned the wrong value.");
 }
Exemplo n.º 15
0
 public void TestGetEnumerable_Implicit_StillEnumerates()
 {
     IEnumerable list = new StringAdapter("Hello");
     IEnumerator enumerator = list.GetEnumerator();
     moveAndCheck(enumerator, 'H');
     moveAndCheck(enumerator, 'e');
     moveAndCheck(enumerator, 'l');
     moveAndCheck(enumerator, 'l');
     moveAndCheck(enumerator, 'o');
     Assert.IsFalse(enumerator.MoveNext(), "There should not have been any more items.");
 }