public async Task It_Should_Delete_Batch_Variable()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(true);

            var existingBatchVariable = new BatchVariable
            {
                Id = 123
            };

            batchRepository.GetBatchVariable(Arg.Any <string>(), Arg.Any <string>())
            .Returns(existingBatchVariable);

            batchRepository.DeleteBatchVariable(Arg.Any <ulong>()).Returns(true);

            var request = new DeleteBatchVariableRequest();

            // Act
            var response = await Sut.Delete(request);

            // Assert
            response.Should().NotBeNull();
            await batchRepository.Received().DeleteBatchVariable(Arg.Is <ulong>(a =>
                                                                                a == existingBatchVariable.Id));
        }
        public void Delete_Batch_Variable_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

            var request = new DeleteBatchVariableRequest
            {
                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");
        }
Exemple #3
0
        public async Task <DeleteBatchVariableResponse> Delete(DeleteBatchVariableRequest request)
        {
            if (!await batchRepository.DoesBatchExist(request.BatchId))
            {
                throw Err.BatchNotFound(request.BatchId);
            }

            var existingBatchVariable =
                await batchRepository.GetBatchVariable(request.BatchId, request.VariableName);

            if (existingBatchVariable == null)
            {
                throw Err.BatchVariableNotFound(request.VariableName);
            }

            await batchRepository.DeleteBatchVariable(existingBatchVariable.Id);

            return(new DeleteBatchVariableResponse());
        }