From 025b4aa04a6fd6379956818acd0252488da7ac28 Mon Sep 17 00:00:00 2001 From: marsen Date: Fri, 24 Nov 2023 17:14:07 +0800 Subject: [PATCH] Fix API endpoint in integration tests and add new test case for PalindromeNumber --- .../Kata/PickupService/PickUpService.http | 6 +- .../Kata/PickupService/PickupServiceTests.cs | 38 ++-- .../Kata/PickupService/Readme3.md | 212 +++++++++++++++++- .../PalindromeNumber/PalindromeNumberTests.cs | 7 + 4 files changed, 240 insertions(+), 23 deletions(-) diff --git a/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickUpService.http b/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickUpService.http index 1ae08ba4..edfa3d3f 100644 --- a/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickUpService.http +++ b/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickUpService.http @@ -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 = diff --git a/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickupServiceTests.cs b/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickupServiceTests.cs index 11be5c68..7d7745e7 100644 --- a/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickupServiceTests.cs +++ b/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/PickupServiceTests.cs @@ -16,14 +16,14 @@ public class PickupServiceTests private Dojo.Kata.PickupService.Services.PickupService _target; private const long TestStoreId = 1; private readonly List _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; @@ -40,14 +40,14 @@ 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); } @@ -55,7 +55,7 @@ public void Case2_Query_Shipping_waybillNo() [Fact] public void Case3_Query_FAIL_waybillNo() { - var actual = QueryWaybillNoWith(UrlMockFail); + var actual = QueryWaybillNoWith(MockFail); actual.Should().Be(Status.Abnormal); } @@ -63,14 +63,14 @@ public void Case3_Query_FAIL_waybillNo() [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); } @@ -78,17 +78,17 @@ public void Case5_Query_Arrived_waybillNo() [Fact] public void Case6_Query_Error_Result() { - GetPickupServiceWith(UrlMockResultError); + GetPickupServiceWith(MockResultError); Action act = () => _target.GetUpdateStatus(TestStoreId, _testWaybillNo); act.Should().Throw(); - _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(); } @@ -96,10 +96,10 @@ public void Case7_Query_Error_Content() [Fact] public void Case8_Query_Exception() { - GetPickupServiceWith(UrlMockException); + GetPickupServiceWith(MockException); Action act = () => _target.GetUpdateStatus(TestStoreId, _testWaybillNo); act.Should().Throw(); - _logger.ReceivedWithAnyArgs().LogError(default(string)); + _logger.ReceivedWithAnyArgs().LogError(default); } private void GetPickupServiceWith(string url) @@ -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; } } } \ No newline at end of file diff --git a/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/Readme3.md b/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/Readme3.md index 8a026cf1..7765b7f6 100644 --- a/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/Readme3.md +++ b/test/Marsen.NetCore.Dojo.Integration.Tests/Kata/PickupService/Readme3.md @@ -9,4 +9,214 @@ 必須來進行修正。 上一次用遺留代碼來開發,這次沒有代碼了,只剩遺留的測試。 -有趣! 讓我來試試看吧 \ No newline at end of file +有趣! 讓我來試試看吧 + +## 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": "john.doe@example.com", + "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": "john.doe@example.com", + "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": "john.doe@example.com", + "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": "john.doe@example.com", + "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": "john.doe@example.com", + "errorCode": null + } + ] +} +``` + + + +### Test Case Error +```json +{ + "result": "error", + "content": [] +} +``` +### Test Case Error Content + +```json +{ + "result": "success", + "content": [] +} +``` + +### Test Case Exception + +```json +Something Wrong + +``` + +(fin) diff --git a/test/Marsen.NetCore.Dojo.Tests/LeetCode/PalindromeNumber/PalindromeNumberTests.cs b/test/Marsen.NetCore.Dojo.Tests/LeetCode/PalindromeNumber/PalindromeNumberTests.cs index 8b335e6a..2d63df99 100644 --- a/test/Marsen.NetCore.Dojo.Tests/LeetCode/PalindromeNumber/PalindromeNumberTests.cs +++ b/test/Marsen.NetCore.Dojo.Tests/LeetCode/PalindromeNumber/PalindromeNumberTests.cs @@ -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)); + } } \ No newline at end of file