Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在比较预期/实际值之前,XUnit未在字符串内执行代码_C#_Xunit - Fatal编程技术网

C# 在比较预期/实际值之前,XUnit未在字符串内执行代码

C# 在比较预期/实际值之前,XUnit未在字符串内执行代码,c#,xunit,C#,Xunit,我有以下带有简单字符串插值的代码: public string CreateStyledGuestList(VolunteerDTO volunteerData) { List<GuestContact> guestListWithLeaderIncluded = GetNewGuestListWithLeaderIncluded(volunteerData); string styledGuestList = "<div style=\"margin-le

我有以下带有简单字符串插值的代码:

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;
}
预计:··杜松子酒左:40px“>
李罗伊·詹金斯 实际值:···gin左:40px“>
System.Linq.Enumerable+SelectListIterator··· ↑ (位置35)

测试本身:

[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);
}
[事实]
public void应使用onlyleader()创建GuestList
{
志愿者数据到志愿者数据=新志愿者数据到();
志愿者数据。FirstName=“Leeroy”;
志愿者数据。LastName=“Jenkins”;
志愿者数据。来宾=新列表();
字符串实际值=_fixture.CreateStyledGuestList(数据);
应为字符串=“
Leeroy Jenkins”; 断言。相等(预期、实际); }

为什么没有插入字符串/如何修复此问题?

包含Leader的来宾列表。选择(…)
将返回一个
IEnumerable
而不是
字符串

您需要将字符串连接到一个字符串,如:

... + string.Join("<br>", guestListWithLeaderIncluded.Select(...)) + ...
…+string.Join(“
”,包含Leader的来宾列表。选择(…)+。。。
包含引线的来宾列表。选择(…)
将返回一个
IEnumerable
,而不是
字符串

您需要将字符串连接到一个字符串,如:

... + string.Join("<br>", guestListWithLeaderIncluded.Select(...)) + ...
…+string.Join(“
”,包含Leader的来宾列表。选择(…)+。。。
需要查看GetNewGuestListWithLeaderIncluded正在做什么。看起来它对你的DTO有影响,包括Linq,但这并不是你所期望的。(顺便说一句,35号位置的东西是一个例外吗?真的不清楚它是关于什么的…)需要看看GetNewGuestListWithLeaderIncluded在做什么。看起来它对你的DTO有影响,包括Linq,但这并不是你所期望的。(顺便说一句,35号位置的东西是个例外吗?真的不清楚它是关于什么的…)