The test
A unit test is a small method that calls one unit of code, such as one method, with known inputs and checks the result by itself. Here CartTests checks Cart.Total, which should give 10% off for 10 or more items.
dotnet test builds the test project, which references Shop. xUnit then looks through it for methods marked [Fact]: each one is a test. It finds one, BulkDiscount, makes a fresh CartTests object and calls it.
Run it: red
Every test has three parts. Arrange sets up what the test needs. Line 5 puts 10 in qty and 5 in price: 10 items at 5 each, the smallest order that should get the discount.
Act does the one thing being tested. Line 7 calls Cart.Total(10, 5), so qty and price travel into Total in the Shop project. The test calls the method directly, in memory: no app, no window, no web server.
The comment says 10 or more items get 10% off, but line 5 tests qty > 10. With qty = 10 that is false, so line 7 returns 10 × 5 = 50, with no discount. total now holds 50.
Assert.Equal(45, total) compares the expected value, 45, with the actual one, 50. They differ, so Assert throws an exception. A test fails when it throws; the runner catches the exception and records the failure.
dotnet test prints the failed test with Expected: 45 and Actual: 50, then a summary: 1 failed, 0 passed. The test has caught a real bug before any customer did.
Fix it: green
The test was right; the code was wrong. Change > to >= on line 5, so 10 or more items get the discount. Never change the expected value just to make a red test pass.
Run dotnet test again. Now 10 >= 10 is true, so line 6 returns 10 × 5 × 9 / 10 = 45. Assert.Equal(45, 45) does not throw, so the test passes: 0 failed, 1 passed.
To check several inputs, write a [Theory] with one [InlineData] row per case; xUnit runs it once per row. The tests stay in the project and run on every change, so this bug cannot quietly come back.
What happens
// step 1/10 · idea
unit a small piece of code: one method or class
unit test a method that calls it and checks the result
Shop the project with Cart.cs (the code)
Shop.Tests the test project with CartTests.cs
references Shop + the xUnit NuGet packages
good tests fast, isolated, repeatable, self-checking
dotnet new xunit makes the test project. It brings the xunit, xunit.runner.visualstudio and Microsoft.NET.Test.Sdk packages from NuGet and a global using for Xunit, which is why CartTests.cs needs no using line. dotnet add reference connects it to Shop. The console is shortened. The real dotnet test output also shows the build, the test file and line, timing and Skipped/Total counts, and its exact layout depends on the SDK version and test platform.