0

I realise this question had been asked before. However I tried the previous solutions and none of them worked for me. I am trying to isolate the real DB in order to run the mocking dependency test by using a fake DB context. I create an ApplicationBbContext for this reason, but having difficulties to figure out why do get an error with Application DbContext does not implement interface member error

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.Identity.EntityFramework;
using MVC_ATM.Models;
using System.Data.Entity;
using MVC_ATM.ViewModels;
using MVC_ATM.Migrations;

namespace MVC_ATM.ViewModels
{
    public interface IApplicationDbContext
    {
        IDbSet<CheckingAccount> checkingAccounts { get; set; }
        IDbSet<Transaction> Transactions { get; set; }
        int SaveChanges();
    }


    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IApplicationDbContext //This is the first error
    {

        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>());
            base.OnModelCreating(modelBuilder);

        }
        public IDbSet<CheckingAccount> checkAccounuts { get; set; }

        public IDbSet<Transaction> Transactions { get; set; }
    }
}
//This IApplication db is made for mock testing 
public class FakeApplicationDBContext : IApplicationDbContext //This is the second error 
{
    public IDbSet<CheckingAccount> checkAccounuts { get; set; }

    public IDbSet<Transaction> Transactions { get; set; }
    public int SaveChanges()
    {
        return 0;
    }
} 

Transactions controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC_ATM.ViewModels;
using MVC_ATM.Models;

namespace MVC_ATM.Controllers
{
    [Authorize]
    public class AllTransactionsController : Controller
    {
        private IApplicationDbContext DB;

        public AllTransactionsController()
        {
            DB = new ApplicationDbContext();
        }

        public AllTransactionsController(IApplicationDbContext DBContext)
        {
            DB = DBContext;
        }


    }
}

1 Answer 1

2

That's because the inherited interface declares

IDbSet<CheckingAccount> checkingAccounts { get; set; }

and in the implementations they have

 public IDbSet<CheckingAccount> checkAccounuts { get; set; }

checkAccounuts instead of checkingAccounts which does not match the contract defined by the interface. Thus the compile time error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.