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_03_develop_code_features.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,8 +215,8 @@ To implement the book availability feature, you'll need to complete the followin
215
215
- The **SearchBooks** method should read a user provided book title.
216
216
- Check if a book is available for loan, and display a message stating either:
217
217
218
-
- "`book.title` is available for loan", or
219
-
- "`book.title` is on loan to another patron. The return due date is `loan.DueDate`."
218
+
- "**book.title** is available for loan", or
219
+
- "**book.title** is on loan to another patron. The return due date is **loan.DueDate**."
220
220
221
221
GitHub Copilot Chat can help you implement the code updates needed to complete the new feature.
222
222
@@ -473,8 +473,8 @@ Use the following steps to complete this section of the exercise:
473
473
1. Check if a book is available for loan.
474
474
1. Display a message stating one of the following options:
475
475
476
-
- "`book.title` is available for loan"
477
-
- "`book.title` is on loan to another patron. The return due date is `loan.DueDate`."
476
+
- "**{book.title}** is available for loan"
477
+
- "**{book.title}** is on loan to another patron. The return due date is **{loan.DueDate}**."
478
478
479
479
To build the message options, your code will need to access the following JSON files:
480
480
@@ -495,7 +495,7 @@ Use the following steps to complete this section of the exercise:
495
495
496
496
>**NOTE**: Be sure to remove any code comments created by GitHub Copilot. Unnecessary and inaccurate comments can negatively influence GitHub Copilot's suggestions.
497
497
498
-
1. Select the `SearchBooks` method.
498
+
1. Select the **SearchBooks** method.
499
499
500
500
1. Open the Chat view and then enter the following prompt:
Copy file name to clipboardExpand all lines: Instructions/Labs/LAB_AK_04_develop_unit_tests_xunit.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -261,15 +261,15 @@ Use the following steps to complete this section of the exercise:
261
261
262
262
2. Identify methods to test:
263
263
264
-
- Identify the methods in the `Library.Infrastructure` project that need to be tested. For example, if you want to test the `LoanService` class, identify the methods in the `LoanService` class that need to be tested.
264
+
- Identify the methods in the **Library.Infrastructure** project that need to be tested. For example, if you want to test the **LoanService** class, identify the methods in the **LoanService** class that need to be tested.
265
265
266
266
3. Create Test Classes:
267
267
268
-
- Create new test classes in the `tests/UnitTests` directory to test the methods in the `Library.Infrastructure` project. For example, if you want to test `LoanService`, create a file named `LoanServiceTests.cs`.
268
+
- Create new test classes in the **tests/UnitTests** directory to test the methods in the **Library.Infrastructure** project. For example, if you want to test **LoanService**, create a file named **LoanServiceTests.cs**.
269
269
270
270
4. Write Unit Tests:
271
271
272
-
- In the newly created test classes, write unit tests for the methods in the `Library.Infrastructure` project. Use the xUnit framework for writing tests and NSubstitute for mocking dependencies.
272
+
- In the newly created test classes, write unit tests for the methods in the **Library.Infrastructure** project. Use the xUnit framework for writing tests and NSubstitute for mocking dependencies.
273
273
274
274
5. Run Tests:
275
275
@@ -282,7 +282,7 @@ Use the following steps to complete this section of the exercise:
282
282
283
283
## Extend the UnitTests project to begin testing data access classes
284
284
285
-
The `Library.Infrastructure` project contains data access classes that interact with the file system to load and save data. The project includes the following classes:
285
+
The **Library.Infrastructure** project contains data access classes that interact with the file system to load and save data. The project includes the following classes:
286
286
287
287
- JsonData: A class that loads and saves JSON data.
288
288
- JsonLoanRepository: A class that implements the ILoanRepository interface and uses the JsonData class to load and save loan data.
@@ -333,19 +333,19 @@ Use the following steps to complete this section of the exercise:
333
333
334
334
When you select**Continue**, GitHub Copilot completes the following actions:
335
335
336
-
- Runs the mkdir commandin the terminal to create the `Infrastructure\JsonLoanRepository` folders in the UnitTests project.
337
-
- Creates a new file named `GetLoan.cs`in the `JsonLoanRepository` folder.
336
+
- Runs the mkdir commandin the terminal to create the **Infrastructure\JsonLoanRepository** folders in the UnitTests project.
337
+
- Creates a new file named **GetLoan.cs**in the **JsonLoanRepository** folder.
338
338
339
339
1. Take a moment to review the updates.
340
340
341
341
You should see the following updates in the editor:
342
342
343
-
- The `UnitTests` project now includes a reference to `Library.Infrastructure.csproj`.
344
-
- The `GetLoan.cs` file is created in the `Infrastructure\JsonLoanRepository` folder.
343
+
- The **UnitTests** project now includes a reference to **Library.Infrastructure.csproj**.
344
+
- The **GetLoan.cs** file is created in the **Infrastructure\JsonLoanRepository** folder.
345
345
346
346
1. In the Chat view, to accept all changes, select**Keep**.
347
347
348
-
1. In the SOLUTION EXPLORER view, expand the `Infrastructure\JsonLoanRepository` folder structure.
348
+
1. In the SOLUTION EXPLORER view, expand the **Infrastructure\JsonLoanRepository** folder structure.
349
349
350
350
The folder structure should look like this:
351
351
@@ -356,19 +356,19 @@ Use the following steps to complete this section of the exercise:
356
356
357
357
### Use the Edit mode to create unit tests for the GetLoan method
358
358
359
-
In this section of the exercise, you use GitHub Copilot's Edit mode to create unit tests for the `GetLoan` method in the `JsonLoanRepository` class.
359
+
In this section of the exercise, you use GitHub Copilot's Edit mode to create unit tests for the **GetLoan** method in the **JsonLoanRepository** class.
360
360
361
361
Use the following steps to complete this section of the exercise:
362
362
363
363
1. In the Chat view, select the **Set Mode** button, and then select **Edit**.
364
364
365
365
The Chat view is now in Edit mode.
366
366
367
-
1. Open the `JsonLoanRepository.cs` file.
367
+
1. Open the **JsonLoanRepository.cs** file.
368
368
369
-
`JsonLoanRepository.cs` is located in the `src/Library.Infrastructure/Data/` folder.
369
+
**JsonLoanRepository.cs** is located in the **src/Library.Infrastructure/Data/** folder.
370
370
371
-
1. Take a minute to review the `JsonLoanRepository.cs` file.
371
+
1. Take a minute to review the **JsonLoanRepository.cs** file.
372
372
373
373
```csharp
374
374
using Library.ApplicationCore;
@@ -428,22 +428,22 @@ Use the following steps to complete this section of the exercise:
428
428
}
429
429
```
430
430
431
-
1. Notice the following details about the `JsonLoanRepository` class:
431
+
1. Notice the following details about the **JsonLoanRepository** class:
432
432
433
-
- The `JsonLoanRepository` class contains two methods: `GetLoan` and `UpdateLoan`.
434
-
- The `JsonLoanRepository` class uses a `JsonData` object to load and save loan data.
433
+
- The **JsonLoanRepository** class contains two methods: **GetLoan** and **UpdateLoan**.
434
+
- The **JsonLoanRepository** class uses a **JsonData** object to load and save loan data.
435
435
436
-
1. Take a minute to consider the field and constructor requirements for the `GetLoan` test class.
436
+
1. Take a minute to consider the field and constructor requirements for the **GetLoan** test class.
437
437
438
-
The `JsonLoanRepository.GetLoan` method receives a loan ID parameter when it's called. The method uses `_jsonData.EnsureDataLoaded` to get the latest JSON data, and `_jsonData.Loans` to search for a matching loan. If the method finds a matching loan ID, it returns a populated loan object (`populated`). If the method is unable to find a matching loan ID, it returns `null`.
438
+
The **JsonLoanRepository.GetLoan** method receives a loan ID parameter when it's called. The method uses **_jsonData.EnsureDataLoaded** to get the latest JSON data, and **_jsonData.Loans** to search for a matching loan. If the method finds a matching loan ID, it returns a populated loan object (**populated**). If the method is unable to find a matching loan ID, it returns **null**.
439
439
440
440
For the GetLoan unit tests:
441
441
442
-
- You can use a mock loan repository object (`_mockLoanRepository`) to helptest the case where a matching ID is found. Load the mock with the ID you want to find. The `ReturnLoanTest` class demonstrates how to mock the `ILoanRepository` interface and instantiate a mock loan repository object.
442
+
- You can use a mock loan repository object (**_mockLoanRepository**) to helptest the case where a matching ID is found. Load the mock with the ID you want to find. The **ReturnLoanTest** class demonstrates how to mock the **ILoanRepository** interface and instantiate a mock loan repository object.
443
443
444
-
- You can use a non-mock loan repository object (`_jsonLoanRepository`) to test the case where no matching ID is found. Just specify a loan ID that you know isn't in the file (anything over 100 should work).
444
+
- You can use a non-mock loan repository object (**_jsonLoanRepository**) to test the case where no matching ID is found. Just specify a loan ID that you know isn't in the file (anything over 100 should work).
445
445
446
-
- You'll need a `JsonData` object to create a non-mock `JsonLoanRepository` object. Since the `UnitTests` project doesn't have access to the `JsonData` object created by the `ConsoleApp` project, you'll need to create one using the `IConfiguration` interface.
446
+
- You'll need a **JsonData** object to create a non-mock **JsonLoanRepository** object. Since the **UnitTests** project doesn't have access to the **JsonData** object created by the **ConsoleApp** project, you'll need to create one using the **IConfiguration** interface.
447
447
448
448
1. Open the GetLoan.cs test file and selectthe GetLoan class.
449
449
@@ -506,15 +506,15 @@ Use the following steps to complete this section of the exercise:
506
506
507
507
> **NOTE**: Sample code in the following step shows updates that correct the following issues:
508
508
509
-
- If there's a conflict between the `UnitTests.Infrastructure.JsonLoanRepository` namespace and the `JsonLoanRepository`type specified in the code, you should update the namespace in GetLoans.cs to eliminate the conflict. Follow the pattern used in the `ReturnLoan.cs` and `RenewMembership.cs` files.
509
+
- If there's a conflict between the **UnitTests.Infrastructure.JsonLoanRepository** namespace and the **JsonLoanRepository**type specified in the code, you should update the namespace in GetLoans.cs to eliminate the conflict. Follow the pattern used in the **ReturnLoan.cs** and **RenewMembership.cs** files.
510
510
511
-
- If `ILoanRepository` isn't recognized in your code, you may need to add a `using` directive for `Library.ApplicationCore` to the top of the file.
511
+
- If **ILoanRepository** isn't recognized in your code, you may need to add a **using** directive for **Library.ApplicationCore** to the top of the file.
512
512
513
-
- If the `_configuration` object isn't instantiated correctly, you may need to update the code line containing `ConfigurationBuilder`. You can simplify the code to use `_configuration = new ConfigurationBuilder().Build();`.
513
+
- If the **_configuration** object isn't instantiated correctly, you may need to update the code line containing **ConfigurationBuilder**. You can simplify the code to use **_configuration = new ConfigurationBuilder().Build();**.
514
514
515
-
- If a `using Library.ApplicationCore.Interfaces` is suggested by GitHub Copilot, you can delete it from the top of the file.
515
+
- If a **using Library.ApplicationCore.Interfaces** is suggested by GitHub Copilot, you can delete it from the top of the file.
516
516
517
-
1. Update the `GetLoan.cs` file to match the following code snippet:
517
+
1. Update the **GetLoan.cs** file to match the following code snippet:
518
518
519
519
```csharp
520
520
using NSubstitute;
@@ -552,13 +552,13 @@ Use the following steps to complete this section of the exercise:
552
552
- JsonData.cs
553
553
- Loans.json.
554
554
555
-
1. Select the contents of the `GetLoan.cs` file, and then enter the following prompt in the Chat view:
555
+
1. Select the contents of the **GetLoan.cs** file, and then enter the following prompt in the Chat view:
556
556
557
557
```plaintext
558
558
@workspace Update the selection to include a unit testforthe `JsonLoanRepository.GetLoan` method. The unit test should test the case where a loan ID is foundin the data. Use `_mockLoanRepository` to arrange the expected return loan. Use `_jsonLoanRepository` to return an actual loan. Asserts should verify that the return loan ID matches the expected loan ID. Use a loan ID that exists in the `Loans.json` file.
559
559
```
560
560
561
-
This prompt asks GitHub Copilot to suggest a unit testforthe `JsonLoanRepository.GetLoan` method. The unit test should test the case where a loan ID is foundin the data. The test should use `_mockLoanRepository` to arrange the expected return loan, `_jsonLoanRepository` to return an actual loan, and asserts to verify that the return loan ID matches the expected loan ID. The loan ID should exist in the `Loans.json` file.
561
+
This prompt asks GitHub Copilot to suggest a unit testforthe **JsonLoanRepository.GetLoan** method. The unit test should test the case where a loan ID is foundin the data. The test should use **_mockLoanRepository** to arrange the expected return loan, **_jsonLoanRepository** to return an actual loan, and asserts to verify that the return loan ID matches the expected loan ID. The loan ID should exist in the **Loans.json** file.
562
562
563
563
1. Take a minute to review the updates suggested by GitHub Copilot.
564
564
@@ -618,13 +618,13 @@ Use the following steps to complete this section of the exercise:
618
618
619
619
1. In the Chat view, to accept all updates, select **Keep**.
620
620
621
-
If the `Loan` class isn't recognized in your code, ensure that you have a `using Library.ApplicationCore.Entities;` statement at the top of the GetLoan.cs file. The `Loan` class is located in the `Library.ApplicationCore.Entities` namespace.
621
+
If the **Loan** class isn't recognized in your code, ensure that you have a **using Library.ApplicationCore.Entities;** statement at the top of the GetLoan.cs file. The **Loan** class is located in the **Library.ApplicationCore.Entities** namespace.
622
622
623
-
1. Build the `AccelerateDevGitHubCopilot` solution to ensure there are no errors.
623
+
1. Build the **AccelerateDevGitHubCopilot** solution to ensure there are no errors.
624
624
625
625
1. Use GitHub Copilot's autocompletion feature to create a test for the case where the loan ID isn't found.
626
626
627
-
Create a blank line after the `GetLoan_ReturnsLoanWhenLoanIdIsFound` method.
627
+
Create a blank line after the **GetLoan_ReturnsLoanWhenLoanIdIsFound** method.
628
628
629
629
Accept the autocompletion suggestions to create a new test method.
630
630
@@ -673,17 +673,17 @@ Use the following steps to complete this section of the exercise:
673
673
674
674
```
675
675
676
-
You can delete the code that mocks an expected loan, but you need a loan ID that doesn't exist in the `Loans.json` file.
676
+
You can delete the code that mocks an expected loan, but you need a loan ID that doesn't exist in the **Loans.json** file.
677
677
678
-
Ensure that your "Returns null when loan ID is not found" unit test assigns a `loanId` value that isn't in the data set.
678
+
Ensure that your "Returns null when loan ID is not found" unit test assigns a **loanId** value that isn't in the data set.
679
679
680
680
1. Notice that the unit tests require access to the JSON data files.
681
681
682
-
The `JsonLoanRepository.GetLoan` method uses a `JsonData` object to load and save loan data.
682
+
The **JsonLoanRepository.GetLoan** method uses a **JsonData** object to load and save loan data.
683
683
684
-
The JSON data files are located in the `Library.Console\Json` folder. You need to update the `UnitTests.csproj` file to include these files in the test project.
684
+
The JSON data files are located in the **Library.Console\Json** folder. You need to update the **UnitTests.csproj** file to include these files in the test project.
685
685
686
-
1. Add the following XML snippet to the `UnitTests.csproj` file:
686
+
1. Add the following XML snippet to the **UnitTests.csproj** file:
687
687
688
688
```xml
689
689
<ItemGroup>
@@ -698,7 +698,7 @@ Use the following steps to complete this section of the exercise:
698
698
699
699
## Run the unit tests
700
700
701
-
There are several ways to run the unit tests for the `JsonLoanRepository` class. You can use Visual Studio Code's Test Explorer, the integrated terminal, or the `dotnet test` command.
701
+
There are several ways to run the unit tests for the **JsonLoanRepository** class. You can use Visual Studio Code's Test Explorer, the integrated terminal, or the **dotnet test** command.
702
702
703
703
Use the following steps to complete this section of the exercise:
704
704
@@ -716,7 +716,7 @@ Use the following steps to complete this section of the exercise:
716
716
717
717
The Test Explorer is a tree view that shows all the test cases in your workspace. You can run/debug your test cases and view the test results using Test Explorer.
718
718
719
-
1. Expand **UnitTests** and the underlying nodes to locate `GetLoanTest`.
719
+
1. Expand **UnitTests** and the underlying nodes to locate **GetLoanTest**.
720
720
721
721
1. Run the **JsonLoanRepository.GetLoan: Returns loan when loan ID is found** test case.
0 commit comments