Exemplo n.º 1
0
        public void GetFirstEntity_Throw_When_None_Exist()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2A"),
                new VCardSimpleValue("two", "2B"),
            };

            list.GetFirstEntity("three");
        }
Exemplo n.º 2
0
        public void GetEntities_No_Matches()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2"),
            };

            var result = list.GetEntities("three");

            CollectionAssert.IsEmpty(result);
        }
Exemplo n.º 3
0
        public void GetFirstEntity_Success_When_One_Exists()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2"),
            };

            VCardSimpleValue value = list.GetFirstEntity("two");

            Assert.That(value.Name, Is.EqualTo("two"));
        }
Exemplo n.º 4
0
        public void GetEntities_Two_Of_Three_Matches()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2A"),
                new VCardSimpleValue("two", "2B"),
            };

            VCardSimpleValue[] result = list.GetEntities("two").ToArray();

            Assert.That(result.GetLength(0), Is.EqualTo(2));
            CollectionAssert.AllItemsAreUnique(result);
        }
Exemplo n.º 5
0
        public void TryGetFirstEntity_By_Different_Case()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2A"),
                new VCardSimpleValue("TWO", "2B"),
            };

            VCardSimpleValue value;
            bool result = list.TryGetFirstEntity("TWO", out value);

            Assert.That(result, Is.True);
            Assert.That(value.Name, Is.EqualTo("two"));
            Assert.That(value.EscapedValue, Is.EqualTo("2A"));
        }
Exemplo n.º 6
0
        public void TryGetFirstEntity_When_One_Exists()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2"),
            };

            VCardSimpleValue value;
            bool result = list.TryGetFirstEntity("two", out value);

            Assert.That(result, Is.True);
            Assert.That(value.Name, Is.EqualTo("two"));
        }
Exemplo n.º 7
0
        public void TryGetFirstEntity_Return_First_When_Two_Exist()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2A"),
                new VCardSimpleValue("two", "2B"),
            };

            VCardSimpleValue value;
            bool result = list.TryGetFirstEntity("two", out value);

            Assert.That(result, Is.True);
            Assert.That(value.Name, Is.EqualTo("two"));
            Assert.That(value.EscapedValue, Is.EqualTo("2A"));
        }
Exemplo n.º 8
0
        public void TryGetFirstEntity_Return_False_When_None_Exist()
        {
            VCardEntityList<VCardSimpleValue> list = new VCardEntityList<VCardSimpleValue>()
            {
                new VCardSimpleValue("one", "1"),
                new VCardSimpleValue("two", "2"),
            };

            VCardSimpleValue value;
            bool result = list.TryGetFirstEntity("three", out value);

            Assert.That(result, Is.False);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Parses a value list into a list of values
        /// </summary>
        /// <returns></returns>
        public VCardEntityList<VCardSimpleValue> GetListValues()
        {
            VCardEntityList<VCardSimpleValue> output = new VCardEntityList<VCardSimpleValue>();

            string inputText = EscapedValue;

            if (String.IsNullOrEmpty(inputText))
            {
                output.Add(new VCardSimpleValue("1", String.Empty));
                return output;
            }

            int count = 0;
            int lastIndex = -1;
            int index = 0;
            while (index < inputText.Length)
            {
                char c = inputText[index];

                if (c == ',')
                {
                    count++;
                    string content = inputText.Substring(lastIndex + 1, index - lastIndex - 1);
                    output.Add(new VCardSimpleValue(count.ToString(), content));

                    lastIndex = index;
                }
                if (c == '\\') // escape character
                {
                    // skip another character, and make sure there is more at the end
                    index++;
                    if (index >= inputText.Length)
                        throw new InvalidVCardFormatException("Line ends with escape character", inputText);
                }

                index++;
            }

            // add everything after the last separator
            count++;
            output.Add(new VCardSimpleValue(count.ToString(), inputText.Substring(lastIndex + 1)));

            // return the list
            return output;
        }
Exemplo n.º 10
0
 public VCardGroup()
 {
     Children = new VCardEntityList<VCardEntity>();
 }
Exemplo n.º 11
0
 public VCardValue()
 {
     Parameters = new VCardEntityList<VCardSimpleValue>();
 }