repository-pattern

How to write unit test code for my ADO.Net based repository from VS2013

北慕城南 提交于 2019-12-06 14:38:14
问题 i am quite new in unit test area. so please guide me how to write unit test for ADO.Net based repository and action method inside my controller? i will be using VS own unit test framework. so please see the code and tell me what are the classes and functions need to go through unit test? it will be really helpful if some one tell me which area i need to unit test and which area not required? if possible please write few unit test code which show me how to write unit test for action ,student

Design for multi-tenant app using SOA, UoW, Repository, DataContext & multiple databases

删除回忆录丶 提交于 2019-12-06 11:21:54
问题 Let me start by apologizing for the length of this post but I wanted to provide as much detail as possible to increase the chance of an answer. Thanks in advance. I’m adding new features to an existing application that integrates data from several databases. In short, it allows clients and/or their accountants to access and update financial information about their locations. The application has 3 tiers with a web client (I’m looking to replace this will a Silverlight client very soon), a

Can I access a repository from presentation layer?

风流意气都作罢 提交于 2019-12-06 10:36:13
I am starting with DDD. I am a bit confused with the interaction between the several layers involved in a DDD application. Can I call my repositories from my presentation layer? If not do I have to replicate the CRUD functionality provided by the repositories in my service layer (which ofcourse will in turn use the repository for these functions)? What would be the best way to do this? What exactly do you mean by presentation layer? If you mean the Controller/Presenter, then it's perfectly fine. The rule of thumb that I've used is if the controller action is 4 lines of code or more I should

Implementing a Repository<T> that returns a domain model mapped from an EF Entity

元气小坏坏 提交于 2019-12-06 09:52:42
I have the following application structure, based on the onion architecture by Jeffery Palermo (ref link) . So my Core is not dependant on anything, my Infrastructure is dependent on my Core My Core has the Repository Contract and my Infrastructure implements it. The Implementation gets Injected by my IoC Container Core -Interfaces --IRepository<TDomainModel> -Domain --Person Infrastructure -Data --Repository<TDomainModel> (Implementation) -Entities --Ef.edmx So this wouldn't be a problem if I wrote out a concrete repository implementation (e.g a PersonRepository) because I know what type to

Entity Framework RC1 DbContext query issue

我怕爱的太早我们不能终老 提交于 2019-12-06 09:39:01
I'm trying to implement the repository pattern using entity framework code first rc 1. The problem I am running into is with creating the DbContext. I have an ioc container resolving the IRepository and it has a contextprovider which just news up a new DbContext with a connection string in a windsor.config file. With linq2sql this part was no problem but EF seems to be choking. I'll describe the problem below with an example. I've pulled out the code to simplify things a bit so that is why you don't see any repository pattern stuff here. just sorta what is happening without all the extra code

Should we use Data Repository pattern in MVC application using Entity Framework Code First approach?

偶尔善良 提交于 2019-12-06 09:35:57
问题 I have developed many application now with Entity Framework Code First approach. In all of the I use Data Repository pattern. This Data Repository pattern queries over single entity at a Time. for e.g, I have 2 models Employee and Department So to fetch all employees and department I would create 2 data repository instances. e.g var empRepository = new DataRepository<Employee>(); var allEmployees = empRepository.GetAll(); var depRepository = new DataRepository<Department>(); var alldepartment

translate this into a generic repository pattern

放肆的年华 提交于 2019-12-06 09:21:58
I have started translating a project into a generic repository and unit of work pattern. So far I have been able to reverse engineer all direct context references in the controllers to a generic repository; however, I am having trouble with the following two lines of codes: `context.Entry(ticket).Collection(i => i.TicketItems).Load(); ticket.TicketItems.Clear();` This is what my controller was doing before to remove any reference between a Ticket and a TicketItem . There is a many-to-many relation between Ticket and TicketItem . So those two lines of code is what I was using before to remove

Repository Pattern Retrieve Desired Columns Only

你离开我真会死。 提交于 2019-12-06 09:07:55
问题 I am using the example here to create a repository pattern with Unit of Work. Within the code, there is a generic Get method: public class GenericRepository<TEntity> where TEntity : class { internal AdminDbContext context; internal DbSet<TEntity> dbSet; public GenericRepository(AdminDbContext context) { this.context = context; this.dbSet = context.Set<TEntity>(); } public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<TEntity, TEntity> selector = null,

Entity Framework Service Layer Update POCO

自古美人都是妖i 提交于 2019-12-06 07:49:57
问题 I am using the Service Layer --> Repository --> Entity Framework (Code-First) w/POCO objects approach, and I am having a hard time with updating entities. I am using AutoMapper to map my Domain Objects to my View Models and that works good for getting the data, no how do I get that changes back into the database? Using pure POCO objects, I would assume that there is no sort of change tracking, so I see my only option is to handle it myself. Do you just make sure that your View Models have the

Handling Multiple Mocks and Asserts in Unit Tests

谁说我不能喝 提交于 2019-12-06 07:33:28
I currently have a repository that is using Entity Framework for my CRUD operations. This is injected into my service that needs to use this repo. Using AutoMapper, I project the entity Model onto a Poco model and the poco gets returned by the service. If my objects have multiple properties, what is a correct way to set-up and then assert my properties? If my service has multiple repo dependencies what is the correct way to setup all my mocks? * - A class [setup] where all the mocks and objects are configured for these test fixtures?***** I want to avoid having 10 tests and each test has 50