Skip to content

Commit ec715ad

Browse files
committed
- add new suggestions to make the 06 more clear
- include new animations for better code generation and debugging
1 parent 4ecca65 commit ec715ad

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed
Loading
Loading
Binary file not shown.

06-Using-GitHub-Copilot-with-CSharp/README.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The running application in a browser should be like this one.
6767

6868
![test the running application.](./008TestRunningApi.png)
6969

70-
Now let's add a breaking point into our application, to debug each call to the API. Go to the `Program.cs` file in the BackEnd project. The file is in the following path `SampleApp\BackEnd\Program.cs`.
70+
Now let's add a break point into our application, to debug each call to the API. Go to the `Program.cs` file in the BackEnd project. The file is in the following path `SampleApp\BackEnd\Program.cs`.
7171

7272
Add a breakpoint in line 24 (press F9) and refresh the browser with the Url to test the endpoint. The browser should not show the weather forecast, and in the Visual Studio Editor we can see how the program execution was paused at line 24.
7373

@@ -77,6 +77,8 @@ Pressing F10 we can debug step-by-step until line 32, where we can see the gener
7777

7878
![debug the running application.](./010DebugForecastValue.png)
7979

80+
You can stop debugging now.
81+
8082

8183
Congratulations! Now you are ready to add more features into the app using GitHub Copilot.
8284

@@ -106,8 +108,12 @@ Let's use the `/tests` command to generate tests to the code. Select lines 39-42
106108

107109
![Use slash command to generate tests for the selected piece of code](./012SlashCmdTests.gif)
108110

111+
At this point, GitHub Copilot will suggest a new class. You need to first press [Create] to create the new file.
112+
109113
A new class `ProgramTests.cs` was created and added to the project. This tests are using XUnit, however, you can ask to generate tests using another Unit Test library with a command like this one `/tests use MSTests for unit testing`.
110114

115+
***Important:** We are not going to use the test file in this project. You must delete the generated test file to continue.*
116+
111117
Finally, let's use the `/doc` to generate automatic documentation to the code. Select lines 39-42, press `CTRL + I` to open the inline chat, and type `/doc` (or select the command) to generate the documentation for this record.
112118

113119
![Use slash command to generate the documentation for a piece of code](./013SlashCmdDoc.gif)
@@ -124,40 +130,43 @@ Go to the `Program.cs` file in the BackEnd project. The file is in the following
124130
Navigate to the end of the file and ask Copilot to generate a new record that includes the name of the city.
125131

126132
```csharp
127-
// internal record WeatherForecastByCity that request the following parameters:
128-
// City, Date, TemperatureC, Summary
133+
// create a new internal record named WeatherForecastByCity that request the following parameters: City, Date, TemperatureC, Summary
129134
```
130135

131136
The generated code sould be similar to this one:
132137

133138
```csharp
134-
// internal record WeatherForecastByCity that request the following parameters:
135-
// City, Date, TemperatureC, Summary
139+
// create a new internal record named WeatherForecastByCity that request the following parameters: City, Date, TemperatureC, Summary
136140
internal record WeatherForecastByCity(string City, DateOnly Date, int TemperatureC, string? Summary)
137141
{
138142
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
139143
}
140144
```
145+
146+
You can take a look at the prompt working in the next animation:
147+
148+
![open program.cs in the BackEnd project](./014AddNewRecord.gif)
149+
141150
### 🔎 Step 2: Generate a new endpoint to get the weather forecast for a city
142151

143152
Now let's generate a new API endpoint similar to `/weatherforecast` that also includes the city name. The new API endpoint name will be **`/weatherforecastbycity`**.
144153

154+
***Important:** You must place the code after the '.WithOpenApi();' line, this starts in line 36. Also remember to press TAB in each new suggested line until the whole endpoint is defined.*
155+
145156
Next, generate a new endpoint with GitHub Copilot by adding the comment:
146157

147158
```csharp
148-
// Create a new endpoint named /WeatherForecastByCity that accepts a city name and generates a random forecast for that city
159+
// Create a new endpoint named /WeatherForecastByCity/{city}, that accepts a city name in the urls as a paremeter and generates a random forecast for that city
149160
```
161+
In the following example, we added some extra blank lines after the previous endpoint and then GitHub Copilot generated the new endpoint.
150162

151-
***Important:** You must place the code in line 36, after the '.WithOpenApi();' line. Also remember to press TAB in each new suggested line until the whole endpoint is defined.*
152-
153-
![Copilot ghost suggestion for the new endpoint](./020GeneratedCode.png)
163+
![Copilot ghost suggestion for the new endpoint](./020GeneratedCode.gif)
154164

155165
The generated code should look similar to this one:
156166

157167
```csharp
158-
// Create a new endpoint named /weatherforecastbycity/{city}
159-
// the endpoing accepts a city name and generates a random forecast for that city
160-
app.MapGet("/weatherforecastbycity/{city}", (string city) =>
168+
// Create a new endpoint named /WeatherForecastByCity/{city}, that accepts a city name in the urls as a paremeter and generates a random forecast for that city
169+
app.MapGet("/WeatherForecastByCity/{city}", (string city) =>
161170
{
162171
var forecast = new WeatherForecastByCity
163172
(

0 commit comments

Comments
 (0)