Skip to content

Commit 22b440f

Browse files
committed
fix(ch11): Resolve cart initialization bug, stabilize configuration tests, and update Key Vault setup
- Fixed a null reference issue in RefreshShoppingCart() by returning early when the user context is not yet available during first sign-in - Updated database initialization script to retrieve the connection string from Azure Key Vault - Updated README to reflect the new Key Vault–based initialization process - Added .gitignore files to solutions that were missing them - Excluded the script-generated tenant configuration file from source control - Refactored configuration integration tests to avoid relying on real application settings - Replaced Guid.NewGuid() with fixed GUIDs in EF Core seed data where required, since EF cannot translate Guid.NewGuid() during migrations These changes improve reliability of the sample application, align the database setup with the Key Vault security model introduced in Chapter 11 and later chapters, and ensure tests remain stable as configuration evolves.
1 parent 686ee42 commit 22b440f

34 files changed

Lines changed: 2858 additions & 407 deletions

File tree

ch09/CleanCart.NET/src/Infrastructure/Persistence/EntityFramework/ProductConfiguration.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,71 +18,71 @@ public void Configure(EntityTypeBuilder<Product> builder)
1818
builder.HasData(
1919
new Product
2020
{
21-
Id = new Guid("f0ae6d4f-a312-4a81-830d-ea0c16131326"),
21+
Id = Guid.Parse("f0ae6d4f-a312-4a81-830d-ea0c16131326"),
2222
Name = "Wireless Mouse",
2323
Price = 29.99m,
2424
StockLevel = 150,
2525
ImageUrl = "https://placehold.co/200?text=Wireless+Mouse"
2626
},
2727
new Product
2828
{
29-
Id = new Guid("543b49a3-2daa-46b3-8498-004322f86f41"),
29+
Id = Guid.Parse("543b49a3-2daa-46b3-8498-004322f86f41"),
3030
Name = "Mechanical Keyboard",
3131
Price = 89.99m,
3232
StockLevel = 75,
3333
ImageUrl = "https://placehold.co/200?text=Mechanical+Keyboard"
3434
},
3535
new Product
3636
{
37-
Id = new Guid("875d83af-a771-4c8b-97e7-c62f2d54b19b"),
37+
Id = Guid.Parse("875d83af-a771-4c8b-97e7-c62f2d54b19b"),
3838
Name = "27-inch Monitor",
3939
Price = 199.99m,
4040
StockLevel = 45,
4141
ImageUrl = "https://placehold.co/200?text=27-inch+Monitor"
4242
},
4343
new Product
4444
{
45-
Id = new Guid("8e8e3c26-2f5a-4ce8-a274-cdc9c83d0b12"),
45+
Id = Guid.Parse("8e8e3c26-2f5a-4ce8-a274-cdc9c83d0b12"),
4646
Name = "USB-C Hub",
4747
Price = 49.99m,
4848
StockLevel = 200,
4949
ImageUrl = "https://placehold.co/200?text=USB-C+Hub"
5050
},
5151
new Product
5252
{
53-
Id = new Guid("ce1bb70b-8faf-4fb5-bac3-8ae488a95beb"),
53+
Id = Guid.Parse("ce1bb70b-8faf-4fb5-bac3-8ae488a95beb"),
5454
Name = "Noise Cancelling Headphones",
5555
Price = 129.99m,
5656
StockLevel = 30,
5757
ImageUrl = "https://placehold.co/200?text=Noise+Cancelling+Headphones"
5858
},
5959
new Product
6060
{
61-
Id = new Guid("91b4da28-d060-43ea-861a-ceb8783ef880"),
61+
Id = Guid.Parse("91b4da28-d060-43ea-861a-ceb8783ef880"),
6262
Name = "Webcam",
6363
Price = 69.99m,
6464
StockLevel = 120,
6565
ImageUrl = "https://placehold.co/200?text=Webcam"
6666
},
6767
new Product
6868
{
69-
Id = new Guid("77b608ae-1ce8-4bb2-b02c-edd4185e54e5"),
69+
Id = Guid.Parse("77b608ae-1ce8-4bb2-b02c-edd4185e54e5"),
7070
Name = "Portable SSD",
7171
Price = 99.99m,
7272
StockLevel = 80,
7373
ImageUrl = "https://placehold.co/200?text=Portable+SSD"
7474
},
7575
new Product
7676
{
77-
Id = new Guid("d182e085-408d-4bc7-aea5-946ca3d0dcec"),
77+
Id = Guid.Parse("d182e085-408d-4bc7-aea5-946ca3d0dcec"),
7878
Name = "Gaming Chair",
7979
Price = 249.99m,
8080
StockLevel = 20,
8181
ImageUrl = "https://placehold.co/200?text=Gaming+Chair"
8282
},
8383
new Product
8484
{
85-
Id = new Guid("7a7d74b7-e9af-41ca-9f89-69c1e7f45c8c"),
85+
Id = Guid.Parse("7a7d74b7-e9af-41ca-9f89-69c1e7f45c8c"),
8686
Name = "Smart Speaker",
8787
Price = 39.99m,
8888
StockLevel = 90,

ch09/CleanCart.NET/src/Presentation.BSA/Components/ShoppingCartIcon/ShoppingCartIcon.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868

6969
private async Task RefreshShoppingCart()
7070
{
71-
_shoppingCart = await ShoppingCartRepository.GetByUserIdAsync(_user!.Id);
71+
if (_user is null) return;
72+
_shoppingCart = await ShoppingCartRepository.GetByUserIdAsync(_user.Id);
7273
_isBadgeVisible = _shoppingCart?.Items.Count > 0;
7374
_cartItemCount = _shoppingCart?.Items.Count ?? 0;
7475
}

0 commit comments

Comments
 (0)