コード例 #1
0
 public ActionResult AddTask(int projectId, int storyId, string description, string initials)
 {
     var task = new Task { Description = description, ParentStoryId = storyId, ProjectId = projectId };
     task.Description = AddInitialsToDescription(task, initials);
     Service.AddNewTask (task);
     return GetStory (storyId, projectId);
 }
コード例 #2
0
        public void Complete_Doesnt_Save_Task_If_No_Change()
        {
            var mockery = new MockRepository();

            var projectId = 3;
            var storyId = 4;
            var id = 5;
            var completed = true;
            var description = "Doin work";
            var task = new Task { Description = description, Id = id, ParentStoryId = storyId, ProjectId = projectId, Complete = true };

            var storyService = mockery.StrictMock<IStoryService>();

            using (mockery.Record())
            using (mockery.Ordered()) {
                Expect.Call(storyService.GetTask(projectId, storyId, id)).Return(task);
            }

            using (mockery.Playback()) {
                var controller = new TaskController(storyService);
                var result = controller.Complete(id, storyId, projectId, completed);
                var viewResult = result as PartialViewResult;
                Assert.NotNull(viewResult);
                Assert.AreEqual("TaskDetails", viewResult.ViewName);
                Assert.IsInstanceOf<TaskViewModel>(viewResult.Model);
                Assert.AreEqual(task, (viewResult.Model as TaskViewModel).Task);
            }
        }
コード例 #3
0
        public Task AddNewTask(Task task)
        {
            var request = BuildPostRequest();
            request.Resource = string.Format(SaveNewTaskEndpoint, task.ProjectId, task.ParentStoryId, task.Description);

            var response = RestClient.Execute<Task>(request);
            return response.Data;
        }
