Just an example: I have a class that reacts to set properties. More specifically, there are three properties from which an assembly is loaded once they are all set. Afterwards an event is triggered.
My unit test for this behavior look something like this:
bool assemblyLoaded = false;
loader.AssemblyLoaded += () => assemblyLoaded = true;
loader.Type = "someType";
Assert.IsFalse(assemblyLoaded); // not loaded, only one property was set
This would lead to three unit tests, one test for each property. So I’d like to abstract the test by using a helping method (see below) to avoid code replication:
private void Testfoobar(Action setProperty)
{
bool assemblyLoaded = false;
loader.AssemblyLoaded += (sender, args) => assemblyLoaded = true;
setProperty();
}
Unfortunately, I cannot make a property assignment an Action.
So, I wonder, can you somehow “transform” the assignment to Action? Or is there maybe a different way to abstract the code?
What do you mean when you say you cant make a property assignment an Action?
That you cant implement the assignment in action?
Why cant you use
If you want to do it with delegate, you can use the Funct<> delegates: