public async void All()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var repository = new LinkTypeRepository(loggerMoc.Object, context);
            var records    = await repository.All();

            records.Should().NotBeEmpty();
            records.Count.Should().Be(1);
        }
示例#2
0
        public async void Create()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var repository = new LinkTypeRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
        public void DeleteNotFound()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var repository = new LinkTypeRepository(loggerMoc.Object, context);

            Func <Task> delete = async() =>
            {
                await repository.Delete(default(int));
            };

            delete.Should().NotThrow();
        }
示例#4
0
        public async void Get()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var repository = new LinkTypeRepository(loggerMoc.Object, context);

            LinkType entity = new LinkType();

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

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

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

            var entity = new LinkType();

            entity.SetProperties(default(int), "B");
            await repository.Create(entity);

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

            records.Count.Should().Be(2);
        }
示例#6
0
        public async void Delete()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var      repository          = new LinkTypeRepository(loggerMoc.Object, context);
            LinkType entity = new LinkType();

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

            await repository.Delete(entity.Id);

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

            modifiedRecord.Should().BeNull();
        }
示例#7
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var      repository          = new LinkTypeRepository(loggerMoc.Object, context);
            LinkType entity = new LinkType();

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

            await repository.Update(new LinkType());

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

            modifiedRecord.Should().NotBeNull();
        }
        public async void DeleteFound()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var      repository          = new LinkTypeRepository(loggerMoc.Object, context);
            LinkType entity = new LinkType();

            entity.SetProperties(default(int), "B");
            context.Set <LinkType>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Delete(entity.Id);

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

            records.Count.Should().Be(1);
        }
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <LinkTypeRepository> > loggerMoc = LinkTypeRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = LinkTypeRepositoryMoc.GetContext();
            var      repository          = new LinkTypeRepository(loggerMoc.Object, context);
            LinkType entity = new LinkType();

            entity.SetProperties(default(int), "B");
            context.Set <LinkType>().Add(entity);
            await context.SaveChangesAsync();

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

            await repository.Update(entity);

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

            records.Count.Should().Be(2);
        }