コード例 #1
0
        public async virtual Task Delete(
            int id)
        {
            DeviceAction record = await this.GetById(id);

            if (record == null)
            {
                return;
            }
            else
            {
                this.Context.Set <DeviceAction>().Remove(record);
                await this.Context.SaveChangesAsync();
            }
        }
コード例 #2
0
        public async void All()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var repository = new DeviceActionRepository(loggerMoc.Object, context);

            DeviceAction entity = new DeviceAction();

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

            var record = await repository.All();

            record.Should().NotBeEmpty();
        }
コード例 #3
0
        public async virtual Task Update(DeviceAction item)
        {
            var entity = this.Context.Set <DeviceAction>().Local.FirstOrDefault(x => x.Id == item.Id);

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

            await this.Context.SaveChangesAsync();
        }
コード例 #4
0
        public async void Create()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var repository = new DeviceActionRepository(loggerMoc.Object, context);

            var entity = new DeviceAction();

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

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

            records.Count.Should().Be(2);
        }
コード例 #5
0
        public async void Delete()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var          repository      = new DeviceActionRepository(loggerMoc.Object, context);
            DeviceAction entity          = new DeviceAction();

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

            await repository.Delete(entity.Id);

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

            modifiedRecord.Should().BeNull();
        }
コード例 #6
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var          repository      = new DeviceActionRepository(loggerMoc.Object, context);
            DeviceAction entity          = new DeviceAction();

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

            await repository.Update(new DeviceAction());

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

            modifiedRecord.Should().NotBeNull();
        }
コード例 #7
0
        public async void Get()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var repository = new DeviceActionRepository(loggerMoc.Object, context);

            DeviceAction entity = new DeviceAction();

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

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

            record.Should().NotBeNull();
        }
コード例 #8
0
        public async void DeleteFound()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var          repository      = new DeviceActionRepository(loggerMoc.Object, context);
            DeviceAction entity          = new DeviceAction();

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

            await repository.Delete(entity.Id);

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

            records.Count.Should().Be(1);
        }
コード例 #9
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <DeviceActionRepository> > loggerMoc = DeviceActionRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = DeviceActionRepositoryMoc.GetContext();
            var          repository      = new DeviceActionRepository(loggerMoc.Object, context);
            DeviceAction entity          = new DeviceAction();

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

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

            await repository.Update(entity);

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

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