c# - Mocking UserManager -
i used post (http://www.asp.net/web-api/overview/testing-and-debugging/mocking-entity-framework-when-unit-testing-aspnet-web-api-2) mocking db , able test. of classes has applicationuser foreign key. having trouble test them. can do?
this interface:
using system; using system.data.entity; namespace prac.models { public interface ipraccontext : idisposable { idbset<graduando> graduando { get; set; } idbset<funcionario> funcionario { get; set; } idbset<applicationuser> users { get; set; } int savechanges(); void markasmodified<t>(t i) t : class; } }
identitymodels.cs (with applicatiouser class)
using system.data.entity; using system.security.claims; using system.threading.tasks; using microsoft.aspnet.identity; using microsoft.aspnet.identity.entityframework; namespace prac.models { // can add profile data user adding more properties applicationuser class, please visit http://go.microsoft.com/fwlink/?linkid=317594 learn more. public class applicationuser : identityuser { public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager, string authenticationtype) { // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype var useridentity = await manager.createidentityasync(this, authenticationtype); // add custom user claims here return useridentity; } } public class applicationdbcontext : identitydbcontext<applicationuser>, ipraccontext { public applicationdbcontext() : base("defaultconnection", throwifv1schema: false) { //solve problem of json serialization //db getting data foreign key base.configuration.proxycreationenabled = false; } public static applicationdbcontext create() { return new applicationdbcontext(); } public void markasmodified<t>(t i) t : class { entry(i).state = entitystate.modified; } public idbset<beneficio> beneficio { get; set; } public idbset<familiar> familiar { get; set; } public idbset<cadastrograduando> cadastrograduando { get; set; } public idbset<graduando> graduando { get; set; } public idbset<doencacronica> doencacronica { get; set; } public idbset<edital> edital { get; set; } public idbset<editalgraduando> editalgraduandoe { get; set; } public idbset<funcionario> funcionario { get; set; } public idbset<noticia> noticia { get; set; } } }
Comments
Post a Comment