mardi 25 août 2015

callback is not called using moq + autofaq

I have a unit test done using moq to mock the objects, and the test is working fine, and now I want to use autofac +moq, but I'm having a few problems. this is the test:

        using (var mock = AutoMock.GetLoose())
        {

            var issues = new List<Issue>();
            issues.Add(new Issue { Organization = "org", Repository = "repo", Number = 1 });
            issues.Add(new Issue { Organization = "org", Repository = "repo", Number = 2 });
            var numKeys = 0;

            mock.MockRepository.Create<IStorageService>()
                .Setup(myMock => myMock.GetBatchIssues(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IList<string>>()))
                .Callback((string org, string repo, IList<string> keys) => numKeys = keys.Count)
                .Returns(issues);

            var sut = mock.Create<IssueReceiveService>();

            var check = await sut.CheckInStorage("org", "repo", issues);
            Assert.AreEqual(issues.Count, numKeys);
        }

the call to sut.CheckInStorage return null, and the variable numKeys is not updated to the correct value. This test works fine using just moxk, so I suppose I'm missing something how to configure a mock with autoMock. Where can I find more informations?

Aucun commentaire:

Enregistrer un commentaire