i want test concrete implementation of abstract videoviewmodel on android. use vs 2013 nunitlite.
for create videoviewmodel instance need activity context
here constructor vor videoviewmodel:
public videoviewmodelandroid(context context, ifilesystem filesystem) : base(filesystem) { bool contextisactivity = context activity; exceptionutil.throwif.isfalse(() => contextisactivity); this.context = context; this.videoview = (context activity).findviewbyid<videoview>(resource.id.videoview1); // returns null videoview this.videoview.touch += videoview_touch; }
here create videoview
context = mainactivity.con; var view = new videoviewmodelandroid(context, filesystem); the context comes here:
[activity(label = "ids.droid.tests", mainlauncher = true, icon = "@drawable/icon")] public class mainactivity : testsuiteactivity { public static context con; protected override void oncreate(bundle bundle) { // tests can inside main assembly addtest(assembly.getexecutingassembly()); // or in reference assemblies // addtest (typeof (your.library.testclass).assembly); // once called base.oncreate(), cannot add more assemblies. base.oncreate(bundle); //setcontentview(resource.layout.mainlayout); con = this; } } i linked layout application , id represented in resource.designer.cs.
but retuns no view after call
this.videoview = (context activity).findviewbyid<videoview>(resource.id.videoview1); any idea resolve problem???
do need context or maybe mock it? if can mock use package(available through nuget):
github: https://github.com/moq/moq4
nuget: https://www.nuget.org/packages/moq/
but others stated in comment, using context in viewmodel isn't practice. reason viewmodel has platform independent. if wanted reuse viewmodel ios , winphone have problem context not existing on these platforms.
Comments
Post a Comment