예제 #1
0
        public async virtual Task <PostType> Create(PostType item)
        {
            this.Context.Set <PostType>().Add(item);
            await this.Context.SaveChangesAsync();

            this.Context.Entry(item).State = EntityState.Detached;
            return(item);
        }
예제 #2
0
        public async void Create()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var repository = new PostTypeRepository(loggerMoc.Object, context);

            var entity = new PostType();
            await repository.Create(entity);

            var record = await context.Set <PostType>().FirstOrDefaultAsync();

            record.Should().NotBeNull();
        }
예제 #3
0
        public async void Get()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var repository = new PostTypeRepository(loggerMoc.Object, context);

            PostType entity = new PostType();

            context.Set <PostType>().Add(entity);
            await context.SaveChangesAsync();

            var record = await repository.Get(entity.Id);

            record.Should().NotBeNull();
        }
예제 #4
0
        public async virtual Task Delete(
            int id)
        {
            PostType record = await this.GetById(id);

            if (record == null)
            {
                return;
            }
            else
            {
                this.Context.Set <PostType>().Remove(record);
                await this.Context.SaveChangesAsync();
            }
        }
예제 #5
0
        public async virtual Task Update(PostType item)
        {
            var entity = this.Context.Set <PostType>().Local.FirstOrDefault(x => x.Id == item.Id);

            if (entity == null)
            {
                this.Context.Set <PostType>().Attach(item);
            }
            else
            {
                this.Context.Entry(entity).CurrentValues.SetValues(item);
            }

            await this.Context.SaveChangesAsync();
        }
예제 #6
0
        public async void Create()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var repository = new PostTypeRepository(loggerMoc.Object, context);

            var entity = new PostType();

            entity.SetProperties(default(int), "B");
            await repository.Create(entity);

            var records = await context.Set <PostType>().ToListAsync();

            records.Count.Should().Be(2);
        }
예제 #7
0
        public async void Delete()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var      repository          = new PostTypeRepository(loggerMoc.Object, context);
            PostType entity = new PostType();

            context.Set <PostType>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Delete(entity.Id);

            PostType modifiedRecord = await context.Set <PostType>().FirstOrDefaultAsync();

            modifiedRecord.Should().BeNull();
        }
예제 #8
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var      repository          = new PostTypeRepository(loggerMoc.Object, context);
            PostType entity = new PostType();

            context.Set <PostType>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Update(new PostType());

            var modifiedRecord = context.Set <PostType>().FirstOrDefaultAsync();

            modifiedRecord.Should().NotBeNull();
        }
예제 #9
0
        public async void DeleteFound()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var      repository          = new PostTypeRepository(loggerMoc.Object, context);
            PostType entity = new PostType();

            entity.SetProperties(default(int), "B");
            context.Set <PostType>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Delete(entity.Id);

            var records = await context.Set <PostType>().ToListAsync();

            records.Count.Should().Be(1);
        }
예제 #10
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostTypeRepository> > loggerMoc = PostTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostTypeRepositoryMoc.GetContext();
            var      repository          = new PostTypeRepository(loggerMoc.Object, context);
            PostType entity = new PostType();

            entity.SetProperties(default(int), "B");
            context.Set <PostType>().Add(entity);
            await context.SaveChangesAsync();

            context.Entry(entity).State = EntityState.Detached;

            await repository.Update(entity);

            var records = await context.Set <PostType>().ToListAsync();

            records.Count.Should().Be(2);
        }
예제 #11
0
        public virtual async Task Migrate()
        {
            var badgeItem1 = new Badge();

            badgeItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1);
            this.Context.Badges.Add(badgeItem1);

            var commentItem1 = new Comment();

            commentItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1);
            this.Context.Comments.Add(commentItem1);

            var linkTypeItem1 = new LinkType();

            linkTypeItem1.SetProperties(1, "A");
            this.Context.LinkTypes.Add(linkTypeItem1);

            var postHistoryItem1 = new PostHistory();

            postHistoryItem1.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1);
            this.Context.PostHistories.Add(postHistoryItem1);

            var postHistoryTypeItem1 = new PostHistoryType();

            postHistoryTypeItem1.SetProperties(1, "A");
            this.Context.PostHistoryTypes.Add(postHistoryTypeItem1);

            var postLinkItem1 = new PostLink();

            postLinkItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            this.Context.PostLinks.Add(postLinkItem1);

            var postItem1 = new Post();

            postItem1.SetProperties(1, 1, 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, 1, 1, "A", "A", 1);
            this.Context.Posts.Add(postItem1);

            var postTypeItem1 = new PostType();

            postTypeItem1.SetProperties(1, "A");
            this.Context.PostTypes.Add(postTypeItem1);

            var tagItem1 = new Tag();

            tagItem1.SetProperties(1, 1, 1, "A", 1);
            this.Context.Tags.Add(tagItem1);

            var userItem1 = new User();

            userItem1.SetProperties(1, "A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, "A");
            this.Context.Users.Add(userItem1);

            var voteItem1 = new Vote();

            voteItem1.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            this.Context.Votes.Add(voteItem1);

            var voteTypeItem1 = new VoteType();

            voteTypeItem1.SetProperties(1, "A");
            this.Context.VoteTypes.Add(voteTypeItem1);

            await this.Context.SaveChangesAsync();
        }
예제 #12
0
파일: Post.cs 프로젝트: codenesium/samples
 public void SetPostTypeIdNavigation(PostType item)
 {
     this.PostTypeIdNavigation = item;
 }