Beispiel #1
0
        public async Task <CreateTaskResponse> Process(CreateTaskRequest request)
        {
            var task = new CssTask(request.Name);

            task.SetDueDate(request.DueDate);
            task.SetDescription(request.Description);
            task.SetScheduledDate(request.ScheduledDate);

            //we don't allow them to save invalid tasks.
            if (task.IsValid())
            {
                try
                {
                    await _repository.Save(task);

                    return(new CreateTaskResponse(true));
                }
                catch (Exception ex)
                {
                    //Oh crap errors, validations are handled by is valid.
                    _logger.LogError(ex, "Unable to create task.");
                    var errors = new Validations();
                    errors.AddError(ErrorCode.Unexpected, ex.Message);
                    return(new CreateTaskResponse(false, errors));
                }
            }
            return(new CreateTaskResponse(false, task.Errors));
        }
Beispiel #2
0
        public void ScheduleDateShouldBeInValid(string dDate, string sDate)
        {
            var dueDate       = DateTimeOffset.Parse(dDate);
            var scheduledDate = DateTimeOffset.Parse(sDate);
            var obj           = new CssTask(TaskName);

            obj.SetDueDate(dueDate);
            obj.SetScheduledDate(scheduledDate);

            //scheduled date is set as it's null.
            Assert.False(obj.IsValid());
        }
Beispiel #3
0
        public void CanSetScheduleDateNull()
        {
            var dueDate = DateTimeOffset.Now.AddDays(2);

            var obj = new CssTask(TaskName);

            obj.SetDueDate(dueDate);
            obj.SetScheduledDate(null);

            Assert.Equal(dueDate, obj.DueDate);
            Assert.False(obj.ScheduleDate.HasValue);  //scheduled date is set as it's null.
            Assert.True(obj.IsValid());
        }