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); } }
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); } }
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(); } }
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"); } }
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); } }
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"); } }
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); } }
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; }
public TagsRepository(BlogsDbContext context) { _context = context; }
public FavoritePostsRepository(BlogsDbContext context) { _context = context; }
public BlogsControllerAPI(BlogsDbContext dbContext) { _context = dbContext; }
public BlogService(BlogsDbContext blogsDbContext) { this.blogsDbContext = blogsDbContext; }
public CommentsPostsRepository(BlogsDbContext context) { _context = context; }
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(); }
protected GenericRepository(BlogsDbContext dbContext) { DbContext = dbContext; }
public CategoryService(BlogsDbContext blogsDbContext) { this.blogsDbContext = blogsDbContext; }
public UsersRepository(BlogsDbContext context) { _context = context; }