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: Instructions/Labs/LAB_AK_07_simplify_complex_conditionals.md
+42-24Lines changed: 42 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ Use the following steps to download the sample projects and open them in Visual
82
82
83
83
1. Open a browser window in your lab environment.
84
84
85
-
1. To download a zip file containing the sample app projects, paste the following URL into your browser's address bar: [GitHub Copilot lab - develop code features](https://github.com/MicrosoftLearning/mslearn-github-copilot-dev/raw/refs/heads/main/DownloadableCodeProjects/Downloads/GHCopilotEx7LabApps.zip)
85
+
1. To download a zip file containing the sample app projects, open the following URL in your browser: [GitHub Copilot lab - develop code features](https://github.com/MicrosoftLearning/mslearn-github-copilot-dev/raw/refs/heads/main/DownloadableCodeProjects/Downloads/GHCopilotEx7LabApps.zip)
86
86
87
87
The zip file is named **GHCopilotEx7LabApps.zip**.
88
88
@@ -96,33 +96,36 @@ Use the following steps to download the sample projects and open them in Visual
96
96
97
97
1. Select **Show extracted files when complete**, and then select **Extract**.
98
98
99
-
1. Open the extracted files folder, then copy the **ECommercePricingEngine** folder to a location that's easy to access, such as your Windows Desktop folder.
99
+
1. Copy the **GHCopilotEx7LabApps** folder to a location that's easy to access, such as your Windows Desktop folder.
100
100
101
-
1. Open the **ECommercePricingEngine** folder in Visual Studio Code.
101
+
1. Open the **GHCopilotEx7LabApps** folder in Visual Studio Code.
102
102
103
103
For example:
104
104
105
105
1. Open Visual Studio Code in your lab environment.
106
106
107
107
1. In Visual Studio Code, on the **File** menu, select**Open Folder**.
108
108
109
-
1. Navigate to the Windows Desktop folder, select **ECommercePricingEngine** and then select **Select Folder**.
109
+
1. Navigate to the Windows Desktop folder, select**GHCopilotEx7LabApps** and thenselect**Select Folder**.
110
110
111
111
1. In the Visual Studio Code SOLUTION EXPLORER view, verify the following solution structure:
112
112
113
-
- ECommercePricingEngine\
114
-
- ECommercePricingDemo.cs
115
-
- ECommercePricingEngine.csproj
116
-
- SecurityTest.cs
117
-
- LoanApprovalWorkflow\
118
-
- LoanApprovalDemo.cs
119
-
- LoanApprovalWorkflow.csproj
120
-
- SecurityTest.cs
113
+
- GHCopilotEx7LabApps\
114
+
- ECommercePricingEngine\
115
+
- Dependencies\
116
+
- ECommercePricingDemo.cs
117
+
- SecurityTest.cs
118
+
- LoanApprovalWorkflow\
119
+
- Dependencies\
120
+
- LoanApprovalDemo.cs
121
+
- SecurityTest.cs
121
122
122
-
1. Ensure that the solution builds successfully.
123
+
1. Ensure that the two code projects build successfully.
123
124
124
125
For example, in the SOLUTION EXPLORER view, right-click **ECommercePricingEngine**, and thenselect**Build**.
125
126
127
+
You'll see warnings "Cannot convert null literal to non-nullable reference type." when you build the ECommercePricingEngine project. You can ignore these warnings for the purposes of this exercise.
128
+
126
129
## Part 1: E-commerce pricing engine
127
130
128
131
In this section, you examine the E-commerce Pricing Engine sample app and use GitHub Copilot to refactor the conditional logic.
@@ -133,31 +136,46 @@ The first step in any refactoring effort is to understand the existing codebase.
133
136
134
137
Use the following steps to complete this task:
135
138
136
-
1. Open Visual Studio Code inyour lab environment.
139
+
1. Ensure that you have the GHCopilotEx7LabApps folder open inVisual Studio Code.
137
140
138
-
1. In Visual Studio Code, on the **File** menu, select**Open Folder**.
141
+
1. Open the GitHub Copilot Chat view.
139
142
140
-
1. Navigate to the project folder and selectthe**ECommercePricingEngine**folder.
143
+
If the Chat view is not already open, you can open it by selecting the **Chat**icon at the top of the Visual Studio Code window, just to the right of the Search textbox.
141
144
142
-
The ECommercePricingEngine folder is located at: `DownloadableCodeProjects\standalone-lab-projects\simplify-compex-conditionals\ECommercePricingEngine`
145
+
1. In the Chat view, ensure that the chat mode is set to **Ask** and the model is set to **GPT-4.1**.
143
146
144
-
1. In the EXPLORER view, expand the project structure and locate the **ECommercePricingDemo.cs** file.
147
+
The Ask mode allows you to interact with GitHub Copilot to ask questions and get explanations about the code. The GPT-4.1 model, which is included with the GitHub Copilot Free plan, provides advanced capabilities for understanding and generating code.
145
148
146
-
1. Open the **ECommercePricingDemo.cs** file.
149
+
You will be using Agent mode later in this exercise to perform more complex tasks, but for now, Ask mode is sufficient for code analysis and explanations.
147
150
148
-
This file contains the complex pricing logic that you'll be refactoring. Notice the deeply nested conditional statements in the `CalculateFinalPrice` method.
151
+
> [!NOTE]
152
+
> The selected model can affect the responses generated by GitHub Copilot. After completing the lab exercise using the recommended settings, you may want to repeat the exercise using different models to compare the results.
149
153
150
-
1. Select the entire `CalculateFinalPrice` method.
154
+
1. In Visual Studio Code, open the **ECommercePricingDemo.cs** file.
155
+
156
+
This file contains the complex pricing logic that you'll be refactoring. Notice the deeply nested conditional statements in the CalculateFinalPrice method.
157
+
158
+
1. Locate the **PricingEngine** class, and then select the entire **CalculateFinalPrice** method.
151
159
152
160
This method contains over 8 levels of nested conditional logic that evaluates membership levels, seasonal events, corporate accounts, subscription services, and various discount scenarios.
153
161
154
-
1. Right-click the selected code and select **Copilot** > **Explain This**.
162
+
1. Right-click the selected code, and then select **Copilot** > **Explain**.
155
163
156
164
GitHub Copilot will analyze the complex conditional logic and provide an explanation of what the code does, helping you understand the business rules before refactoring.
157
165
158
-
1. Take a minute to review GitHub Copilot's explanation.
166
+
1. Take a few minutes to review GitHub Copilot's explanation.
167
+
168
+
The explanation should highlight the main discount categories such as the hierarchical membership, coupon applications, bulk purchase incentives, and category-specific rules.
169
+
170
+
Understanding these business domains is crucial for creating effective helper methods to simplify the logic.
171
+
172
+
1. If time permits, in the Chat view, enter the following prompt to get a deeper analysis:
173
+
174
+
```plaintext
175
+
@workspace Explain the business logic flow in the CalculateFinalPrice method. What are the different discount paths and how do they interact with each other? What are the key business rules that govern pricing calculations?
176
+
```
159
177
160
-
The explanation should highlight the main discount categories: membership-based discounts, seasonal promotions, coupon applications, bulk purchase incentives, and category-specific rules. Understanding these business domains is crucial for creating effective helper methods.
178
+
This will help you understand how the different discount categories interact and what business rules are applied at each step of the pricing calculation.
161
179
162
180
### Task 2: Identify refactoring opportunities in the E-commerce pricing code
0 commit comments