Skip to content

Commit

Permalink
add - Added re-parsing tests
Browse files Browse the repository at this point in the history
---

We've added tests that save the resultant cards to string and re-parse them.

---

Type: add
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Mar 31, 2024
1 parent dcaa8d5 commit 4fe93f3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions VisualCard.Tests/ContactParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ internal void ParseDifferentContactsInternal(string cardText)
Should.NotThrow(() => cards = CardTools.GetCardsFromString(cardText));
}

[TestMethod]
[DynamicData(nameof(ContactData.singleVcardContactShorts), typeof(ContactData))]
public void ReparseDifferentContactsShorts(string cardText) =>
ReparseDifferentContactsInternal(cardText);

[TestMethod]
[DynamicData(nameof(ContactData.singleVcardContacts), typeof(ContactData))]
public void ReparseDifferentContacts(string cardText) =>
ReparseDifferentContactsInternal(cardText);

[TestMethod]
[DynamicData(nameof(ContactData.multipleVcardContacts), typeof(ContactData))]
public void ReparseDifferentContactsMultiple(string cardText) =>
ReparseDifferentContactsInternal(cardText);

[TestMethod]
[DynamicData(nameof(ContactData.remainingContacts), typeof(ContactData))]
public void ReparseDifferentContactsRemaining(string cardText) =>
ReparseDifferentContactsInternal(cardText);

internal void ReparseDifferentContactsInternal(string cardText)
{
Card[] cards = [];
Card[] secondCards;
Should.NotThrow(() => cards = CardTools.GetCardsFromString(cardText));

// Save all the cards to strings and re-parse
foreach (Card card in cards)
{
string saved = Should.NotThrow(card.SaveToString);
Should.NotThrow(() => secondCards = CardTools.GetCardsFromString(saved));
}
}

[TestMethod]
[DynamicData(nameof(ContactData.singleVcardContactShorts), typeof(ContactData))]
public void ParseDifferentContactsAndTestEqualityShorts(string cardText) =>
Expand Down Expand Up @@ -247,5 +281,25 @@ public void BogusButSeemsValidShouldNotThrowWhenParsing(string cardText)
foreach (Card card in cards)
card.ShouldNotBeNull();
}

[TestMethod]
[DynamicData(nameof(ContactDataBogus.seemsValidContacts), typeof(ContactDataBogus))]
public void BogusButSeemsValidShouldNotThrowWhenParsingAndReparsing(string cardText)
{
Card[] cards = [];
Card[] secondCards = [];
Should.NotThrow(() => cards = CardTools.GetCardsFromString(cardText));
foreach (Card card in cards)
card.ShouldNotBeNull();

// Save all the cards to strings and re-parse
foreach (Card card in cards)
{
string saved = Should.NotThrow(card.SaveToString);
Should.NotThrow(() => secondCards = CardTools.GetCardsFromString(saved));
}
foreach (Card card in secondCards)
card.ShouldNotBeNull();
}
}
}

0 comments on commit 4fe93f3

Please sign in to comment.