public async Task PreparationAsync_requests_proper_uri() { // arrange var expectedRequest = new PaymentPreparation { Amount = 1000, TransactionId = Guid.NewGuid().ToString(), }; var expectedResult = new IamportResponse <PaymentPreparation> { HttpStatusCode = HttpStatusCode.OK, Content = new PaymentPreparation { TransactionId = expectedRequest.TransactionId, Amount = expectedRequest.Amount, } }; var expectedPath = $"payments/prepare"; var client = GetMockClient(expectedRequest, expectedResult); var sut = new PaymentsApi(client); // act var result = await sut.PrepareAsync(expectedRequest); // assert Mock.Get(client) .Verify(mocked => mocked.RequestAsync <PaymentPreparation, PaymentPreparation>( It.Is <IamportRequest <PaymentPreparation> >(req => req.ApiPathAndQueryString.EndsWith(expectedPath)))); }
public async Task PreparationAsync_throws_ValidationException(decimal amount, string transactionId) { // arrange var expectedRequest = new PaymentPreparation { Amount = amount, TransactionId = transactionId, }; var expectedResult = new IamportResponse <PaymentPreparation>(); var client = GetMockClient(expectedRequest, expectedResult); var sut = new PaymentsApi(client); // act/assert await Assert.ThrowsAsync <ValidationException>( () => sut.PrepareAsync(expectedRequest)); }
public async Task PreparationAsync_throws_IamportResponseException_when_response_code_is_not_success() { // arrange var expectedRequest = new PaymentPreparation { Amount = 1000, TransactionId = Guid.NewGuid().ToString(), }; var expectedResult = new IamportResponse <PaymentPreparation> { Code = -1, HttpStatusCode = HttpStatusCode.InternalServerError, }; var client = GetMockClient(expectedRequest, expectedResult); var sut = new PaymentsApi(client); // act/assert await Assert.ThrowsAsync <IamportResponseException>( () => sut.PrepareAsync(expectedRequest)); }
public async Task PrepareAsync_GuardClause() { var sut = new PaymentsApi(GetEmptyMockClient()); await Assert.ThrowsAsync <ArgumentNullException>( () => sut.PrepareAsync(null)); }