有人可以帮助启发我吗?
我去签入了对 TFS 的一些更改,但我的签入被拒绝了。它促使我查看我编辑过的 switch 语句。
我发现 Visual Studio 2017 声称不存在编译时问题,并允许我成功构建和部署应用程序。最重要的是,甚至该方法的单元测试似乎也按预期通过了。
public enum PaymentStatus
{
Issued,
Cleared,
Voided,
Paid,
Requested,
Stopped,
Unknown
}
public class PaymentViewModel
{
public PaymentStatus Status { get; set; }
...
public String StatusString
{
get
{
switch (this.Status)
{
case PaymentStatus.Cleared:
return "Cleared";
case PaymentStatus.Issued:
return "Issued";
case PaymentStatus.Voided:
return "Voided";
case PaymentStatus.Paid:
return "Paid";
case PaymentStatus.Requested:
return "Requested";
case PaymentStatus.Stopped:
return "Stopped";
case PaymentStatus Unknown:
return "Unknown";
default:
throw new InavlidEnumerationException(this.Status);
}
}
}
}
因此,请注意“case PaymentStatus Unknown”这一行缺少“。” 点运算符。如前所述,项目构建并运行;但未能与封闭式构建服务器签入。
另外,请注意以下测试正在通过:
[TestMethod]
public void StatusStringTest_Unknown()
{
var model = new PaymentViewModel()
{
Status = PaymentStatus.Unknown
}
Assert.AreEqual("Unknown", model.StatusString);
}
最后,请注意,我只使用静态字符串而不是使用资源文件运行测试,它通过了。为了简单起见,我在上面的代码中省略了资源文件的内容。
对此的任何想法都非常感谢!提前致谢!