Esempio n. 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));
        }
Esempio n. 2
0
        public void CanSetDueDateNull()
        {
            var obj = new CssTask(TaskName);

            obj.SetDueDate(null);

            Assert.False(obj.DueDate.HasValue);
            Assert.False(obj.ScheduleDate.HasValue);  //scheduled date is set as it's null.
            Assert.True(obj.IsValid());
        }
Esempio n. 3
0
        public void CanSetDueDate()
        {
            var dueDate = DateTimeOffset.Now.AddDays(2);
            var obj     = new CssTask(TaskName);

            obj.SetDueDate(dueDate);

            Assert.Equal(dueDate, obj.DueDate);
            Assert.Equal(dueDate, obj.ScheduleDate);  //scheduled date is set as it's null.
            Assert.True(obj.IsValid());
        }
Esempio n. 4
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());
        }
Esempio n. 5
0
        public void DueDateShoudBeInValid(int yearDiff, int monthDiff, int dayDiff, int hourDiff, int minuteDiff, int secondDiff)
        {
            var dueDateToSet = DateTimeOffset.Now.AddYears(yearDiff).AddMonths(monthDiff).AddDays(dayDiff)
                               .AddHours(hourDiff).AddMinutes(minuteDiff).AddSeconds(secondDiff);
            var dueDateStart  = DateTimeOffset.Now.AddDays(14);
            var childDueDate  = DateTimeOffset.Now.AddDays(7);
            var scheduledDate = DateTimeOffset.Now.AddDays(6);

            var obj = new CssTask(new LongIdentity(1), TaskName, TaskDescription, dueDateStart, scheduledDate
                                  , DateTimeOffset.Now, DateTimeOffset.Now, new List <SubTask>()
            {
                new SubTask(new LongIdentity(2), TaskName, TaskDescription, childDueDate, childDueDate, DateTimeOffset.Now, DateTimeOffset.Now)
            });

            obj.SetDueDate(dueDateToSet);

            Assert.False(obj.IsValid());
        }