Trying to write tests for some legacy code and I have a question about mocking fields or other references inside a mock. In the code below, "Assert.IsNotNull(member.Rsa)" will fail because the mocked constructor of member hasn't created anything. Currently I've solved the problem by creating a separate mock and assigning to it, but is this really the best way to do this?
var testChallengeData = new ChallengeData();testChallengeData.responseList = new Response[] {new Response(), new Response(), new Response()};var member = Mock.Create<Member>(Constructor.Mocked);var rsa = Mock.Create<Vendors.RSA>(Constructor.Mocked);Mock.SetupStatic(typeof (Settings), StaticConstructor.Mocked);Mock.Arrange(() => Settings.getBool(Arg.AnyString)).IgnoreInstance().Returns(false);Mock.Arrange(() => Settings.getInt(Arg.AnyString)).IgnoreInstance().Returns(3);Mock.Arrange(() => rsa.CurrUserStatus).IgnoreInstance().Returns(Vendors.AdaptiveAuthRef.UserStatus.UNVERIFIED).OccursOnce();Mock.Arrange(() => rsa.HasChallengeQuestions).IgnoreInstance().Returns(true).OccursNever();Mock.Arrange(() => member.challengeQuestions).IgnoreInstance().Returns(testChallengeData);Mock.Arrange(() => member.hasChallengeQuestions).CallOriginal();member.Rsa = rsa;Assert.IsNotNull(member.Rsa);Assert.IsTrue(member.hasChallengeQuestions);rsa.Assert();Mock.Assert(() => Settings.getBool(Arg.AnyString), Occurs.Once());