Example #1
0
        private void when_wait_for_task()
        {
            act = () => { _actualTask = _waiter.Wait(_originalTask); };

            context["that is finished"] = () =>
            {
                before = () =>
                {
                    _originalTask = new TaskResource {
                        Id = ExpectedTaskId, State = TaskState.Canceled
                    };
                    _dateTimeSequence = CreateDateTimeSequence(1);
                    A.CallTo(() => _dateTime.Now).ReturnsNextFromSequence(_dateTimeSequence);
                };

                it["should return this task"] = () => { _actualTask.should_be_same(_originalTask); };
            };


            context["that is not finished"] = () =>
            {
                before = () =>
                {
                    _taskRepository = A.Fake <ITaskRepository>(x => x.Strict());
                    A.CallTo(() => _repository.Tasks).Returns(_taskRepository);
                };

                context["and task queued"] = () =>
                {
                    before = () =>
                    {
                        _originalTask = new TaskResource {
                            Id = ExpectedTaskId, State = TaskState.Queued
                        };
                        _finishedTask = new TaskResource {
                            Id = ExpectedTaskId, State = TaskState.Success
                        };
                        TaskResource[] tasks =
                        {
                            new TaskResource {
                                Id = ExpectedTaskId, State = TaskState.Queued
                            },
                            new TaskResource {
                                Id = ExpectedTaskId, State = TaskState.Executing
                            },
                            new TaskResource {
                                Id = ExpectedTaskId, State = TaskState.Executing
                            },
                            _finishedTask,
                            _finishedTask
                        };
                        _dateTimeSequence = CreateDateTimeSequence(4);
                        A.CallTo(() => _taskRepository.Get(ExpectedTaskId)).ReturnsNextFromSequence(tasks);
                    };

                    it["should return finished task"] = () => { _actualTask.should_be_same(_finishedTask); };
                };

                context["and task executing"] = () =>
                {
                    before = () =>
                    {
                        _originalTask = new TaskResource {
                            Id = ExpectedTaskId, State = TaskState.Executing
                        };
                        _finishedTask = new TaskResource {
                            Id = ExpectedTaskId, State = TaskState.Failed
                        };
                        TaskResource[] tasks =
                        {
                            new TaskResource {
                                Id = ExpectedTaskId, State = TaskState.Executing
                            },
                            _finishedTask
                        };
                        _dateTimeSequence = CreateDateTimeSequence(2);
                        A.CallTo(() => _taskRepository.Get(ExpectedTaskId)).ReturnsNextFromSequence(tasks);
                    };

                    it["should return finished task"] = () => { _actualTask.should_be_same(_finishedTask); };
                };
            };
        }