コード例 #4
0
        public void ActivityProcessingTest()
        {
            int storyId;

            {
                var story = new Story
                {
                    Name = "Nouvelle histoire",
                    RequestedById = Constants.UserId,
                    StoryType = StoryType.Feature,
                    Description = "bla bla bla and more bla",
                    ProjectId = Constants.ProjectId
                };

                var savedStory = this.storyService.AddNewStory(Constants.ProjectId, story);

                var task1 = new Task { Description = "stuff stuff stuff", StoryId = savedStory.Id, ProjectId = Constants.ProjectId };
                var task2 = new Task { Description = "stuff stuff stuff", StoryId = savedStory.Id, ProjectId = Constants.ProjectId };

                var savedTask1 = this.storyService.AddNewTask(task1);

                savedStory.Labels = new List<Label>() { "Label1", "Label2" };
                savedStory.Estimate = 3;

                savedStory = this.storyService.UpdateStory(Constants.ProjectId, savedStory);

                var savedTask2 = this.storyService.AddNewTask(task2);

                this.storyService.AddComment(savedStory.ProjectId, savedStory.Id, "Comment 1");
                this.storyService.AddComment(savedStory.ProjectId, savedStory.Id, "Comment 2");

                savedStory.Name     = "New story";
                savedStory.Deadline = DateTimeOffset.Now.AddDays(10);
                savedStory.Estimate = 3;

                savedStory = this.storyService.UpdateStory(Constants.ProjectId, savedStory);

                storyId = savedStory.Id;
            }

            var activities = this.storyService.GetStoryActivity(Constants.ProjectId, storyId);

            activities = activities.OrderBy(a => a.OccurredAt).ToList();

            var accumulatedStoryValues      = new Dictionary<string, object>();
            var accumulatedTasksValues      = new Dictionary<int, Dictionary<string, object>>();
            var accumulatedCommentValues    = new Dictionary<int, Dictionary<string, object>>();
            var accumulatedLabelValues      = new Dictionary<int, Dictionary<string, object>>();

            var deserializer = new DictionaryDeserializer();

            var foundObjects = new List<object>();

            foreach (var activity in activities)
            {
                foreach (var change in activity.Changes)
                {
                    if (change.NewValues != null && change.NewValues.Count == 1 && change.NewValues.ContainsKey("updated_at"))
                        continue; // Skip story changes without any significat changes

                    switch (change.Kind)
                    {
                        case ResourceKind.Story:
                        {
                            if (change.NewValues != null)
                                change.NewValues.ToList().ForEach(kp => accumulatedStoryValues[kp.Key] = kp.Value);
                            else if (change.OriginalValues != null)
                                change.OriginalValues.ToList().ForEach(kp => accumulatedStoryValues[kp.Key] = kp.Value);

                            var story = deserializer.Deserialize<Story>(accumulatedStoryValues);

                            if (activity.OccurredAt != DateTimeOffset.MinValue || 
                                (change.NewValues != null && !change.NewValues.ContainsKey("updated_at")))
                            {
                                story.UpdatedAt = activity.OccurredAt;
                            }

                            foundObjects.Add(story);
                            break;
                        }

                        case ResourceKind.Comment:
                        {
                            Dictionary<string, object> values;
                            if (!accumulatedTasksValues.TryGetValue(change.Id, out values))
                            {
                                values = accumulatedTasksValues[change.Id] = new Dictionary<string, object>();
                            }

                            if (change.NewValues != null)
                                change.NewValues.ToList().ForEach(kp => values[kp.Key] = kp.Value);
                            else if (change.OriginalValues != null)
                                change.OriginalValues.ToList().ForEach(kp => values[kp.Key] = kp.Value);

                            var comment = deserializer.Deserialize<Comment>(values);

                            if (activity.OccurredAt != DateTimeOffset.MinValue || 
                                (change.NewValues != null && !change.NewValues.ContainsKey("updated_at")))
                            {
                                comment.UpdatedAt = activity.OccurredAt;
                            }

                            foundObjects.Add(comment);
                            break;
                        }

                        case ResourceKind.Task:
                        {
                            Dictionary<string, object> values;
                            if (!accumulatedCommentValues.TryGetValue(change.Id, out values))
                            {
                                values = accumulatedCommentValues[change.Id] = new Dictionary<string, object>();
                            }

                            if (change.NewValues != null)
                                change.NewValues.ToList().ForEach(kp => values[kp.Key] = kp.Value);
                            else if (change.OriginalValues != null)
                                change.OriginalValues.ToList().ForEach(kp => values[kp.Key] = kp.Value);

                            var task = deserializer.Deserialize<Task>(values);

                            if (activity.OccurredAt != DateTimeOffset.MinValue || 
                                (change.NewValues != null && !change.NewValues.ContainsKey("updated_at")))
                            {
                                task.UpdatedAt = activity.OccurredAt;
                            }

                            foundObjects.Add(task);
                            break;
                        }

                        case ResourceKind.Label:
                        {
                            Dictionary<string, object> values;
                            if (!accumulatedLabelValues.TryGetValue(change.Id, out values))
                            {
                                values = accumulatedLabelValues[change.Id] = new Dictionary<string, object>();
                            }

                            if (change.NewValues != null)
                                change.NewValues.ToList().ForEach(kp => values[kp.Key] = kp.Value);
                            else if (change.OriginalValues != null)
                                change.OriginalValues.ToList().ForEach(kp => values[kp.Key] = kp.Value);

                            var label = deserializer.Deserialize<Label>(values);

                            if (activity.OccurredAt != DateTimeOffset.MinValue || 
                                (change.NewValues != null && !change.NewValues.ContainsKey("updated_at")))
                            {
                                label.UpdatedAt = activity.OccurredAt;
                            }

                            foundObjects.Add(label);
                            break;
                        }

                        default:
                            throw new Exception("Unhandled resource kind: " + change.Kind);
                    }
                }
            }

            Assert.IsNotEmpty(foundObjects);
            Assert.AreEqual(4, foundObjects.Where(o => o is Story).Count());
            Assert.AreEqual(2, foundObjects.Where(o => o is Comment).Count());
            Assert.AreEqual(2, foundObjects.Where(o => o is Task).Count());
            Assert.AreEqual(2, foundObjects.Where(o => o is Label).Count());
        }
コード例 #5
0
        public void CanAddGetAndDeleteNewTasks()
        {
            var story = new Story
            {
                Name = "Nouvelle histoire",
                RequestedById = Constants.UserId,
                StoryType = StoryType.Feature,
                Description = "bla bla bla and more bla",
                ProjectId = Constants.ProjectId
            };

            var savedStory = this.storyService.AddNewStory(Constants.ProjectId, story);

            var task = new Task { Description = "stuff stuff stuff", StoryId = savedStory.Id, ProjectId = Constants.ProjectId };

            var savedTask = this.storyService.AddNewTask(task);
            Assert.AreEqual(task.Description, savedTask.Description);

            var retrievedTask = this.storyService.GetTask(Constants.ProjectId, savedTask.StoryId, savedTask.Id);
            Assert.NotNull(retrievedTask);

            Assert.IsTrue(this.storyService.RemoveTask(retrievedTask.ProjectId, task.StoryId, retrievedTask.Id));
        }
