c# - Access a WPF classes in UnitTest Project -
i have wierd problem while trying unit test viewmodel classes in unittest project in visual studio 2012. created unittest project , added solutinon. added wpf project reference unittest project test viewmodel classes , methods. problem can't access viewmodel classes. lets type :
[testclass] public class unittest1 { [testmethod] public void testmethod1() { mywpfproject.viewmodels.mainviewmodel } }
it's acting there no mainviewmodel class in viewmodels folder. problem here ?
this due declaring mainviewmodel
class internal access modifier:
namespace viewmodels { internal class mainviewmodel { ... } }
the internal access modifier limits visibility defining assembly (in case, wpf project). if want access class external assembly (in case, testing project) can either change access modifier public or use internalsvisibleto
attribute.
the internalsvisibleto
assembly attribute allows specify "friend" assemblies can view assemblies internal members. define attribute, open assemblyinfo.cs (should in project default - extend "properties" node in solution explorer) , paste following besides of other assembly attributes:
[assembly: internalsvisibleto("code")]
change string "code" name of unit testing project.
see, in case referencing codewpf code. see highlighted class assemblyinfo, should pretty self explanatory define attribute.
Comments
Post a Comment