repository-pattern

Mockery not calling method from repository (interface)

筅森魡賤 提交于 2019-12-11 05:51:15
问题 I am trying to test my controller with this test (I'm using Laravel, if that matters): <?php use Zizaco\FactoryMuff\Facade\FactoryMuff; class ProjectControllerTest extends TestCase { public function setUp() { parent::setUp(); $this->mock = $this->mock('Dumminvoicing\Storage\Project\ProjectRepositoryInterface'); } public function mock($class) { $mock = Mockery::mock($class); $this->app->instance($class, $mock); return $mock; } protected function tearDown() { Mockery::close(); } public function

UnitOfWork, Repository Database Connection Issue

拥有回忆 提交于 2019-12-11 05:35:18
问题 I'm using Unity for Dependency Injection. I implemented generic repository IRepository<T> and IUnitOfWork as per direction mentioned here Now when I access Repository and UnitOfWork in Service layer using constructor injection, it adds the data in database but never closes connection with database. UnitOfWork implements IDisposable but that's never called since I'm not able to implement Using pattern knowing the fact that Repository and UnitOfWork is being shared by other functions also.

NSubstitute not matching Linq Expression

拥有回忆 提交于 2019-12-11 03:57:46
问题 I am implementing a repository pattern Query class and testing using NSubstitute. Repository interface: public interface IMyRepository { IQueryable<T> Query<T>(Expression<Func<T, bool>> filter) where T : class; } DateTimeProvider interface: public interface IMyDateTimeProvider { DateTime GetDateNow(); } Application interface: public interface IMyApplication { List<Thing> GetThingsByQuery(int status); } Application implementation: public class MyApplication : IMyApplication { private readonly

How to fix: The return type of an async method must be void, Task or Task<T> [AppName]

拜拜、爱过 提交于 2019-12-11 03:36:57
问题 I'm using VS Code and following an ASP.NET Core/ EF Core tutorial and admit I'm not quite clear on how the async, await and Task do (well, I know the first two, but not the third.) I am implementing a repository for the first time, and a UnitofWork Class and Interface to go with it. Here is the UnitofWork Class: using System.Threading.Tasks; namespace vega.Persistence { public class UnitOfWork : IUnitOfWork { private readonly VegaDbContext context; public UnitOfWork(VegaDbContext context) {

Laravel4: Will not using the repository pattern hurt my project in the long run?

落爺英雄遲暮 提交于 2019-12-11 03:24:26
问题 I'm reading Taylor Otwell's book in which he suggests using the repository pattern. I get the theory behind it. That it's easy to switch implementations and decouples your code. I get the code too. And it is very nice to be able to switch by App::bind() with some other implementation. But I've been thinking for the last two hours how I should approach things for a new CRM I'm building. Almost no code yet but it might end up big. I would prefer to simply use eloquent models and collection

How to universally create Repositories that inherit from a generic type?

帅比萌擦擦* 提交于 2019-12-11 02:49:13
问题 I'm currently trying to implement the Repository Pattern on top of my DbContext. The thing is, I eventually end up with a situation where I have to inject several Repositories into a UnitOfWork constructor, like this: public class UnitOfWork { private DbContext _context; ICustomerRepository Customers { get; private set; } IEmployeeRepository Employees { get; private set; } public UnitOfWork(DbContext context, ICustomerRepository cust, IEmployeeRepository emp) { _context = context; Customers =

Syntax folder repository for the function edit()

a 夏天 提交于 2019-12-11 02:35:44
问题 I have 2 foreign keys which are fk_author and fk_bookcase , I am trying to create my function edit() via a folder Repositorie but I am stuck on the syntax again. Here is my code via the file BookRepository public function edit($id) { $books = Book::find($id); $authors = Author::all(); $bookcases = Bookcase::all(); return Book::find($id); } Then, in my Controller I have this... public function edit($id) { $books = $this->books->edit($id); return view('admin.books.edit', compact('books',

How do i make .Include to work on an IEnumerable

喜你入骨 提交于 2019-12-11 02:20:56
问题 I'm having trouble running a query on my repository. I have to fetch a product by the id and display it in an edit view alongside the image of the product. There is a method in my ProductRepository that implements Get() i.e fetch all the product and GetByID as the name implies. I implemented a generic repository pattern with a unit of work class like below public class GenericRepository<TEntity> where TEntity : class { internal SchoolContext context; internal DbSet<TEntity> dbSet; public

When implementing the repository pattern should lookup value / tables get their own Repository?

蓝咒 提交于 2019-12-11 02:20:23
问题 I am creating RESTful services for several database entities based on a modified version of the BISDM. Some of these entities have associated lookup tables, such as depicted below: I have decided to use the repository pattern to provide a clean separation between data persistance / retrieval; however, I am not sure how lookups ( as opposed to entities ) should be represented in the repository. Should lookups get their own repository interface, "share" one with the associated entity, or should

EF Core change tracking - issue with original values and altered values

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:06:59
问题 I have Net core API configured with .net core 2.0 and EF core 2.0. it contains repository pattern architecture. Now, I am trying to implement Audit log for each save change using EF change tracker. My Issue : Whenever I tries to add a log for edit/modification endpoint, the original value and current value remain same and it's newly updated value. so in that way I am not able to track the modification or a change. Here is my ApplicationContext file where I have overridden save call. public