简体   繁体   中英

Moq to FakeItEasy migration - How to migrate Verify()?

I'm in the process of migrating Moq tests to FakeItEasy and I have runned into a case which I don't know how to migrate.

The case is:

    [TestMethod]
    public void Should_EditItem()
    {
        _itemMock.Verify(
            item => item.Edit((ItemTypeId)2, (ProcessId)1, "TITLE", "TEXT", new DateTime(2012, 11, 28), (UserId)321,
                              (GroupId)321, (ItemPriorityId)1, ItemStatus.Open, (ItemTypeStatusId)3, (PlantId)0,
                              (UserId)123, 1, null, 15, "REF", It.IsAny<RegionId>(), It.IsAny<CountryId>(), It.IsAny<string>()));
    }

How do I migrate this call to FakeItEasy? What does it even do?

Moq is saying, "verify the Edit method was called with these arguments".

2 mins on the FakeItEasy docs ( https://fakeiteasy.readthedocs.io/en/stable/argument-constraints/ ) and you should be able to say something like:

A.CallTo(() => item.Edit(((ItemTypeId)2, (ProcessId)1, "TITLE", "TEXT", new DateTime(2012, 11, 28), (UserId)321,
                          (GroupId)321, (ItemPriorityId)1, ItemStatus.Open, (ItemTypeStatusId)3, (PlantId)0,
                          A<UserId>.That.Matches(x=>x==(UserId)123), 1, null, 15, "REF", A<RegionId>, A<CountryId>, A<string>)).MustHaveHappened();

Or something similar.

//Moq
_mock.Verify(x=>x.method());
It.IsAny<string>()
//FIE
A.CallTo(x=>x.method()).MustHaveHappened();
A<string>.Ignored // or A<string>._

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM