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

            this.Context.Entry(item).State = EntityState.Detached;
            return(item);
        }
        public async void Create()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var repository = new PostLinkRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
Example #3
0
        public async virtual Task Delete(
            int id)
        {
            PostLink record = await this.GetById(id);

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

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

            await this.Context.SaveChangesAsync();
        }
Example #5
0
        public async void Create()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var repository = new PostLinkRepository(loggerMoc.Object, context);

            var entity = new PostLink();

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

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

            records.Count.Should().Be(2);
        }
        public async void Get()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var repository = new PostLinkRepository(loggerMoc.Object, context);

            PostLink entity = new PostLink();

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

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

            record.Should().NotBeNull();
        }
Example #7
0
        public async void Get()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var repository = new PostLinkRepository(loggerMoc.Object, context);

            PostLink entity = new PostLink();

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

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

            record.Should().NotBeNull();
        }
        public async void Delete()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var      repository          = new PostLinkRepository(loggerMoc.Object, context);
            PostLink entity = new PostLink();

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

            await repository.Delete(entity.Id);

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

            modifiedRecord.Should().BeNull();
        }
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var      repository          = new PostLinkRepository(loggerMoc.Object, context);
            PostLink entity = new PostLink();

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

            await repository.Update(new PostLink());

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

            modifiedRecord.Should().NotBeNull();
        }
Example #10
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <PostLinkRepository> > loggerMoc = PostLinkRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = PostLinkRepositoryMoc.GetContext();
            var      repository          = new PostLinkRepository(loggerMoc.Object, context);
            PostLink entity = new PostLink();

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

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

            await repository.Update(entity);

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

            records.Count.Should().Be(2);
        }
Example #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();
        }