internal BloggingDataService(IBloggingContext context) { _dbContext = context; Posts = new PostRepository(_dbContext.Posts); Blogs = new BlogRepository(_dbContext.Blogs); }
public async Task <Blog> Get(int id) { //validation goes here Blog blog = null; // Instantiage context only if needed and dispose immediately using (IBloggingContext context = _bloggingContextFactory.CreateContext()) { blog = await context.Blogs.FindAsync(id); } //Do further processing without need of context. return(blog); }
public BlogControllerTest() { //creating seed objects var post = new Post() { PostId = 1, Title = "Some title", Content = "post contemt" }; var blog = new Blog() { BlogId = 1, Url = "google", Posts = new List <Post>() { post } }; //associating blog with post post.Blog = blog; post.BlogId = blog.BlogId; var blogsMock = new List <Blog>() { blog }.AsDbSetMock(); var postsMock = new List <Post>() { post }.AsDbSetMock(); var contextMock = new Mock <IBloggingContext>(); contextMock.Setup(m => m.Blogs).Returns(blogsMock.Object); contextMock.Setup(m => m.Posts).Returns(postsMock.Object); _context = contextMock.Object; _controller = new BlogController(_context); }
public BlogService(IBloggingContext context) { _context = context; }
public HomeController(IBloggingContext context) { _context = context; }
public BlogController(IBloggingContext bloggingContext) { this._context = bloggingContext; }