public void TestCreate_Success()
        {
            //Arrange
            Guid taskListGuid = new Guid("00000000-0000-0000-1111-000000000001");
            Task newTask = new Task()
            {
                Complete = false,
                Description = "Desc",
                Due = new DateTime(2010, 1, 1),
                Name = "Name"
            };
            TaskViewModel newTaskViewModel = new TaskViewModel(newTask);
            var stubDao = MockRepository.GenerateStub<ITaskListDao>();
            TaskController controller = new TaskController(stubDao);

            //Act
            ActionResult ar = controller.Create(taskListGuid, newTaskViewModel);

            //Assert
            stubDao.AssertWasCalled(x => x.AddTask(Arg<Task>.Matches(t => t.Id != default(Guid))));
            stubDao.AssertWasCalled(x => x.AddTask(Arg<Task>.Matches(t => t.Complete == false)));
            stubDao.AssertWasCalled(x => x.AddTask(Arg<Task>.Matches(t => t.Description == "Desc")));
            stubDao.AssertWasCalled(x => x.AddTask(Arg<Task>.Matches(t => t.Due == new DateTime(2010, 1, 1))));
            stubDao.AssertWasCalled(x => x.AddTask(Arg<Task>.Matches(t => t.Name == "Name")));
            stubDao.AssertWasCalled(x => x.AddTask(Arg<Task>.Matches(t => t.TaskListId == taskListGuid)));

            Assert.IsInstanceOf<EmptyResultWithStatus>(ar);
            EmptyResultWithStatus ers = ar as EmptyResultWithStatus;
            Assert.AreEqual(201, ers.StatusCode);
            Assert.IsNotNull(ers.Location);
            Assert.Greater(ers.Location.ToString().Length, 0);
            Assert.AreNotEqual(default(Guid).ToString("D"), ers.Location.ToString());
        }
        public void TestUrl()
        {
            TaskViewModel vm = new TaskViewModel();
            vm.Id = new Guid("0c51048d-1820-421d-ac41-13d579d4a6ad");

            Assert.AreEqual("/Task/0c51048d-1820-421d-ac41-13d579d4a6ad", vm.Self);
        }
 public ActionResult Create(Guid taskListId, TaskViewModel tvm)
 {
     Task t = tvm.Task;
     t.Id = Guid.NewGuid();
     t.TaskListId = taskListId;
     dao.AddTask(t);
     return new EmptyResultWithStatus(201, new Uri(t.Id.ToString("D"), UriKind.Relative));
 }
        public ActionResult GetTask(Guid taskId, string format)
        {
            Task task = dao.GetTask(taskId);
            if (task == null)
            {
                return new EmptyResultWithStatus(404);
            }

            TaskViewModel tvm = new TaskViewModel(task);

            return SelectActionResult("Task", tvm, format);
        }