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: 06-Using-GitHub-Copilot-with-CSharp/README.md
+21-12
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ The running application in a browser should be like this one.
67
67
68
68

69
69
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`.
71
71
72
72
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.
73
73
@@ -77,6 +77,8 @@ Pressing F10 we can debug step-by-step until line 32, where we can see the gener
77
77
78
78

79
79
80
+
You can stop debugging now.
81
+
80
82
81
83
Congratulations! Now you are ready to add more features into the app using GitHub Copilot.
82
84
@@ -106,8 +108,12 @@ Let's use the `/tests` command to generate tests to the code. Select lines 39-42
106
108
107
109

108
110
111
+
At this point, GitHub Copilot will suggest a new class. You need to first press [Create] to create the new file.
112
+
109
113
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`.
110
114
115
+
***Important:** We are not going to use the test file in this project. You must delete the generated test file to continue.*
116
+
111
117
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.
112
118
113
119

@@ -124,40 +130,43 @@ Go to the `Program.cs` file in the BackEnd project. The file is in the following
124
130
Navigate to the end of the file and ask Copilot to generate a new record that includes the name of the city.
125
131
126
132
```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
129
134
```
130
135
131
136
The generated code sould be similar to this one:
132
137
133
138
```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
You can take a look at the prompt working in the next animation:
147
+
148
+

149
+
141
150
### 🔎 Step 2: Generate a new endpoint to get the weather forecast for a city
142
151
143
152
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`**.
144
153
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
+
145
156
Next, generate a new endpoint with GitHub Copilot by adding the comment:
146
157
147
158
```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
149
160
```
161
+
In the following example, we added some extra blank lines after the previous endpoint and then GitHub Copilot generated the new endpoint.
150
162
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
-

163
+

154
164
155
165
The generated code should look similar to this one:
156
166
157
167
```csharp
158
-
// Create a new endpoint named /weatherforecastbycity/{city}
159
-
// the endpoing accepts a city name and generates a random forecast for that city
// 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
0 commit comments