wpf - Moq with c# System.Windows.MessageBoxButton.YesNoCancel -
i'm writing unit tests around wpf module of program. i've come point showmessage
returns yes
or no
value within statement.
dservice.showmessage(view, args);
the args takes lambda (shortened)
new messageargs(arg1, arg2, arg3, (la) => { if (la.result == messresult.yes) { // } }
i'm trying mock result given lambda having difficulty , have been unable find similar problem.
i've tried setting default result within lambda in unit test:
new messageargs(arg1, arg2, arg3, (la) => { if (la.result == messresult.yes) { la.result = messresult.yes; } }
which proved unsuccessful along trying set arg result below statement as:
args.result = messresult.yes;
i have tried use setup as:
dservicemock.setup(x => x.showmessage)
but there no return property showmessage
void function.
none have shown change in action unit test. has else had similar "problem" , found solution or know of documentation around this? i'll update if find in mean time.
thank you.
if dservice
not instance of sealed
class, create subclass overrides showmessage
method in way need test purposes.
edit:
the problem arises dservice.showmessage(view, args)
call encapsulating 2 (or more) actions:
- calls view.showmessage
- calls lambda enclosed in args result of view.showmessage
now have create dservice.showmessage(view, args)
such that:
- not show view
- assumes outcome of action instead
- calls lambda desired outcome
Comments
Post a Comment