C# 如何使用任意整数进行测试
我是否可以将“1”替换为通配符(任何大于0的数字),以便对传入的任何内容都返回相同的内容,等等C# 如何使用任意整数进行测试,c#,asp.net-mvc,unit-testing,C#,Asp.net Mvc,Unit Testing,我是否可以将“1”替换为通配符(任何大于0的数字),以便对传入的任何内容都返回相同的内容,等等 [TestMethod] public void GameManagersEventsIndexReturnedWhenUserHasNoLocations() { // Arrange List<CustomerLocation> locations = new List<CustomerLocation>(); locations.Add(new C
[TestMethod]
public void GameManagersEventsIndexReturnedWhenUserHasNoLocations()
{
// Arrange
List<CustomerLocation> locations = new List<CustomerLocation>();
locations.Add(new CustomerLocation() { Active = true, Name = "Ted" });
customerLocationDataProvider.Setup(x => x.GetAllForUserId(1)).Returns(locations);
customerLocationDataProvider.Setup(x => x.GetAllForUserId(1).Count).Returns(0);
[TestMethod]
public void Game Manager在用户无位置时返回Ventsindex()
{
//安排
列表位置=新列表();
Add(new CustomerLocation(){Active=true,Name=“Ted”});
customerLocationDataProvider.Setup(x=>x.GetAllForUserId(1))。返回(位置);
customerLocationDataProvider.Setup(x=>x.GetAllForUserId(1.Count)。返回(0);
如果您使用MOQ,您可以
x => x.GetAllForUserId(It.Is<int>(i => i > 0)) // condition that int value is > 0 or you can have any other conditions
x=>x.GetAllForUserId(It.Is(i=>i>0))//int值大于0的条件,或者可以有任何其他条件
或
x=>x.GetAllForUserId(It.IsAny())//如果您不关心该值
我已经编辑了你的标题。请参见“”,其中的共识是“不,他们不应该”。
x => x.GetAllForUserId(It.IsAny<int>()) //if you don't care about the value