Skip to main content

Posts

Showing posts from May, 2012

RuntimeBinderException cannot resolver property in Unit Test in case of dynamic return.. Solved

This is an issue that i have face while doing tests for a dynamic return method, while it worked on the run, it did not work on the testing environment so it had to be a mocking return issue, i was returning a collection of anonymous types and it was, how ever  i have found the solution, to illustrate the issue here is what happened in samples. A sample test would normally fail cause of exception runtime binder exception   so the test simply check for a return of a function that returns a dynamic object and checks for its return, once run a run time binder exception   will be thrown in the Assert statement as the props cannot be resolved. The issue here is with anonymous types if you use ExpandoObject instead it should work fine with no problem. So replace the anonymous type with an expand object, check below

Dynamic Anonymous my experience through out assemblies doing unit tests and more RuntimeBinderException Headache

While at work on a project I was facing a matter that caused me a lot of headache, which is passing dynamics throughout assemblies, after doing a lot of research and investigation like Should I use dynamics if no then why and how can I compensate it’s flexibility and stuff like that  just to get a profound to wither to use it or not , And I found that it is preferred not to use dynamic whenever possible and that because The overhead it causes on the runtime, in other words the time to identify properties types is not done on compile, it is done on runtime thus the overhead. Nevertheless the fact that literally we do not know if it is working alright, unless we are at runtime if it is not working for instance we got a property name wrong  then boom exception for sure BUT a very convenient guy would say where are your tests that should cover that from happening “just for your info not all of us right tests and not all of us right proper tests”, I would say that is one othe