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

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

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

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

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

            VoteTypes entity = new VoteTypes();

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

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

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

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

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

            await this.Context.SaveChangesAsync();
        }
        public async void Delete()
        {
            Mock <ILogger <VoteTypesRepository> > loggerMoc = VoteTypesRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = VoteTypesRepositoryMoc.GetContext();
            var       repository         = new VoteTypesRepository(loggerMoc.Object, context);
            VoteTypes entity             = new VoteTypes();

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

            await repository.Delete(entity.Id);

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

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

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

            await repository.Update(new VoteTypes());

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

            modifiedRecord.Should().NotBeNull();
        }
Example #8
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();
        }