コード例 #6
0
        public void SignUp_No_Initials_Clears_Existing()
        {
            var mockery = new MockRepository();

            var projectId = 3;
            var storyId = 4;
            var id = 5;
            var initials = "";
            var description = "Doin work (AA/FF)";
            var task = new Task { Description = description, Id = id, ParentStoryId = storyId, ProjectId = projectId };

            var storyService = mockery.StrictMock<IStoryService>();

            using (mockery.Record())
            using (mockery.Ordered()) {
                Expect.Call(storyService.GetTask(projectId, storyId, id)).Return(task);
                storyService.SaveTask(task);
            }

            using (mockery.Playback()) {
                var controller = new TaskController(storyService);
                var result = controller.SignUp(initials, new[] { string.Format("{0}-{1}-{2}", projectId, storyId, id) });
                var viewResult = result as RedirectToRouteResult;
                Assert.NotNull(viewResult);
                Assert.False(task.Description.Contains("(AA/FF)"));
            }
        }
コード例 #7
0
        public void SignUp_Multiple()
        {
            var mockery = new MockRepository();

            var projectId = 3;
            var storyId = 4;
            var id = 5;
            var id2 = 6;
            var initials = "NN/GZ";
            var description = "Doin work";
            var task = new Task { Description = description, Id = id, ParentStoryId = storyId, ProjectId = projectId };
            var task2 = new Task { Description = description, Id = id2, ParentStoryId = storyId, ProjectId = projectId };

            var storyService = mockery.StrictMock<IStoryService>();

            using (mockery.Record())
            using (mockery.Ordered()) {
                Expect.Call(storyService.GetTask(projectId, storyId, id)).Return(task);
                storyService.SaveTask(task);
                Expect.Call(storyService.GetTask(projectId, storyId, id2)).Return(task2);
                storyService.SaveTask(task2);
            }

            using (mockery.Playback()) {
                var controller = new TaskController(storyService);
                var result = controller.SignUp(initials, new[] {
                    string.Format("{0}-{1}-{2}", projectId, storyId, id),
                    string.Format("{0}-{1}-{2}", projectId, storyId, id2),
                });
                var redirectResult = result as RedirectToRouteResult;
                Assert.NotNull(redirectResult);
                //Assert.AreEqual("Get", redirectResult.RouteName);
            }
        }
コード例 #8
0
        public void SignUp_Lowercase_Initials()
        {
            var mockery = new MockRepository();

            var projectId = 3;
            var storyId = 4;
            var id = 5;
            var initials = "nn/gz";
            var description = "Doin work";
            var task = new Task { Description = description, Id = id, ParentStoryId = storyId, ProjectId = projectId };

            var storyService = mockery.StrictMock<IStoryService>();

            using (mockery.Record())
            using (mockery.Ordered()) {
                Expect.Call(storyService.GetTask(projectId, storyId, id)).Return(task);
                storyService.SaveTask(task);
            }

            using (mockery.Playback()) {
                var controller = new TaskController(storyService);
                var result = controller.SignUp(initials, new[] { string.Format("{0}-{1}-{2}", projectId, storyId, id) });
                var redirectResult = result as RedirectToRouteResult;
                Assert.NotNull(redirectResult);
                Assert.True(task.Description.EndsWith("(NN/GZ)"));
            }
        }
コード例 #9
0
 private string AddInitialsToDescription(Task task, string initials)
 {
     return new TaskViewModel(task).GetDescriptionWithoutOwners() + (string.IsNullOrEmpty(initials) ? "" : (" (" + initials.ToUpper() + ")"));
 }
コード例 #10
0
 public TaskViewModel(Task task)
 {
     Task = task;
 }
コード例 #11
0
 public Task AddNewTask(Task task)
 {
     var request = BuildPostRequest();
     request.Resource = string.Format(TaskEndpoint, task.ProjectId, task.StoryId);
     request.AddParameter("application/json", task.ToJson(), ParameterType.RequestBody);
     var savedTask = RestClient.ExecuteRequestWithChecks<Task>(request);
     savedTask.ProjectId = task.ProjectId;
     return savedTask;
 }
コード例 #12
0
 public Task AddNewTask(Task task)
 {
     var request = BuildPostRequest();
     request.Resource = string.Format(SaveNewTaskEndpoint, task.ProjectId, task.ParentStoryId, task.Description);
     //request.AddParameter("application/xml", toBeSaved.ToXml(), ParameterType.RequestBody);
     var response = RestClient.Execute<Task>(request);
     var savedTask = response.Data;
     savedTask.ParentStoryId = task.ParentStoryId;
     savedTask.ProjectId = task.ProjectId;
     return savedTask;
 }
コード例 #13
0
 public void SaveTask(Task task)
 {
     var request = BuildPutRequest();
     request.Resource = string.Format(TaskEndpoint + "/{2}?task[description]={3}&task[complete]={4}&task[position]={5}", task.ProjectId, task.ParentStoryId, task.Id, HttpUtility.UrlEncode(task.Description), task.Complete.ToString().ToLower(), task.Position);
     RestClient.Execute(request);
 }