// private methods private void SetupMockWithNewFakeDb(List <BaseEntity> fakeBaseEntities) { // setup DbSet _mockDbSet = MockDbSet.Create <BaseEntity>(fakeBaseEntities); // setup DbContext _mockDbContext = new Mock <FinancialDbContext>(); _mockDbContext.Setup(c => c.Set <BaseEntity>()) .Returns(_mockDbSet); // set up repository _repository = new Repository <BaseEntity>(_mockDbContext.Object); }
public Tests() { // first we need a database context. var dbTestContext = new Mock <DbTestContext>(); Vehicle fakeVehicle = new Vehicle(1, "Test Name", "Test Description"); Mock <DbSet <Vehicle> > mockVehicles = MockDbSet.Create(fakeVehicle); dbTestContext.Setup(x => x.Vehicles).Returns(mockVehicles.Object); _vehicleApiController = new VehicleApiController(dbTestContext.Object); }
private void Setup_Repository_MockDbContext(List <Asset> fakeAssets) { // setup DbSet _mockAssetDbSet = MockDbSet.Create <Asset>(fakeAssets); // setup DbContext _callCount = 0; _mockDbContext = new Mock <FinancialDbContext>(); _mockDbContext.Setup(c => c.Set <Asset>()) .Returns(_mockAssetDbSet) .Callback(() => _callCount++); // set up repository _repository = new AssetRepository(_mockDbContext.Object); }