public async virtual Task <PostHistory> Create(PostHistory item)
        {
            this.Context.Set <PostHistory>().Add(item);
            await this.Context.SaveChangesAsync();

            this.Context.Entry(item).State = EntityState.Detached;
            return(item);
        }
Exemplo n.º 2
0
        public async void Create()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var repository = new PostHistoryRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
        public async virtual Task Delete(
            int id)
        {
            PostHistory record = await this.GetById(id);

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

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

            await this.Context.SaveChangesAsync();
        }
        public async void Create()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var repository = new PostHistoryRepository(loggerMoc.Object, context);

            var entity = new PostHistory();

            entity.SetProperties(default(int), "B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, "B", "B", "B", 1);
            await repository.Create(entity);

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

            records.Count.Should().Be(2);
        }
Exemplo n.º 6
0
        public async void Get()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var repository = new PostHistoryRepository(loggerMoc.Object, context);

            PostHistory entity = new PostHistory();

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

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

            record.Should().NotBeNull();
        }
        public async void Get()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var repository = new PostHistoryRepository(loggerMoc.Object, context);

            PostHistory entity = new PostHistory();

            entity.SetProperties(default(int), "B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, "B", "B", "B", 1);
            context.Set <PostHistory>().Add(entity);
            await context.SaveChangesAsync();

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

            record.Should().NotBeNull();
        }
Exemplo n.º 8
0
        public async void Delete()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var         repository       = new PostHistoryRepository(loggerMoc.Object, context);
            PostHistory entity           = new PostHistory();

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

            await repository.Delete(entity.Id);

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

            modifiedRecord.Should().BeNull();
        }
Exemplo n.º 9
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var         repository       = new PostHistoryRepository(loggerMoc.Object, context);
            PostHistory entity           = new PostHistory();

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

            await repository.Update(new PostHistory());

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

            modifiedRecord.Should().NotBeNull();
        }
Exemplo n.º 10
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostHistoryRepository> > loggerMoc = PostHistoryRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostHistoryRepositoryMoc.GetContext();
            var         repository       = new PostHistoryRepository(loggerMoc.Object, context);
            PostHistory entity           = new PostHistory();

            entity.SetProperties(default(int), "B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, "B", "B", "B", 1);
            context.Set <PostHistory>().Add(entity);
            await context.SaveChangesAsync();

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

            await repository.Update(entity);

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

            records.Count.Should().Be(2);
        }
Exemplo n.º 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();
        }
Exemplo n.º 12
0
        public void Migrate()
        {
            var badgesItem1 = new Badges();

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

            var commentsItem1 = new Comments();

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

            var linkTypesItem1 = new LinkTypes();

            linkTypesItem1.SetProperties(1, "A");
            this.context.LinkTypes.Add(linkTypesItem1);

            var postHistoryItem1 = new PostHistory();

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

            var postHistoryTypesItem1 = new PostHistoryTypes();

            postHistoryTypesItem1.SetProperties(1, "A");
            this.context.PostHistoryTypes.Add(postHistoryTypesItem1);

            var postLinksItem1 = new PostLinks();

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

            var postsItem1 = new Posts();

            postsItem1.SetProperties(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, 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(postsItem1);

            var postTypesItem1 = new PostTypes();

            postTypesItem1.SetProperties(1, "A");
            this.context.PostTypes.Add(postTypesItem1);

            var tagsItem1 = new Tags();

            tagsItem1.SetProperties(1, 1, 1, "A", 1);
            this.context.Tags.Add(tagsItem1);

            var usersItem1 = new Users();

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

            var votesItem1 = new Votes();

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

            var voteTypesItem1 = new VoteTypes();

            voteTypesItem1.SetProperties(1, "A");
            this.context.VoteTypes.Add(voteTypesItem1);

            this.context.SaveChanges();
        }