public IActionResult AddAllocationToPod(TeamType?teamType, [FromBody] PodAllocationRequest pod) { if (teamType == null) { return(BadRequest(new ErrorResponse("No pod by that name exists"))); } // If the request body is null (likely because it was not correctly formatted) // respond with an appropriate error if (pod == null) { return(BadRequest(new ErrorResponse("Bad or invalid request body"))); } if (!pod.Pod.IsStateValid) { return(BadRequest(new ErrorResponse("Invalid pod allocation supplied. No changes were saved"))); } Pod newPodState; lock (_updateAllocationLock) { switch (teamType) { case TeamType.A: _allocation.SetPodAAllocation(pod.Pod); newPodState = _allocation.PodA; break; case TeamType.B: _allocation.SetPodBAllocation(pod.Pod); newPodState = _allocation.PodB; break; case TeamType.C: _allocation.SetPodCAllocation(pod.Pod); newPodState = _allocation.PodC; break; case TeamType.D: _allocation.SetPodDAllocation(pod.Pod); newPodState = _allocation.PodD; break; default: return(NotFound(new ErrorResponse("No such pod"))); } _allocation.Commit(teamType.Value); } return(Json(newPodState)); }
private void ValidAllocationToValidPod_Success() { // Given var fooAllocation = MockAllocation.GetTestAllocation(); var fooProvider = new AllocationProvider(fooAllocation); var fooController = new TeamController(fooProvider); var fooNewAllocation = new PodAllocationRequest(MockPodD.GetTestPodD().AsPod); // When var successRes = fooController.AddAllocationToPod(TeamType.A, fooNewAllocation); // Then Assert.IsType <JsonResult>(successRes); }
private void ValidAllocationToNullPod_BadRequest() { // Given var fooAllocation = MockAllocation.GetTestAllocation(); var fooProvider = new AllocationProvider(fooAllocation); var fooController = new TeamController(fooProvider); var fooNewAllocation = new PodAllocationRequest(MockPodD.GetTestPodD().AsPod); // When var nullTypeRes = fooController.AddAllocationToPod(null, fooNewAllocation); // Then Assert.IsType <BadRequestObjectResult>(nullTypeRes); }