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

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

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

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

            LinkTypes entity = new LinkTypes();

            context.Set <LinkTypes>().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)
        {
            LinkTypes record = await this.GetById(id);

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

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

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

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

            await repository.Delete(entity.Id);

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

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

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

            await repository.Update(new LinkTypes());

            var modifiedRecord = context.Set <LinkTypes>().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();
        }