How can I test the protected property was correctly initialized in constructor?
Code looks as follows:
public class ClassUnderTest
{
protected List<Update> Updates { get; }
public ClassUnderTest(string email)
{
Updates = StaticDatabaseContext.Updates.Where(update => update.email.Equals(email)).ToList();
}
}
Then the test code looks as follows:
[Test]
public void UpdatesAreInitializedCorrectlyInConstructor()
{
var updatesTable = Isolate.Fake.Instance<Table<Updates>>();
Isolate.WhenCalled(() => StaticDatabaseContext.Updates).WillReturn(updatesTable);
var updates = new List<Updates> { update1, update2 };
Isolate.WhenCalled(() => updatesTable).WillReturnCollectionValuesOf(updates.AsQueryable());
var target = new ClassUnderTest("user@email.com");
// throws an error
Isolate.Verify.NonPublic.Property.WasCalledSet(target, "Updates").WithArgument(new List<Updates> { update1 });
}
My Isolate.Verify throws an error:
TypeMock.TypeMockException :
*** Cannot verify methods that were not faked. Either fake the method's class, or use WhenCalled
Problem here is, that Isolate.Verify.NonPublic can work only with fakes
-
so either target have to be faked
-
or Updates set property have to be faked (via Isolate.NonPublic.Property.WhenSetCalled)
Regarding 1.
While I am creating new instance of ClassUnderTest in test code, Isolate.Fake.NextInstance does not work.
Regarding 2.
While the Updates property is not static Isolate.NonPublic.Property.WhenSetCalled(typeof(ClassUnderTest), "Updates").IgnoreCall() cannot be used.
Also Isolate.NonPublic.Property.WhenSetCalled(target, "Updates").IgnoreCall() cannot be used, becase target has already been created and Updates has already been set in constructor.
Is there a way how can I verify my property has been initialized correctly in the constructor?