public async void Create() { Mock <ILogger <PostsRepository> > loggerMoc = PostsRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = PostsRepositoryMoc.GetContext(); var repository = new PostsRepository(loggerMoc.Object, context); var entity = new Posts(); await repository.Create(entity); var record = await context.Set <Posts>().FirstOrDefaultAsync(); record.Should().NotBeNull(); }
public async void Get() { Mock <ILogger <PostsRepository> > loggerMoc = PostsRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = PostsRepositoryMoc.GetContext(); var repository = new PostsRepository(loggerMoc.Object, context); Posts entity = new Posts(); context.Set <Posts>().Add(entity); await context.SaveChangesAsync(); var record = await repository.Get(entity.Id); record.Should().NotBeNull(); }
public async void Delete() { Mock <ILogger <PostsRepository> > loggerMoc = PostsRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = PostsRepositoryMoc.GetContext(); var repository = new PostsRepository(loggerMoc.Object, context); Posts entity = new Posts(); context.Set <Posts>().Add(entity); await context.SaveChangesAsync(); await repository.Delete(entity.Id); Posts modifiedRecord = await context.Set <Posts>().FirstOrDefaultAsync(); modifiedRecord.Should().BeNull(); }
public async void Update_Entity_Is_Not_Tracked() { Mock <ILogger <PostsRepository> > loggerMoc = PostsRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = PostsRepositoryMoc.GetContext(); var repository = new PostsRepository(loggerMoc.Object, context); Posts entity = new Posts(); context.Set <Posts>().Add(entity); await context.SaveChangesAsync(); await repository.Update(new Posts()); var modifiedRecord = context.Set <Posts>().FirstOrDefaultAsync(); modifiedRecord.Should().NotBeNull(); }