public async Task It_Should_Delete_Command() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()) .Returns(new Step { Id = 123 }); commandRepository.Get(Arg.Any <ulong>(), Arg.Any <string>()).Returns(new Command { Id = 123 }); var request = new DeleteCommandRequest { BatchId = TestBatchId, CommandName = TestCommandName }; // Act var response = await Sut.Delete(request); // Assert response.Should().NotBeNull(); await commandRepository.Received().Delete(Arg.Is <ulong>(a => a == 123)); }
public async Task <DeleteCommandResponse> Delete(DeleteCommandRequest request) { if (!await batchRepository.DoesBatchExist(request.BatchId)) { throw Err.BatchNotFound(request.BatchId); } var step = await stepRepository.Get(request.BatchId, request.StepName); if (step == null) { throw Err.StepNotFound(request.StepName); } var command = await commandRepository.Get(step.Id, request.CommandName); if (command == null) { throw Err.CommandNotFound(request.CommandName); } await commandRepository.Delete(command.Id); return(new DeleteCommandResponse()); }
/// <summary> /// 此接口用于删除命令。 /// </summary> /// <param name="req"><see cref="DeleteCommandRequest"/></param> /// <returns><see cref="DeleteCommandResponse"/></returns> public DeleteCommandResponse DeleteCommandSync(DeleteCommandRequest req) { JsonResponseModel <DeleteCommandResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "DeleteCommand"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <DeleteCommandResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
public void Delete_Command_Should_Throw_With_Invalid_Batch_Id() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(false); var request = new DeleteCommandRequest { BatchId = TestBatchId, }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Delete(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Batch TestBatch not found"); }
public void Delete_Command_Should_Throw_With_Invalid_Step_Name() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()) .ReturnsNull(); var request = new DeleteCommandRequest { StepName = TestStepName, }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Delete(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Step TestStep not found"); }