ProcessPayment()
BDDとmspecを介して開発しているというメソッドがあります。新しい挑戦に助けが必要です。私のユーザーストーリーは次のように述べています。
Given a payment processing context,
When payment is processed with valid payment information,
Then it should return a successful gateway response code.
コンテキストをセットアップするために、Moq を使用してゲートウェイ サービスをスタブ化しています。
_mockGatewayService = Mock<IGatewayService>();
_mockGatewayService.Setup(x => x.Process(Moq.It.IsAny<PaymentInfo>()).Returns(100);
仕様は次のとおりです。
public class when_payment_is_processed_with_valid_information {
static WebService _webService;
static int _responseCode;
static Mock<IGatewayService> _mockGatewayService;
static PaymentProcessingRequest _paymentProcessingRequest;
Establish a_payment_processing_context = () => {
_mockGatewayService = Mock<IGatewayService>();
_mockGatewayService
.Setup(x => x.Process(Moq.It.IsAny<PaymentInfo>())
.Returns(100);
_webService = new WebService(_mockGatewayService.Object);
_paymentProcessingRequest = new PaymentProcessingRequest();
};
Because payment_is_processed_with_valid_payment_information = () =>
_responseCode = _webService.ProcessPayment(_paymentProcessingRequest);
It should_return_a_successful_gateway_response_code = () =>
_responseCode.ShouldEqual(100);
It should_hit_the_gateway_to_process_the_payment = () =>
_mockGatewayService.Verify(x => x.Process(Moq.It.IsAny<PaymentInfo>());
}
メソッドは「PaymentProcessingRequest」オブジェクト (ドメイン obj ではない) を受け取り、その obj をドメイン obj にマップし、ドメイン obj をゲートウェイ サービスのスタブ メソッドに渡す必要があります。ゲートウェイ サービスからの応答は、メソッドによって返されるものです。ただし、ゲートウェイ サービス メソッドをスタブ化しているため、何が渡されても問題ありません。その結果、メソッドがリクエスト オブジェクトをドメイン オブジェクトに適切にマップするかどうかをテストする方法がないようです。
ここで BDD を遵守できるのはいつですか?