Exemplo n.º 1
0
        public async virtual Task <Badges> Create(Badges item)
        {
            this.Context.Set <Badges>().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 <BadgesRepository> > loggerMoc = BadgesRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = BadgesRepositoryMoc.GetContext();
            var repository = new BadgesRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
Exemplo n.º 3
0
        public async void Get()
        {
            Mock <ILogger <BadgesRepository> > loggerMoc = BadgesRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = BadgesRepositoryMoc.GetContext();
            var repository = new BadgesRepository(loggerMoc.Object, context);

            Badges entity = new Badges();

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

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

            record.Should().NotBeNull();
        }
Exemplo n.º 4
0
        public async virtual Task Delete(
            int id)
        {
            Badges record = await this.GetById(id);

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

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

            await this.Context.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async void Delete()
        {
            Mock <ILogger <BadgesRepository> > loggerMoc = BadgesRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = BadgesRepositoryMoc.GetContext();
            var    repository            = new BadgesRepository(loggerMoc.Object, context);
            Badges entity = new Badges();

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

            await repository.Delete(entity.Id);

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

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

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

            await repository.Update(new Badges());

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

            modifiedRecord.Should().NotBeNull();
        }
Exemplo n.º 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();
        }