Skip to content

Create dedicated setup type for SetupAllProperties#1234

Merged
stakx merged 6 commits intodevlooped:mainfrom
stakx:stubbedpropertiessetup
Feb 15, 2022
Merged

Create dedicated setup type for SetupAllProperties#1234
stakx merged 6 commits intodevlooped:mainfrom
stakx:stubbedpropertiessetup

Conversation

@stakx
Copy link
Contributor

@stakx stakx commented Feb 13, 2022

This is a continuation of #1204, where a dedicated setup type was created for single stubbed properties' accessors (i.e. SetupProperty). Thanks to #1203, the same can also be done for SetupAllProperties.

A few additional notes:

  • This gets rid of the RemoveAllPropertyAccessorSetups method in SetupCollection, restoring it to an add-only collection, which in turn means its use of lock-ing could be optimized in a similar fashion as was done for InvocationCollection.

  • Gets rid of the AutoSetupPropertiesDefaultValueProvider hack and simplifies the interception pipeline.

  • Moq should become a little more efficient in principle, since there will be fewer setups created overall.

Fixes #1066, likely fixes #1231.

@stakx stakx force-pushed the stubbedpropertiessetup branch 3 times, most recently from c3f00b4 to 24d318d Compare February 13, 2022 21:41
@stakx stakx force-pushed the stubbedpropertiessetup branch from 24d318d to ae1a892 Compare February 13, 2022 22:09
@stakx stakx added this to the 4.17.1 milestone Feb 13, 2022
@stakx stakx force-pushed the stubbedpropertiessetup branch 5 times, most recently from ab1dc7c to ac9de6e Compare February 13, 2022 23:56
@stakx stakx force-pushed the stubbedpropertiessetup branch from ac9de6e to 6b44eb7 Compare February 14, 2022 00:02
@stakx stakx force-pushed the stubbedpropertiessetup branch from 6b44eb7 to e30183b Compare February 14, 2022 00:05
@stakx stakx merged commit 4d052c1 into devlooped:main Feb 15, 2022
@stakx stakx deleted the stubbedpropertiessetup branch February 15, 2022 12:11
@stakx stakx restored the stubbedpropertiessetup branch March 6, 2022 09:58
@stakx stakx deleted the stubbedpropertiessetup branch March 6, 2022 09:59
@mo-russo
Copy link

mo-russo commented Aug 3, 2022

Hello @stakx, since we got version 4.18.1, our mocks' subclasses that call SetupAllProperties are crashing.

public class MyInterfaceMock : Mock<IMyInterface>
{
  public MyInterfaceMock ()
  {
    SetupAllProperties(); // Crashes here
  }
}

This isn't allowed anymore?

@stakx
Copy link
Contributor Author

stakx commented Aug 3, 2022

@mo-russo, this is a regression. Could you please report the above again in a new issue, so that we can properly track it? Thanks.

@devlooped devlooped locked and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SetupAllProperties causes mocks to become race-prone Property setups are ignored on mocks instantiated using Mock.Of

2 participants