N
N
Nikita072021-07-15 14:09:33
C++ / C#
Nikita07, 2021-07-15 14:09:33

Why is the value null?

Hello everyone, the question is the following, there is the following unit test fragment

// Arrange
            var mock1 = new Mock<IRtbService>();
            mock1
                .Setup(a => a.GetAuctionResult(rtb_partners, auctionModel))
                .ReturnsAsync("VAST");


In fact, it should return a VAST string, but when debugging it returns null, what can this "feature" be connected with?

PS
Here is the GetAuctionResult() method:
public Task GetAuctionResult(IEnumerable rtb_partners, AuctionModel auctionModel);

Here is a screenshot of getting null
60f017342caf8847848527.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-07-15
@Nikita07

Most likely because rtb_partners and auctionModel do not match what is passed to it.
As I understand it, the comparison is by reference and the mock returns null.
If you don’t really care what comes there, then you can unconditionally configure:

var mock1 = new Mock<IRtbService>();
mock1
    .Setup(a => a.GetAuctionResult(It.IsAny<IEnumerable>(), It.IsAny<AuctionModel>()))
    .ReturnsAsync("VAST");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question