chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have this method:

public class Mod
{
public void AddProperty(Property property)
{
if (property == null)
throw new ArgumentNullException("property");

this.Properties.Add(property);
}
}

Notice the properties call, which calls the getter. The following test fails to verify this, even though it gets called.

[TestFixture]
public class ModTest : Mod
{
[Test]
public void AddingPropertyToSubmoduleAddsElementsCorrectly()
{
//Arrange
var moduleFake = Isolate.Fake.Instance<ModTest>();
Isolate.SwapNextInstance<ModTest>();
Isolate.WhenCalled(() => moduleFake.AddProperty(new Property("Test", moduleFake))).CallOriginal();

var propertyFake = Isolate.Fake.Instance<Property>(Members.CallOriginal, ConstructorWillBe.Called);
Isolate.SwapNextInstance<Property>();

//Act
ModTesttest = new ModTest();
var property = new Property("Test", test);
test.AddProperty(property);

//Assert
Isolate.Verify.NonPublic.Property.WasCalledGet(moduleFake, "Properties");
}
}

Notice the test inherits from the class. The inheritance seems to be throwing it off.
asked by bmains (13.2k points)

4 Answers

0 votes
Hi,

I would like to look at the entire code. Since you have multiple questions around the same code, let's take it offline. I'll write you a separate email.

Thanks,
answered by gilz (14.5k points)
0 votes
Hello,

I found a clarification... there is an issue when that Properties collection property is private in the base class... When making it internal/protected, it does seem to work as is.

Brian
answered by bmains (13.2k points)
0 votes
Hello,

Also, the SwapNewInstance<> trick doesn't work when it's private also... it may when internal/protected; I have not tested that.

Being an issue when private does make sense.

Brian
answered by bmains (13.2k points)
0 votes
Brian,

Thanks for the clarifications; this ties in to a known issue with faking private values on abstract base classes. This is high on our task board and I will update you when we have a fix for this.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
...