Weaving not applied during Live Unit Testing
See original GitHub issueBit new to Fody so pls go easy. There are a few moving parts to this that I’ve tried as a result of reading various posts/articles.
I’m unsure if this is an issue with PropertyChanged.Fody
or if Fody
in its entirety is not being executed under LUT scenarios. Happy to post to another location if that’s appropriate but thought I’d start at the highest level of specificity.
Environment
I have a basic soln structure as follows:
- VS 2022 (17.0.0 Preview 5)
- C# Library project (sdk=
Microsoft.Net.Sdk
) targetingnet6.0
- MSTest v2 library targeting same
- Library project has a base (abstract) class with
INotifyPropertyChanged
andprotected virtual void OnPropertyChanged( string propertyName )
- Test library has a class that inherits from the base and implements a basic string property (auto-implemented)
- All projects have
FodyWeavers.xml
in the root with the<PropertyChanged />
element added - There are no other weavers present
- All projects have references as follows:
<PackageReference Include="Fody" Version="6.5.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody" Version="4.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Problem
Nothing I can do will make OnPropertyChanged()
fire in the context of Live Unit Testing.
I can get it to work when running through Test Explorer and via dotnet test
so this isn’t an issue with the normal operation of the library per se.
I have been unable to identify a discrepancy between the build process used in LUT/roslyn and the normal dotnet build
/msbuild
so I can’t imagine why it wouldn’t work, hoping someone with experience in this area can direct me to whatever changes might be necessary to get LUT going.
Observation: Fody
& PropertyChanged.Fody
packages need to be applied to both the library project AND the MSTest project in order for it to work through Test Explorer - I would not have expected this to be the case, but may be a clue. Presumably these references are only required on the project that actually uses the weaving?
Anyone have any suggestions or thoughts?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Most of my tests were against classes that were not defined in the Test library. It happens that the first test was setup that way as I was testing the base class’ ability to record changed properties so I can have a
IsChanged( a => a.Prop )
method that would inherit into all the models I need.I had subsequently created a number of tests against the real models, all of which are in the Library project as you’d expect, and these had tests that passed when debugged or run in Test Explorer, but failed under LUT. With my changes to the target all the tests now pass under all conditions.
@richardhauer
I think this could be the root cause, the class you are testing is in the test library! At least that is the reason why you need
PropertyChanged.Fody
in the test project!