示例#1
0
        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();
        }
示例#2
0
        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();
        }
示例#3
0
        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();
        }