public async Task Can_get_post() { // Arrange var post = new Post { Id = Guid.NewGuid().ToString(), Title = "Climate", Description = "Global warming", PostedOn = DateTime.UtcNow, TrainedMeanRateValue = 2, Features = new double[] { 1, 0.5, 0.3, 5 }, Article = new Article { Content = "Global warming is the long-term heating of Earth’s climate system", Image = "data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P" } }; using var context = new PersonalBlogContext(_contextOptions); context.Add(post); context.SaveChanges(); var repository = new Repository <Post>(context); // Act var receivedPost = await repository.Get(p => p.Id == post.Id).FirstOrDefaultAsync(); // Assert receivedPost.Should().BeEquivalentTo(post, options => options .Excluding(p => p.Id) .Excluding(p => p.Article.Id)); }
public bool ValidationUser(string login, string password) { bool isValid = false; using (PersonalBlogContext db = new PersonalBlogContext()) { User user = (from u in db.Users where u.Login == login && u.Password == password select u).FirstOrDefault(); if (user != null) { isValid = true; } } return(isValid); }
public void FindRecord_WhenExists_ShouldWorks() { var options = new DbContextOptionsBuilder <PersonalBlogContext>() .UseInMemoryDatabase(databaseName: "Find") .Options; using (var context = new PersonalBlogContext(options)) { context.ArticleCategories.Add(new ArticleCategory { Id = 1, Name = "Name", Description = "Description" }); context.SaveChanges(); } using (var context = new PersonalBlogContext(options)) { var result = context.ArticleCategories.Find(1); Assert.IsNotNull(result); } }
public UnitOfWork(PersonalBlogContext context) { _context = context; }
public AuthorsController(PersonalBlogContext context) { _context = context; }
public PostController(PersonalBlogContext context) { _context = context; }
public ArticlesController(PersonalBlogContext context) { _context = context; }
public CategoryController(PersonalBlogContext context) { _context = context; }