Exemplo n.º 1
0
        public async Task <TEntity> AddAsync(TEntity item)
        {
            await _context.Set <TEntity>().AddAsync(item);

            await _context.SaveChangesAsync();

            return(item);
        }
Exemplo n.º 2
0
        public async Task TaskService_AddTask_ThrowsDatabaseUpdateException()
        {
            var task = GenerateRandomTask();

            _dbContext.Tasks = null;
            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            var taskService = new TaskService(_dbContext);

            Assert.ThrowsAsync <DatabaseUpdateException>(() => taskService.AddTaskAsync(task));
        }
Exemplo n.º 3
0
 public async Task AddTaskAsync(DiaTask task)
 {
     try
     {
         _doItDbContext.Tasks.Add(task);
         await _doItDbContext.SaveChangesAsync().ConfigureAwait(false);
     }
     catch (Exception e)
     {
         throw new DatabaseUpdateException(e);
     }
 }
Exemplo n.º 4
0
        public async Task DoItDbContextTests_SetAndGetTasks_SetsProperly()
        {
            var dateTimeOffset      = new DateTimeOffset(DateTime.UtcNow);
            var alertDateTimeOffset = new DateTimeOffset(DateTime.UtcNow.AddHours(5));
            var task = new DiaTask
            {
                Id              = Guid.NewGuid().ToString(),
                UserId          = "myuserid",
                TaskDescription = "Here's my task description.",
                CreatedDate     = DateTimeOffset.UtcNow,
                DueDateTime     = dateTimeOffset,
                AlertTimes      = new List <AlertTime> {
                    new AlertTime {
                        Id = Guid.NewGuid().ToString(), Time = alertDateTimeOffset
                    }
                },
                Comments = new List <Comment> {
                    new Comment {
                        Id = Guid.NewGuid().ToString(), Text = "Hi"
                    }
                }
            };

            _dbContext.Tasks = new InternalDbSet <DiaTask>(_dbContext)
            {
                task
            };
            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            _dbContext.Tasks.Should().Contain(task);
        }
Exemplo n.º 5
0
        public async Task TaskService_GetAlerts_ThrowsNoAlertsFoundException()
        {
            _dbContext = GenerateDbContext();
            var newTask = new DiaTask {
                Id = "abcde"
            };

            _dbContext.Tasks.Add(newTask);
            await _dbContext.SaveChangesAsync();

            var taskService = new TaskService(_dbContext);

            Assert.ThrowsAsync <NoAlertsFoundException>(() => taskService.GetAlertsAsync(null, newTask.Id));
        }
Exemplo n.º 6
0
 public async Task AddAsync <TEntity>(TEntity entity)
     where TEntity : class
 {
     _context.Add(entity);
     await _context.SaveChangesAsync();
 }