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"); }
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); }
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")); }
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); }
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")); }
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")); }
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")); }
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); }
/// <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; }
public VCardGroup() { Children = new VCardEntityList<VCardEntity>(); }
public VCardValue() { Parameters = new VCardEntityList<VCardSimpleValue>(); }