0

For my test pupose method i want to put any integer value besides 0. Nevertheless it always put 0 even if i say like this:

It.Is<int>(x => x > 0)

Can anyone tell me what is wrong?

Full code:

[Test]
public void Test()
{
      DerService.Add(new Demo(It.Is<int>(x => x > 0), new Gert()), false);
      SigQuery.Verify(uow => uow.IsExistRef(It.IsAny<int>()), Times.Once);
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Arie
  • 3,041
  • 7
  • 32
  • 63
  • 2
    You are using `It` wrong. Bad pun aside, that class is meant to only be used in Setup/Verify Expressions to match arguments – Nkosi Mar 15 '20 at 17:45
  • 2
    This appears to be an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Can you reformat the question so we get a clearer picture of the current problem and what you are **actually** trying to do? See the [ask] page for help clarifying this question. – Nkosi Mar 15 '20 at 17:47
  • Reference https://github.com/Moq/moq4/wiki/Quickstart#matching-arguments – Nkosi Mar 15 '20 at 17:48
  • Reference https://github.com/Moq/moq4/wiki/Quickstart#verification – Nkosi Mar 15 '20 at 17:49
  • @Nkosi how then should i do this ii am not intresting put here specific value (besides 0)? – Arie Mar 15 '20 at 18:07
  • Just use any value you want that would allow the test to be exercised to completion. You can then use the `It.Is` in the `Verify` to confirm the expected behavior – Nkosi Mar 15 '20 at 18:10
  • @Nkosi but i am talking about that line: DerService.Add(new Demo(It.Is(x => x > 0), new Gert()), false); – Arie Mar 15 '20 at 18:14
  • `DerService.Add(new Demo(anyValueGreaterThanZero, new Gert()), false);` then verify `SigQuery.Verify(uow => uow.IsExistRef(It.Is(x => x > 0)), Times.Once);` – Nkosi Mar 15 '20 at 18:15
  • Edit the question with more details so we understand the context about which you are referring – Nkosi Mar 15 '20 at 18:16
  • @Nkosi i know i can put there any value like 100 3 or whatever but i wouldlike to put there random digit because in future an other developer could think that maybe this digit could have potential meaning. – Arie Mar 15 '20 at 18:30
  • then use `Random` class to generate a "random" number greater than 0 to give to your subject under test. – Nkosi Mar 15 '20 at 18:31

0 Answers0