Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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# 如何使用任意整数进行测试_C#_Asp.net Mvc_Unit Testing - Fatal编程技术网

C# 如何使用任意整数进行测试

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

我是否可以将“1”替换为通配符(任何大于0的数字),以便对传入的任何内容都返回相同的内容,等等

[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