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 CanCreateNew()
        {
            var obj = new CssTask(TaskName);

            Assert.Equal(TaskName, obj.Name);
            Assert.True(obj.IsValid());
        }
Beispiel #3
0
        public void ValidDescription(string description)
        {
            var obj = new CssTask(TaskName);

            obj.SetDescription(description);

            Assert.True(obj.IsValid());
        }
Beispiel #4
0
        public void CanSetDescription()
        {
            var obj = new CssTask(TaskName);

            obj.SetDescription(TaskDescription);

            Assert.True(obj.IsValid());
            Assert.Equal(TaskDescription, obj.Description);
        }
Beispiel #5
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());
        }
Beispiel #6
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());
        }
Beispiel #7
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 #8
0
        public void CanCreateFull()
        {
            var dueDate       = DateTimeOffset.Now.AddDays(1);
            var scheduledDate = DateTimeOffset.Now;
            var obj           = new CssTask(new LongIdentity(1), TaskName, TaskDescription, dueDate,
                                            scheduledDate, DateTimeOffset.Now, DateTimeOffset.Now, null);

            Assert.True(obj.IsValid());
            Assert.Equal(TaskName, obj.Name);
            Assert.Equal(TaskDescription, obj.Description);
            Assert.Equal(dueDate, obj.DueDate);
            Assert.Equal(scheduledDate, obj.ScheduleDate);
        }
Beispiel #9
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());
        }
Beispiel #10
0
        public void InvalidNameShouldFail(string name)
        {
            var obj = new CssTask(name);

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