public void Setup() { var Users = new List <Users> { new Users { Username = "******", Firstname = "Prithiwman", Lastname = "Mazumdar" }, new Users { Username = "******", Firstname = "Soumyadip", Lastname = "Saha" }, new Users { Username = "******", Firstname = "Subham", Lastname = "Mitra" } }; var Usersdata = Users.AsQueryable(); var mockSet = new Mock <DbSet <Users> >(); mockSet.As <IQueryable <Users> >().Setup(m => m.Provider).Returns(Usersdata.Provider); mockSet.As <IQueryable <Users> >().Setup(m => m.Expression).Returns(Usersdata.Expression); mockSet.As <IQueryable <Users> >().Setup(m => m.ElementType).Returns(Usersdata.ElementType); mockSet.As <IQueryable <Users> >().Setup(m => m.GetEnumerator()).Returns(Usersdata.GetEnumerator()); var mockContext = new Mock <BloggerContext>(); mockContext.Setup(c => c.Users).Returns(mockSet.Object); db = mockContext.Object; }
public void Setup() { var Blog = new List <Blog> { new Blog { Id = 1, Title = "My Coding Blog", Description = "An awesome coding blog" }, new Blog { Id = 2, Title = "My Painting Blog", Description = "An awesome painting blog" }, new Blog { Id = 3, Title = "My Travelling Blog", Description = "An awesome travel blog" } }; var Blogdata = Blog.AsQueryable(); var mockSet = new Mock <DbSet <Blog> >(); mockSet.As <IQueryable <Blog> >().Setup(m => m.Provider).Returns(Blogdata.Provider); mockSet.As <IQueryable <Blog> >().Setup(m => m.Expression).Returns(Blogdata.Expression); mockSet.As <IQueryable <Blog> >().Setup(m => m.ElementType).Returns(Blogdata.ElementType); mockSet.As <IQueryable <Blog> >().Setup(m => m.GetEnumerator()).Returns(Blogdata.GetEnumerator()); var mockContext = new Mock <BloggerContext>(); mockContext.Setup(c => c.Blogs).Returns(mockSet.Object); db = mockContext.Object; }
public void Setup() { var Comment = new List <Comment> { new Comment { Id = 1, Content = "An awesome coding Comment" }, new Comment { Id = 2, Content = "An awesome painting Comment" }, new Comment { Id = 3, Content = "An awesome travel Comment" } }; var Commentdata = Comment.AsQueryable(); var mockSet = new Mock <DbSet <Comment> >(); mockSet.As <IQueryable <Comment> >().Setup(m => m.Provider).Returns(Commentdata.Provider); mockSet.As <IQueryable <Comment> >().Setup(m => m.Expression).Returns(Commentdata.Expression); mockSet.As <IQueryable <Comment> >().Setup(m => m.ElementType).Returns(Commentdata.ElementType); mockSet.As <IQueryable <Comment> >().Setup(m => m.GetEnumerator()).Returns(Commentdata.GetEnumerator()); var mockContext = new Mock <BloggerContext>(); mockContext.Setup(c => c.Comments).Returns(mockSet.Object); db = mockContext.Object; }
public T GetService <T>(BloggerContext dbcontext) { if (this.instantiatedServices.ContainsKey(typeof(T))) { return((T)this.instantiatedServices[typeof(T)]); } else { // lazy initialization try { // use reflection to invoke the service Type[] types = new Type[1]; types[0] = typeof(BloggerContext); // add the parameter type into an array ConstructorInfo constructor = servicesType[typeof(T)].GetConstructor(types); Debug.Assert(constructor != null, "Cannot find a suitable constructor for " + typeof(T)); T service = (T)constructor.Invoke(new object[] { dbcontext }); // add the service to the ones that we have already instantiated instantiatedServices.Add(typeof(T), service); return(service); } catch (KeyNotFoundException ex) { throw new ApplicationException("The requested service is not registered" + ex); } } }
public void CreateDatabase() { //This will tell EF to drop and recreate the database whenever the models change... Database.SetInitializer(new BloggerContextInitializer()); using (var db = new BloggerContext()) { //Get the seed values from the database and print them to the screen Blog seedBlog = db.Blogs.FirstOrDefault(); Assert.AreNotEqual(seedBlog, null); Assert.AreEqual(seedBlog.Name, "My Blog"); //Assert.AreEqual(seedBlog.Url, "www.myblog.com"); //Assert that the post titles are not empty... just for the heck of it... seedBlog.Posts.ForEach(post => Assert.AreNotEqual(post.Title, string.Empty)); } }
static void Main(string[] args) { //This will tell EF to drop and recreate the database whenever the models change... Database.SetInitializer(new BloggerContextInitializer()); using (var db = new BloggerContext()) { //Get the seed values from the database and print them to the screen Blog seedBlog = db.Blogs.FirstOrDefault(); Console.WriteLine("{0} has {1} posts...", seedBlog.Name, seedBlog.Posts.Count); //Uncomment this line if the Url property has been added to the Blog model. //Console.WriteLine("{0} - '{1}' has {2} posts...", seedBlog.Name, seedBlog.Url, seedBlog.Posts.Count); seedBlog.Posts.ForEach(post => Console.WriteLine(" - {0}", post.Title)); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }
public void Save_And_Fetch_Test() { var options = GetOptions(); using (var context = new BloggerContext(options)) { output.WriteLine(context.Users.GetType().ToString()); var repo = new UserRepository(context); var user = new User() { FirstName = "Rafiul", LastName = "Islam", Email = "*****@*****.**", Password = "******", BlogName = "rafiulblog" }; User createdUser = repo.Add(user).Result; Assert.Equal(user, createdUser); User fetchedUser = repo.Get(1).Result; Assert.Equal(user, fetchedUser); } }
public CommentRepository(BloggerContext context) { _context = context; }
public BloggerController(BloggerContext context, ILogger <WeatherForecastController> logger) { _logger = logger; _context = context; var test = _context.Categories.ToList(); }
public BlogsController(BloggerContext context) { _context = context; blogService = ServiceLocator.Instance.GetService <IBlogService>(context); }
public UsersRepository(BloggerContext context) { _context = context; }
public UserService(BloggerContext dbcontext) { this.dbcontext = dbcontext; user = new User(); }
public CommentService(BloggerContext dbcontext) { this.dbcontext = dbcontext; comment = new Comment(); }
public BlogsController(BloggerContext context, UserManager <ApplicationUser> userManager) { _context = context; _userManager = userManager; }
public TagService(BloggerContext dbcontext) { this.dbcontext = dbcontext; tag = new Tag(); }
public PictureRepository(BloggerContext context) { _context = context; }
public BlogService(BloggerContext dbcontext) { this.dbcontext = dbcontext; blog = new Blog(); }
public DapperPostRepository(BloggerContext context) { _context = context; ConnectionString = _context.Database.GetConnectionString(); }
public PostsController(BloggerContext context) { postservice = ServiceLocator.Instance.GetService <IPostService>(context); }
public Repository() { context = new BloggerContext(); }
public UserRepository(BloggerContext bloggerContext) { _bloggerContext = bloggerContext; }
public AttachmentRepository(BloggerContext context) { _context = context; }
public UsersController(BloggerContext context) { userservice = ServiceLocator.Instance.GetService <IUserService>(context); }
public BlogRepository(BloggerContext context) { _context = context; }
public PostService(BloggerContext dbcontext) { this.dbcontext = dbcontext; post = new Post(); }