Skip to content

Commit

Permalink
Fix API endpoint in integration tests and add new
Browse files Browse the repository at this point in the history
test case for PalindromeNumber
  • Loading branch information
marsen committed Nov 24, 2023
1 parent 358cec9 commit 025b4aa
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@Prod https://pickup/service/
@Sandbox http://sandbox/service/
@host = @Sandbox
# @Prod https://pickup/service/
# @Sandbox http://sandbox/service/
@host = http://sandbox/service/

@loginId = apitest
@auth =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class PickupServiceTests
private Dojo.Kata.PickupService.Services.PickupService _target;
private const long TestStoreId = 1;
private readonly List<string> _testWaybillNo = new() {"TEST2002181800010"};
private const string UrlMockDone = "http://www.mocky.io/v2/5e4e56832f0000f55116a60b";
private const string UrlMockShipping = "http://www.mocky.io/v2/5e5284962d0000f622357b3f";
private const string UrlMockFail = "http://www.mocky.io/v2/5e5290812d0000261d357b5c";
private const string UrlMockExpiry = "http://www.mocky.io/v2/5e5292462d00004c00357b5e";
private const string UrlMockArrived = "http://www.mocky.io/v2/5e5293ff2d0000dd36357b61";
private const string UrlMockResultError = "http://www.mocky.io/v2/5e5bb89b3000004c00f9f29f";
private const string UrlMockContentError = "http://www.mocky.io/v2/5e5c83cd3200006d0043c197";
private const string UrlMockException = "https://www.mocky.io/v2/5e5cad1b320000530043c260";
private const string MockDone = "https://demo3287250.mockable.io/DONE";
private const string MockShipping = "https://demo3287250.mockable.io/Shipping";
private const string MockFail = "https://demo3287250.mockable.io/FAIL";
private const string MockExpiry = "https://demo3287250.mockable.io/Expiry";
private const string MockArrived = "https://demo3287250.mockable.io/Arrived";
private const string MockResultError = "https://demo3287250.mockable.io/Error";
private const string MockContentError = "https://demo3287250.mockable.io/ContentError";
private const string MockException = "https://demo3287250.mockable.io/Exception";
private readonly IStoreSettingService _storeSettingService;
private readonly ILogger _logger;

Expand All @@ -40,66 +40,66 @@ public PickupServiceTests()
[Fact]
public void Case1_Query_Done_waybillNo()
{
var actual = QueryWaybillNoWith(UrlMockDone);
var actual = QueryWaybillNoWith(MockDone);
actual.Should().Be(Status.Finish);
}

[Fact]
public void Case2_Query_Shipping_waybillNo()
{
var actual = QueryWaybillNoWith(UrlMockShipping);
var actual = QueryWaybillNoWith(MockShipping);
actual.Should().Be(Status.Processing);
}


[Fact]
public void Case3_Query_FAIL_waybillNo()
{
var actual = QueryWaybillNoWith(UrlMockFail);
var actual = QueryWaybillNoWith(MockFail);
actual.Should().Be(Status.Abnormal);
}


[Fact]
public void Case4_Query_Expiry_waybillNo()
{
var actual = QueryWaybillNoWith(UrlMockExpiry);
var actual = QueryWaybillNoWith(MockExpiry);
actual.Should().Be(Status.Abnormal);
}

[Fact]
public void Case5_Query_Arrived_waybillNo()
{
var actual = QueryWaybillNoWith(UrlMockArrived);
var actual = QueryWaybillNoWith(MockArrived);
actual.Should().Be(Status.Arrived);
}


[Fact]
public void Case6_Query_Error_Result()
{
GetPickupServiceWith(UrlMockResultError);
GetPickupServiceWith(MockResultError);
Action act = () => _target.GetUpdateStatus(TestStoreId, _testWaybillNo);
act.Should().Throw<Exception>();
_logger.ReceivedWithAnyArgs().LogError(default(string));
_logger.ReceivedWithAnyArgs().LogError(default);
}


[Fact]
public void Case7_Query_Error_Content()
{
GetPickupServiceWith(UrlMockContentError);
GetPickupServiceWith(MockContentError);
var actual = _target.GetUpdateStatus(TestStoreId, _testWaybillNo);
actual.Should().BeEmpty();
}

[Fact]
public void Case8_Query_Exception()
{
GetPickupServiceWith(UrlMockException);
GetPickupServiceWith(MockException);
Action act = () => _target.GetUpdateStatus(TestStoreId, _testWaybillNo);
act.Should().Throw<Exception>();
_logger.ReceivedWithAnyArgs().LogError(default(string));
_logger.ReceivedWithAnyArgs().LogError(default);
}

