Exemplo n.º 1
0
        public void Init()
        {
            var dateTimeOffset      = new DateTimeOffset(DateTime.UtcNow);
            var alertDateTimeOffset = new DateTimeOffset(DateTime.UtcNow.AddHours(5));

            _task = new DiaTask
            {
                Id              = Guid.NewGuid().ToString(),
                UserId          = null, // intentionally null since we can't set user claims.
                TaskDescription = "Here's my task description.",
                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"
                    }
                }
            };

            _comment = new Comment {
                Id = Guid.NewGuid().ToString(), Text = "Hi2"
            };
            _alert = new AlertTime {
                Time = DateTimeOffset.UtcNow.AddHours(5)
            };
        }
Exemplo n.º 2
0
        public static void Init()
        {
            _dbContext = GenerateDbContext();

            var dateTimeOffset      = new DateTimeOffset(DateTime.UtcNow);
            var alertDateTimeOffset = new DateTimeOffset(DateTime.UtcNow.AddHours(5));

            _task = new DiaTask
            {
                Id              = Guid.NewGuid().ToString(),
                UserId          = null, // intentionally null since we can't set user claims.
                TaskDescription = "Here's my task description.",
                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.Add(_task);
            _dbContext.SaveChanges();
        }
Exemplo n.º 3
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.º 4
0
        public async Task UpdateTaskAsync(DiaTask task)
        {
            try
            {
                var entity = await FindTaskByIdForUserAsync(task.Id, task.UserId).ConfigureAwait(false);

                if (entity == null)
                {
                    throw new NoDatabaseObjectFoundException($"Task {task.Id} was not found.");
                }

                UpdateEntityWithTask(task, entity);

                _doItDbContext.Entry(entity).State = EntityState.Modified;

                await _doItDbContext.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (NoDatabaseObjectFoundException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new DatabaseUpdateException(e);
            }
        }
Exemplo n.º 5
0
        public void TaskService_UpdateCommentTaskNotFound_ThrowsNoDatabaseObjectFoundException()
        {
            var taskService = new TaskService(_dbContext);
            var newTask     = new DiaTask {
                Id = "abcde"
            };

            Assert.ThrowsAsync <NoDatabaseObjectFoundException>(() => taskService.UpdateCommentAsync(newTask.Id, new Comment()));
        }
Exemplo n.º 6
0
 private static void UpdateEntityWithTask(DiaTask task, DiaTask entity)
 {
     entity.UpdatedDate     = DateTimeOffset.UtcNow;
     entity.TaskDescription = task.TaskDescription;
     entity.DueDateTime     = task.DueDateTime;
     entity.AlertTimes      = task.AlertTimes;
     entity.Comments        = task.Comments;
     entity.IsCompleted     = task.IsCompleted;
 }
Exemplo n.º 7
0
        public void TaskService_UpdateAlertTaskNotFound_ThrowsNoDatabaseObjectFoundException()
        {
            var taskService = new TaskService(_dbContext);
            var newTask     = new DiaTask {
                Id = "abcde"
            };

            Assert.ThrowsAsync <NoDatabaseObjectFoundException>(() => taskService.UpdateAlertAsync(newTask.Id, new AlertTime {
                Time = DateTimeOffset.UtcNow.AddHours(2)
            }));
        }
Exemplo n.º 8
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.º 9
0
        public async Task <IActionResult> PostTaskAsync(DiaTask task)
        {
            try
            {
                task.UserId = UserId;
                await _taskService.AddTaskAsync(task).ConfigureAwait(false);

                return(Ok());
            }
            catch (DatabaseUpdateException e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 10
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.º 11
0
        public async Task TaskService_MarkTaskIncomplete_TaskMarkedIncomplete()
        {
            var taskService = new TaskService(_dbContext);
            var newTask     = new DiaTask {
                Id = "myId", IsCompleted = true
            };

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

            await taskService.MarkTaskCompleteStatusAsync(newTask.Id, null, false);

            _dbContext.Tasks.FirstOrDefault(x => x.Id == newTask.Id).IsCompleted.Should().BeFalse();
        }
Exemplo n.º 12
0
        public void Task_ModelCreated_GetWorks()
        {
            var dateTimeOffset = new DateTimeOffset(DateTime.UtcNow);
            var task           = new DiaTask
            {
                Id              = Guid.NewGuid().ToString(),
                UserId          = "myuserid",
                TaskDescription = "Here's my task description.",
                DueDateTime     = dateTimeOffset
            };

            task.Id.Should().NotBeNull();
            task.UserId.Should().NotBeNull();
            task.TaskDescription.Should().NotBeNull().And.Should().NotBe(string.Empty);
            task.DueDateTime.Should().Be(dateTimeOffset);
            task.AlertTimes.Should().NotBeNull();
            task.Comments.Should().NotBeNull();
        }
Exemplo n.º 13
0
        public async Task <IActionResult> UpdateTaskAsync(DiaTask task)
        {
            if (string.IsNullOrWhiteSpace(task.Id))
            {
                return(BadRequest("Id on task is required."));
            }

            try
            {
                task.UserId = UserId;
                await _taskService.UpdateTaskAsync(task).ConfigureAwait(false);

                return(Ok());
            }
            catch (NoDatabaseObjectFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (DatabaseUpdateException e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 14
0
        public void Task_ModelCreated_SetWorks()
        {
            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.",
                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"
                    }
                }
            };

            task.Should().NotBeNull();
        }