Exemple #1
0
        public void ShouldCreateTask(string name, Guid projectId, TaskId nextIdentity, Guid resultIdentity)
        {
            "Given name"
            .x(() => name = "task name");

            "And project identity"
            .x(() => projectId = Guid.NewGuid());

            "And task repository that returns next identity".x(() =>
            {
                nextIdentity = TaskId.New();

                _taskRepositoryMock
                .Setup(x => x.GetNextIdentity())
                .Returns(nextIdentity);
            });

            "When I create task"
            .x(() => resultIdentity = _sut.CreateTask(projectId, name));

            "Then task repository should save the task"
            .x(() => _taskRepositoryMock.Verify(x => x.Save(It.IsAny <Task>())));

            "And task identity should be returned"
            .x(() => Assert.Equal(nextIdentity.Value, resultIdentity));

            "And saved task should have valid name, identity and project identity".x(() =>
            {
                Assert.Equal(projectId, _savedTask.GetState().ProjectId.Value);
                Assert.Equal(nextIdentity, _savedTask.GetState().TaskId);
                Assert.Equal(name, _savedTask.GetState().Name.Value);
            });
        }
Exemple #2
0
        public TaskId StartNew(ITask task)
        {
            var         id       = TaskId.New();
            TaskContext context  = null;
            bool        inserted = false;

            try
            {
                lock (_guard) {
                    while (_tasks.ContainsKey(id))
                    {
                        id = TaskId.New();
                    }
                    context    = new TaskContext(id, task, _actionExecutor);
                    _tasks[id] = context;
                }
                inserted = true;
                context.StartExecution();
                context = null;
                return(id);
            }
            catch
            {
                if (inserted)
                {
                    lock (_guard)
                    {
                        _tasks.Remove(id);
                    }
                }
                throw;
            }
            finally
            {
                context?.Dispose();
            }
        }
 public TaskId GetNextIdentity()
 {
     return(TaskId.New());
 }