Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
0
        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));
            }
        }
        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));
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 9
0
 public CommentRepository(BloggerContext context)
 {
     _context = context;
 }
Ejemplo n.º 10
0
 public BloggerController(BloggerContext context, ILogger <WeatherForecastController> logger)
 {
     _logger  = logger;
     _context = context;
     var test = _context.Categories.ToList();
 }
Ejemplo n.º 11
0
 public BlogsController(BloggerContext context)
 {
     _context    = context;
     blogService = ServiceLocator.Instance.GetService <IBlogService>(context);
 }
Ejemplo n.º 12
0
 public UsersRepository(BloggerContext context)
 {
     _context = context;
 }
Ejemplo n.º 13
0
 public UserService(BloggerContext dbcontext)
 {
     this.dbcontext = dbcontext;
     user           = new User();
 }
Ejemplo n.º 14
0
 public CommentService(BloggerContext dbcontext)
 {
     this.dbcontext = dbcontext;
     comment        = new Comment();
 }
Ejemplo n.º 15
0
 public BlogsController(BloggerContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
Ejemplo n.º 16
0
 public TagService(BloggerContext dbcontext)
 {
     this.dbcontext = dbcontext;
     tag            = new Tag();
 }
Ejemplo n.º 17
0
 public PictureRepository(BloggerContext context)
 {
     _context = context;
 }
Ejemplo n.º 18
0
 public BlogService(BloggerContext dbcontext)
 {
     this.dbcontext = dbcontext;
     blog           = new Blog();
 }
Ejemplo n.º 19
0
 public DapperPostRepository(BloggerContext context)
 {
     _context         = context;
     ConnectionString = _context.Database.GetConnectionString();
 }
Ejemplo n.º 20
0
 public PostsController(BloggerContext context)
 {
     postservice = ServiceLocator.Instance.GetService <IPostService>(context);
 }
 public Repository()
 {
     context = new BloggerContext();
 }
 public UserRepository(BloggerContext bloggerContext)
 {
     _bloggerContext = bloggerContext;
 }
Ejemplo n.º 23
0
 public AttachmentRepository(BloggerContext context)
 {
     _context = context;
 }
Ejemplo n.º 24
0
 public UsersController(BloggerContext context)
 {
     userservice = ServiceLocator.Instance.GetService <IUserService>(context);
 }
Ejemplo n.º 25
0
 public BlogRepository(BloggerContext context)
 {
     _context = context;
 }
Ejemplo n.º 26
0
 public PostService(BloggerContext dbcontext)
 {
     this.dbcontext = dbcontext;
     post           = new Post();
 }