You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DownloadableCodeProjects/standalone-lab-projects/refactor-large-functions/ECommerceOrderProcessing/src/ECommerce.ApplicationCore/Services/OrderProcessor.cs
+7-10Lines changed: 7 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
namespaceECommerce.ApplicationCore.Services;
5
5
6
6
/// <summary>
7
-
/// Main order processing service containing the large method that needs refactoring
7
+
/// Main order processing service
8
8
/// </summary>
9
9
publicclassOrderProcessor
10
10
{
@@ -32,9 +32,6 @@ public OrderProcessor(
32
32
}
33
33
34
34
/// <summary>
35
-
/// LARGE METHOD INTENTIONALLY KEPT FOR REFACTORING DEMONSTRATION
36
-
/// This method contains multiple responsibilities and should be refactored into smaller methods
37
-
///
38
35
/// Responsibilities include:
39
36
/// 1. Input Validation & Security Checks
40
37
/// 2. Inventory Management
@@ -52,7 +49,7 @@ public OrderResult ProcessOrder(Order order)
52
49
53
50
try
54
51
{
55
-
// Step 1: Comprehensive Input Validation and Security Checks
52
+
// Comprehensive Input Validation and Security Checks
56
53
if(order==null)
57
54
{
58
55
_auditLogger.LogSecurityEvent("NULL_ORDER_ATTEMPT","Attempted to process null order");
@@ -104,7 +101,7 @@ public OrderResult ProcessOrder(Order order)
104
101
Console.WriteLine($"Processing Order {order.Id} for {_securityValidator.MaskEmail(order.CustomerEmail)}...");
Copy file name to clipboardExpand all lines: DownloadableCodeProjects/standalone-lab-projects/refactor-large-functions/ECommerceOrderProcessing/src/ECommerce.Console/Program.cs
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ public static void Main(string[] args)
46
46
{
47
47
CardNumber="4111111111111111",
48
48
CardCVV="123",
49
-
CardHolderName="John Doe",
49
+
CardHolderName="Ane Pedersen",
50
50
ExpiryMonth="12",
51
51
ExpiryYear="2025",
52
52
BillingAddress="123 Main St, City, State 12345"
@@ -58,23 +58,23 @@ public static void Main(string[] args)
58
58
System.Console.WriteLine("\n--- Test Case 2: Invalid Email Address ---");
59
59
varinvalidEmailOrder=CreateSampleOrder("ORD-002","invalid-email","123 Main St",
newPaymentInfo{CardNumber="4111111111111111",CardCVV="123",CardHolderName="Jane Smith",ExpiryMonth="06",ExpiryYear="2026",BillingAddress="123 Main St"});
61
+
newPaymentInfo{CardNumber="4111111111111111",CardCVV="123",CardHolderName="Jennet Nazarowa",ExpiryMonth="06",ExpiryYear="2026",BillingAddress="123 Main St"});
newPaymentInfo{CardNumber="0000000000000000",CardCVV="999",CardHolderName="Test User",ExpiryMonth="01",ExpiryYear="2024",BillingAddress="456 Oak Ave"});
69
+
newPaymentInfo{CardNumber="0000000000000000",CardCVV="999",CardHolderName="Nikki Vestergaard",ExpiryMonth="01",ExpiryYear="2024",BillingAddress="456 Oak Ave"});
newPaymentInfo{CardNumber="4111111111111111",CardCVV="123",CardHolderName="AB",ExpiryMonth="12",ExpiryYear="2026",BillingAddress="123 Suspicious Ave, City, State 99999"});
Copy file name to clipboardExpand all lines: Instructions/Labs/LAB_AK_08_refactor_large_functions.md
+20-22Lines changed: 20 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,15 +86,21 @@ Use the following steps to download the sample project and open it in Visual Stu
86
86
87
87
1. Navigate to the Windows Desktop folder, select **GHCopilotEx8LabApps** and then select **Select Folder**.
88
88
89
-
1. In the Visual Studio Code SOLUTION EXPLORER view, verify the following solution structure:
89
+
1. In the Visual Studio Code SOLUTION EXPLORER view, verify the following project structure:
90
90
91
91
- GHCopilotEx8LabApps\
92
92
- ECommerceOrderProcessing\
93
93
- src\
94
94
- ECommerce.ApplicationCore\
95
-
- ECommerce.Infrastructure\
95
+
- Entities\
96
+
- Interfaces\
97
+
- Services\
96
98
- ECommerce.Console\
97
-
- ECommerceOrderProcessing.sln
99
+
- order_audit_log.txt
100
+
- Program.cs
101
+
- ECommerce.Infrastructure\
102
+
- Services\
103
+
- ServerLogAnalysisUtility\
98
104
99
105
## Exercise scenario
100
106
@@ -125,18 +131,12 @@ Use the following steps to complete this task:
125
131
126
132
The codebase follows a layered architecture pattern with three main projects:
127
133
128
-
- **ECommerce.ApplicationCore**: Contains domain entities, business logic interfaces, and the main `OrderProcessor` service
129
-
- **ECommerce.Infrastructure**: Contains service implementations for external integrations (payment, shipping, inventory, etc.)
134
+
- **ECommerce.ApplicationCore**: Contains domain entities, business logic interfaces, and the main `OrderProcessor` service.
130
135
- **ECommerce.Console**: Contains the console application entry point and dependency injection setup
136
+
- **ECommerce.Infrastructure**: Contains service implementations for external integrations (payment, shipping, inventory, etc.).
131
137
132
138
This structure represents a real-world .NET application using Clean Architecture principles, where business logic is separated from infrastructure concerns.
133
139
134
-
1. Verify that the **ECommerceOrderProcessing** solution builds successfully.
135
-
136
-
For example, in the SOLUTION EXPLORER view, right-click **ECommerceOrderProcessing.sln**, and thenselect**Build**.
137
-
138
-
You should see a successful build with no errors. This confirms that all project dependencies are properly configured.
139
-
140
140
1. Open the GitHub Copilot Chat view.
141
141
142
142
If the Chat view isn't already open, you can open it by selecting the **Chat** icon at the top of the Visual Studio Code window.
@@ -149,19 +149,13 @@ Use the following steps to complete this task:
149
149
150
150
1. In Visual Studio Code, navigate to **src/ECommerce.ApplicationCore/Services/OrderProcessor.cs**.
151
151
152
-
This file contains the `OrderProcessor` class with the large `ProcessOrder` method that you'll be refactoring. The method is over 200 lines long and handles multiple responsibilities including validation, security checks, inventory management, payment processing, shipping, notifications, and order finalization.
152
+
1. Open the OrderProcessor.cs file in the code editor.
153
153
154
-
1. Locate the **ProcessOrder** method in the **OrderProcessor** class.
154
+
The OrderProcessor.cs file provides the main order processing service for the app.
155
155
156
-
The `ProcessOrder` method represents the core business logic for processing customer orders. Notice that it handles multiple distinct operations:
156
+
1. Take a minute to review the **OrderProcessor** class.
157
157
158
-
- **Input validation and security checks**: Email validation, address validation, payment info validation, risk assessment
159
-
- **Inventory management**: Stock checking and reservation with rollback on failures
160
-
- **Payment processing**: Secure payment validation and processing with fraud detection
161
-
- **Shipping coordination**: Shipment scheduling and tracking number generation
162
-
- **Customer notifications**: Email confirmations and high-value order alerts
163
-
- **Order finalization**: Status updates, completion tracking, and audit logging
164
-
- **Error handling**: Comprehensive exception management with cleanup procedures
158
+
Notice the ProcessOrder method. This method represents the core business logic for processing customer orders. Notice that it handles multiple distinct operations.
165
159
166
160
The method is intentionally large and complex to demonstrate real-world scenarios where business logic has accumulated over time, making it difficult to read, test, and maintain.
167
161
@@ -175,7 +169,11 @@ Use the following steps to complete this task:
175
169
176
170
1. Run the application to understand its current behavior.
177
171
178
-
Navigate to the **src/ECommerce.Console** folder in the terminal and run:
172
+
For example:
173
+
174
+
In the SOLUTION EXPLORER view, right-click the **ECommerce.Console** project, select**Debug**, and thenselect**Start New Instance**.
175
+
176
+
You can also navigate to the **src/ECommerce.Console** folder in the terminal and run:
0 commit comments