private void GetPickupServiceWith(string url)
Expand All @@ -115,7 +115,7 @@ private void GetPickupServiceWith(string url)
private Status? QueryWaybillNoWith(string url)
{
GetPickupServiceWith(url);
return _target.GetUpdateStatus(TestStoreId, _testWaybillNo).FirstOrDefault().Status;
return _target.GetUpdateStatus(TestStoreId, _testWaybillNo).FirstOrDefault()?.Status;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,214 @@
必須來進行修正。

上一次用遺留代碼來開發,這次沒有代碼了,只剩遺留的測試。
有趣! 讓我來試試看吧
有趣! 讓我來試試看吧

## Mock API

### Test case DONE

```json
{
"result": "success",
"content": [
{
"merchantId": "123",
"merchantRef": "ABC123",
"waybillNo": "W123456",
"locationId": "456",
"pudoRef": "PUDO789",
"pudoVerifyCode": "1234",
"senderId": "Sender123",
"consigneeId": "Consignee456",
"customerName": "John Doe",
"customerAddress1": "123 Main St",
"customerAddress2": "Apt 456",
"customerAddress3": "Suburb",
"customerAddress4": "City",
"feedbackURL": "https://example.com/feedback",
"eta": "2023-01-01",
"codAmt": "50.00",
"sizeCode": "L",
"lastStatusId": "DONE",
"lastStatusDescription": "Delivered to Customer",
"lastStatusDate": "2023-01-01",
"lastStatusTime": "12:34:56",
"customerMobile": "1234567890",
"customerEmail": "[email protected]",
"errorCode": null
}
]
}

```

### Test case Shipping

```json
{
"result": "success",
"content": [
{
"merchantId": "123",
"merchantRef": "ABC123",
"waybillNo": "W123456",
"locationId": "456",
"pudoRef": "PUDO789",
"pudoVerifyCode": "1234",
"senderId": "Sender123",
"consigneeId": "Consignee456",
"customerName": "John Doe",
"customerAddress1": "123 Main St",
"customerAddress2": "Apt 456",
"customerAddress3": "Suburb",
"customerAddress4": "City",
"feedbackURL": "https://example.com/feedback",
"eta": "2023-01-01",
"codAmt": "50.00",
"sizeCode": "L",
"lastStatusId": "Shipping",
"lastStatusDescription": "Delivered to Customer",
"lastStatusDate": "2023-01-01",
"lastStatusTime": "12:34:56",
"customerMobile": "1234567890",
"customerEmail": "[email protected]",
"errorCode": null
}
]
}
```

### Test case FAIL

```json
{
"result": "success",
"content": [
{
"merchantId": "123",
"merchantRef": "ABC123",
"waybillNo": "W123456",
"locationId": "456",
"pudoRef": "PUDO789",
"pudoVerifyCode": "1234",
"senderId": "Sender123",
"consigneeId": "Consignee456",
"customerName": "John Doe",
"customerAddress1": "123 Main St",
"customerAddress2": "Apt 456",
"customerAddress3": "Suburb",
"customerAddress4": "City",
"feedbackURL": "https://example.com/feedback",
"eta": "2023-01-01",
"codAmt": "50.00",
"sizeCode": "L",
"lastStatusId": "FAIL",
"lastStatusDescription": "Delivered to Customer",
"lastStatusDate": "2023-01-01",
"lastStatusTime": "12:34:56",
"customerMobile": "1234567890",
"customerEmail": "[email protected]",
"errorCode": null
}
]
}
```

### Test Case Expiry

```json
{
"result": "success",
"content": [
{
"merchantId": "123",
"merchantRef": "ABC123",
"waybillNo": "W123456",
"locationId": "456",
"pudoRef": "PUDO789",
"pudoVerifyCode": "1234",
"senderId": "Sender123",
"consigneeId": "Consignee456",
"customerName": "John Doe",
"customerAddress1": "123 Main St",
"customerAddress2": "Apt 456",
"customerAddress3": "Suburb",
"customerAddress4": "City",
"feedbackURL": "https://example.com/feedback",
"eta": "2023-01-01",
"codAmt": "50.00",
"sizeCode": "L",
"lastStatusId": "Expiry",
"lastStatusDescription": "Delivered to Customer",
"lastStatusDate": "2023-01-01",
"lastStatusTime": "12:34:56",
"customerMobile": "1234567890",
"customerEmail": "[email protected]",
"errorCode": null
}
]
}
```

### Test Case Arrived

```json
{
"result": "success",
"content": [
{
"merchantId": "123",
"merchantRef": "ABC123",
"waybillNo": "W123456",
"locationId": "456",
"pudoRef": "PUDO789",
"pudoVerifyCode": "1234",
"senderId": "Sender123",
"consigneeId": "Consignee456",
"customerName": "John Doe",
"customerAddress1": "123 Main St",
"customerAddress2": "Apt 456",
"customerAddress3": "Suburb",
"customerAddress4": "City",
"feedbackURL": "https://example.com/feedback",
"eta": "2023-01-01",
"codAmt": "50.00",
"sizeCode": "L",
"lastStatusId": "Arrived",
"lastStatusDescription": "Delivered to Customer",
"lastStatusDate": "2023-01-01",
"lastStatusTime": "12:34:56",
"customerMobile": "1234567890",
"customerEmail": "[email protected]",
"errorCode": null
}
]
}
```



### Test Case Error
```json
{
"result": "error",
"content": []
}
```
### Test Case Error Content

```json
{
"result": "success",
"content": []
}
```

### Test Case Exception

```json
Something Wrong

```

(fin)
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ public void Give_N_1_Should_Be_False()
// Arrange, Act, Assert
Assert.False(_sol.IsPalindrome(-1));
}

[Fact]
public void Give_121_Should_Be_True()
{
// Arrange, Act, Assert
Assert.True(_sol.IsPalindrome(121));
}
}

0 comments on commit 025b4aa

Please sign in to comment.