Autofixture: Using AutoMoqCustomization & SetupAllProperties to have all properties of a mocked interface fillled?

StackOverflow https://stackoverflow.com/questions/18597439

  •  27-06-2022
  •  | 
  •  

문제

I am trying to get Autofixture to setup and create me an anonymous of an interface. I am using the AutoMoqCustomization, but I keep getting an error.

My code is

var configuration = fixture.CreateAnonymous<Mock<IConfiguration>>();

Mock.Get(configuration).SetupAllProperties();

It actually errors on the SetupAllProperties with

System.ArgumentException : Object instance was not created by Moq. Parameter name: mocked

Anyone know what I am doing wrong?

도움이 되었습니까?

해결책

You're trying to get a Mock<IConfiguration> from a Mock<IConfiguration> instance, which is hardly necessary. Just use

var configuration = fixture.CreateAnonymous<Mock<IConfiguration>>();

configuration.SetupAllProperties();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top