Exemplo n.º 1
0
        public void UpsertTaskShouldAddNewTask()
        {
            //arrange
            var sut = CreateLogic();
            var ctx = A.Fake<ITaskListContext>();

            A.CallTo(() => contextFactory.Create())
                .Returns(ctx);

            var task = new Task()
            {
                Description = "New Test Task",
                TaskType = TaskType.Social
            };

            A.CallTo(() => ctx.Tasks.Add(task))
                .Invokes(call =>
                {
                    (call.Arguments.First() as Task).TaskId = 5;
                });

            //act
            sut.UpsertTask(task);

            //assert
            Assert.AreEqual(5, task.TaskId);
        }
Exemplo n.º 2
0
 public TaskView(Task task)
 {
     this.taskId = task.TaskId;
     this.description = task.Description;
     this.createDate = task.CreateDate;
     this.taskType = task.TaskType;
     this.taskTypeName = task.TaskType.ToFriendlyString();
 }
Exemplo n.º 3
0
        public HttpResponseMessage Post(Task task)
        {
            var result = new ApiResult();

            try
            {
                logic.UpsertTask(task);

                result.SetSavedSuccess("task", new TaskView(task));
            }
            catch
            {
                result.SetSavedFailed("task");

                //TODO: Log failure and exception
            }

            return Request.CreateResponse(result);
        }
Exemplo n.º 4
0
        public void UpsertTask(Task task)
        {
            using (var ctx = contextFactory.Create())
            {
                if (task.TaskId == 0)
                {
                    task.CreateDate = DateTime.Now;
                    ctx.Tasks.Add(task);
                }
                else
                {
                    var currentTask = ctx.Tasks.SingleOrDefault(t => t.TaskId == task.TaskId);

                    if (currentTask == null)
                        throw new RecordNotFoundException<Task>(task.TaskId);

                    //'last in wins' concurrency
                    currentTask.Description = task.Description;
                    currentTask.TaskType = task.TaskType;
                }

                ctx.SaveChanges();
            }
        }
Exemplo n.º 5
0
 public HttpResponseMessage Put(Task task)
 {
     //follows upsert semantic > put only exists for RESTful correctness
     return Post(task);
 }
Exemplo n.º 6
0
        public void UpsertTaskShouldThrowWithNotFoundTask()
        {
            //arrange
            var sut = CreateLogic();

            var task = new Task()
            {
                TaskId = 55,
                Description = "Test Task 1 Update",
                TaskType = TaskType.Social
            };

            //act
            sut.UpsertTask(task);
        }
Exemplo n.º 7
0
        public void UpsertTaskShouldUpdateExistingTask()
        {
            //arrange
            var sut = CreateLogic();

            var task = new Task()
            {
                TaskId = 1,
                Description = "Test Task 1 Update",
                TaskType = TaskType.Social
            };

            //act
            sut.UpsertTask(task);

            //assert
            Assert.AreEqual(task.Description, tasks.Single(t => t.TaskId == 1).Description);
        }