Example #1
0
        public void UserRepository_Get()
        {
            using (var context = new BlogsDbContext(_options))
            {
                var userRepository = new UserRepository(context);
                var providers      = userRepository.Get().Result;

                Assert.True(providers.ToList().Count == 100);
            }
        }
Example #2
0
 public void UserRepository_GetbyId()
 {
     using (var context = new BlogsDbContext(_options))
     {
         var id             = 1;
         var userRepository = new UserRepository(context);
         var providers      = userRepository.GetById(1).Result;
         Assert.IsInstanceOf(typeof(User), providers);
     }
 }
Example #3
0
        public void SetUpTests()
        {
            var rnd = new Random();

            _options = new DbContextOptionsBuilder <BlogsDbContext>()
                       .UseInMemoryDatabase(databaseName: "openreferralsTests")
                       .Options;
            _blogs = Builder <Blog> .CreateListOfSize(100)
                     .All()
                     .With(p => p.Title   = Faker.Lorem.Sentence())
                     .With(p => p.Content = Faker.Lorem.Paragraph())
                     .With(p => p.Active  = true)
                     .With(p => p.UserId  = 1)
                     .Build();

            var user = Builder <User> .CreateNew().With(p => p.Active = true).With(p => p.FirsName = Faker.Name.First())
                       .With(p => p.Id       = 1)
                       .With(p => p.LastName = Faker.Name.Last())
                       .With(p => p.Username = Faker.Internet.UserName())
                       .With(p => p.Password = "******")
                       .Build()
            ;

            _blogs = Builder <Blog> .CreateListOfSize(100)
                     .All()
                     .With(p => p.Title   = Faker.Lorem.Sentence())
                     .With(p => p.Content = Faker.Lorem.Paragraph())
                     .With(p => p.Active  = true)
                     .With(p => p.UserId  = 1)
                     .With(p => p.User    = user)
                     .Build();

            // Insert seed data into the database using one instance of the context
            using (var context = new BlogsDbContext(_options))
            {
                context.Database.EnsureDeleted();

                foreach (var blog in _blogs)
                {
                    try
                    {
                        context.Blogs.Add(blog);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
                context.SaveChanges();
            }
        }
Example #4
0
 public void BlogRepository_Update()
 {
     using (var context = new BlogsDbContext(_options))
     {
         var id             = 1;
         var blogRepository = new BlogRepository(context);
         var blog           = blogRepository.GetById(1).Result;
         blog.Title  = "Modified";
         blog.Active = false;
         var result  = blogRepository.Update(blog).Result;
         var blogMod = blogRepository.GetById(1).Result;
         Assert.True(blogMod.Active == false && blogMod.Title == "Modified");
     }
 }
Example #5
0
        public async System.Threading.Tasks.Task UserRepository_CreateAsync()
        {
            using (var context = new BlogsDbContext(_options))
            {
                var id             = 1;
                var userRepository = new UserRepository(context);
                var newUser        = CreateUser();
                newUser.Id = -1;
                await userRepository.Create(newUser);

                var newBlog = userRepository.GetById(-1).Result;
                Assert.IsNotNull(newBlog);
            }
        }
Example #6
0
 public void UserRepository_Update()
 {
     using (var context = new BlogsDbContext(_options))
     {
         var id             = 1;
         var userRepository = new UserRepository(context);
         var user           = userRepository.GetById(1).Result;
         user.FirsName = "Modified";
         user.Active   = false;
         var result  = userRepository.Update(user).Result;
         var blogMod = userRepository.GetById(1).Result;
         Assert.True(blogMod.Active == false && blogMod.FirsName == "Modified");
     }
 }
Example #7
0
        public async System.Threading.Tasks.Task BlogRepository_CreateAsync()
        {
            using (var context = new BlogsDbContext(_options))
            {
                var id             = 1;
                var blogRepository = new BlogRepository(context);
                var blog           = CreateBlog();
                blog.Title = "new Blog";
                blog.Id    = -1;
                await blogRepository.Create(blog);

                var newBlog = blogRepository.GetById(-1).Result;
                Assert.IsNotNull(newBlog);
            }
        }
Example #8
0
        public void SetUpTests()
        {
            var rnd = new Random();

            _options = new DbContextOptionsBuilder <BlogsDbContext>()
                       .UseInMemoryDatabase(databaseName: "openreferralsTests")
                       .Options;
            _users = Builder <User> .CreateListOfSize(100)
                     .All()
                     .With(p => p.LastName = Faker.Name.Last())
                     .With(p => p.Username = Faker.Internet.UserName())
                     .With(p => p.Password = "******")
                     .Build();

            //foreach (var user in _users)
            //{
            //    user.Blogs = CreateBlogList(user);
            //}

            // Insert seed data into the database using one instance of the context
            using (var context = new BlogsDbContext(_options))
            {
                context.Database.EnsureDeleted();

                foreach (var user in _users)
                {
                    try
                    {
                        context.Users.Add(user);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }

                context.SaveChanges();
            }
        }
 public PostsRepository(BlogsDbContext context)
 {
     _context = context;
 }
Example #10
0
 public TagsRepository(BlogsDbContext context)
 {
     _context = context;
 }
Example #11
0
 public FavoritePostsRepository(BlogsDbContext context)
 {
     _context = context;
 }
 public BlogsControllerAPI(BlogsDbContext dbContext)
 {
     _context = dbContext;
 }
Example #13
0
 public BlogService(BlogsDbContext blogsDbContext)
 {
     this.blogsDbContext = blogsDbContext;
 }
 public CommentsPostsRepository(BlogsDbContext context)
 {
     _context = context;
 }
Example #15
0
 public BlogRepository(BlogsDbContext dbContext) : base(dbContext)
 {
 }
 public BlogsController(BlogsDbContext context)
 {
     this.context = context;
     //TODO: Need better solution, e.g. creating DBs upfront with scripts
     context.Database.EnsureCreated();
 }
Example #17
0
 protected GenericRepository(BlogsDbContext dbContext)
 {
     DbContext = dbContext;
 }
Example #18
0
 public CategoryService(BlogsDbContext blogsDbContext)
 {
     this.blogsDbContext = blogsDbContext;
 }
Example #19
0
 public UsersRepository(BlogsDbContext context)
 {
     _context = context;
 }