public void Create_BatchVariable_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

            var request = new CreateBatchVariableRequest
            {
                BatchId = TestBatchId
            };

            // Act / Assert
            var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request));

            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString());
            exception.Message.Should().Be("Batch TestBatch not found");
        }
Esempio n. 2
0
        public async Task <CreateBatchVariableResponse> Post(CreateBatchVariableRequest request)
        {
            if (!await batchRepository.DoesBatchExist(request.BatchId))
            {
                throw Err.BatchNotFound(request.BatchId);
            }

            if (await batchRepository.DoesBatchVariableExist(request.BatchId, request.VariableName))
            {
                throw Err.BatchVariableAlreadyExists(request.VariableName);
            }

            var batchVariable = request.ConvertTo <BatchVariable>();

            await batchRepository.CreateOrUpdateBatchVariable(batchVariable);

            return(new CreateBatchVariableResponse());
        }
        public void Create_BatchVariable_Should_Throw_With_Existing_Variable_Name()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(true);
            batchRepository.DoesBatchVariableExist(Arg.Any <string>(), Arg.Any <string>())
            .Returns(true);

            var request = new CreateBatchVariableRequest
            {
                VariableName = TestBatchVariableName
            };

            // Act / Assert
            var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request));

            exception.ErrorCode.Should().Be(HttpStatusCode.Conflict.ToString());
            exception.Message.Should().Be("Batch Variable TestBatchVariable already exists");
        }