Reputation: 12646
I have the following code with simple string interpolation:
public string CreateStyledGuestList(VolunteerDTO volunteerData)
{
List<GuestContact> guestListWithLeaderIncluded = GetNewGuestListWithLeaderIncluded(volunteerData);
string styledGuestList =
"<div style=\"margin-left: 40px\">"
+ "<br>" + guestListWithLeaderIncluded.Select(g => g.FirstName + " " + g.LastName)
+ "</div>";
return styledGuestList;
}
When I test this method, I get the following (note that the code is shown, instead of the resulting string):
↓ (pos 35)
Expected: ···gin-left: 40px">
Leeroy Jenkins Actual: ···gin-left: 40px">
System.Linq.Enumerable+SelectListIterator··· ↑ (pos 35)
The test itself:
[Fact]
public void ShouldCreateGuestListWithOnlyLeader()
{
VolunteerDTO volunteerData = new VolunteerDTO();
volunteerData.FirstName = "Leeroy";
volunteerData.LastName = "Jenkins";
volunteerData.Guests = new List<GuestContact>();
string actual = _fixture.CreateStyledGuestList(volunteerData);
string expected = "<div style=\"margin-left: 40px\"><br>Leeroy Jenkins</div>";
Assert.Equal(expected, actual);
}
Why is the string not being interpolated / how do I fix this?
Upvotes: 0
Views: 81
Reputation: 3498
guestListWithLeaderIncluded.Select(...)
will return an IEnumerable<string>
and not a string
You need to join the strings to one string like:
... + string.Join("<br>", guestListWithLeaderIncluded.Select(...)) + ...
Upvotes: 2