### Complete Example Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md A comprehensive example showcasing the integration of IOC setup, data population using builders and templates, and service resolution within the fluent test scaffold. ```csharp var testScaffold = new TestScaffold() .UseAutofac(ctx => { ctx.Container.Register(_ => dbContext).SingleInstance(); ctx.Container.RegisterType().As(); }) .UsingBuilder() .WithTemplate("StandardUser") .With(new User { Email = "test@example.com" }) .UsingBuilder() .WithDefaultProducts() .Build(); var userService = testScaffold.Resolve(); // Execute test logic... ``` -------------------------------- ### Install FluentTestScaffold.Core Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/setup.md Provides the NuGet installation command for the core FluentTestScaffold library, which is the required base package for the framework. ```csharp Install `FluentTestScaffold.Core` ``` -------------------------------- ### Creating and Publishing a Release Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md This snippet demonstrates the command-line process for creating a Git release tag, pushing it to the remote repository, and then using the GitHub CLI to create a corresponding GitHub release. This action triggers the automated release publishing workflow. ```bash git checkout main git pull origin main git tag v1.0.0 git push origin v1.0.0 gh release create v1.0.0 --title "Release v1.0.0" --notes "Release notes here" ``` -------------------------------- ### CodeQL Security Scanning Integration Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md This describes the integration of CodeQL for automated security vulnerability scanning within the CI workflow. It highlights that the analysis is static, runs automatically, and integrates with GitHub's security features for reporting. ```yaml # CodeQL Security Scanning # Integration: Built into CI workflow # Features: # 1. Static Analysis: Runs security vulnerability scanning # 2. Automated Execution: No manual intervention required # 3. GitHub Security Integration: Results appear in Security tab ``` -------------------------------- ### Local Testing Commands Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md Provides bash commands for local testing of the .NET project, including building, packing, and checking the .NET version. These commands help replicate CI environment checks locally. ```bash # Test build locally dotnet build --configuration Release # Test packaging dotnet pack --configuration Release # Test with specific .NET version dotnet --version ``` -------------------------------- ### Install FluentTestScaffold.EntityFrameworkCore Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/setup.md Provides the NuGet installation command for the Entity Framework Core integration package, enabling the use of EF Core builders with FluentTestScaffold. ```csharp Install `FluentTestScaffold.EntityFrameworkCore` ``` -------------------------------- ### Install FluentTestScaffold.Autofac Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/setup.md Provides the NuGet installation command for the Autofac integration package, enabling support for the Autofac IoC container within FluentTestScaffold. ```csharp Install `FluentTestScaffold.Autofac` ``` -------------------------------- ### Setup with Autofac IOC Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Provides an example of configuring the TestScaffold to use Autofac as the IOC container, including registering services with Autofac's syntax. ```csharp var testScaffold = new TestScaffold() .UseAutofac(ctx => { ctx.Container.Register(_ => mockAuthService.Object).SingleInstance(); ctx.Container.RegisterType().As().SingleInstance(); }); ``` -------------------------------- ### Matrix Strategy for .NET Versions Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md Configures the CI workflow to use a matrix strategy, enabling testing across multiple .NET versions. This ensures compatibility with different .NET runtimes. ```yaml strategy: matrix: dotnet-version: [6.0.x, 7.0.x, 8.0.x] ``` -------------------------------- ### Install FluentTestScaffold.EntityFrameworkCore Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.EntityFrameworkCore/README.md Installs the Entity Framework Core package for FluentTestScaffold using the .NET CLI. ```bash dotnet add package FluentTestScaffold.EntityFrameworkCore ``` -------------------------------- ### Quick Start with TestScaffold Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Core/README.md Demonstrates the basic usage of the TestScaffold class, including configuring IOC services and building the scaffold. ```csharp using FluentTestScaffold.Core; var testScaffold = new TestScaffold() .UseIoc(services => { // Configure your services }) .Build(); ``` -------------------------------- ### Release Process Example Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Demonstrates the command-line steps to create and push a release tag, and then create a GitHub release to trigger the CI/CD pipeline. ```bash # Ensure you're on main branch git checkout main git pull origin main # Create and push release tag git tag v1.0.0 git push origin v1.0.0 # Create GitHub release (triggers release-publish workflow) gh release create v1.0.0 --title "Release v1.0.0" --notes "Release notes here" ``` -------------------------------- ### Install Fluent Test Scaffold Core Package Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Installs the core FluentTestScaffold package using the .NET CLI. ```bash dotnet add package FluentTestScaffold.Core ``` -------------------------------- ### Release Publishing Workflow Configuration (release-publish.yml) Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md This YAML outlines the Continuous Deployment workflow for publishing packages. It is triggered by published releases or manual dispatch. The workflow extracts the version from the release tag, validates the release source, builds packages, and publishes them to NuGet.org and GitHub Packages, updating release notes accordingly. ```yaml # Release Publishing Workflow (release-publish.yml) # Triggers: Published releases, manual workflow dispatch # Jobs: # 1. Extract Version: Extracts version from release tag # 2. Validate Release: Validates release is from main branch # 3. Build Packages: Builds all packages with extracted version # 4. Publish to NuGet.org: Publishes packages to NuGet.org # 5. Publish to GitHub Packages: Publishes packages to GitHub Packages # 6. Update Release Notes: Updates release with publishing information ``` -------------------------------- ### Enable Debug Logging in Workflows Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md Enables debug logging for GitHub Actions workflows. This is useful for detailed troubleshooting by providing more verbose output during execution. ```yaml env: ACTIONS_STEP_DEBUG: true ``` -------------------------------- ### Install FluentTestScaffold.Core Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Core/README.md Adds the FluentTestScaffold.Core package to your .NET project. ```bash dotnet add package FluentTestScaffold.Core ``` -------------------------------- ### Quick Start: NUnit Test with FluentTestScaffold Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Nunit/README.md Example demonstrating how to use FluentTestScaffold with NUnit in a C# test fixture. It shows how to initialize the TestScaffold, configure it to use NUnit logging, and integrate with an IoC container. ```csharp using FluentTestScaffold.Nunit; using NUnit.Framework; [TestFixture] public class MyIntegrationTests { [Test] public void TestWithScaffold() { var testScaffold = new TestScaffold() // Will be used to log scenario steps .UsingNunit() .UseIoc(new AppServicesBuilder()); // Your test logic here } } ``` -------------------------------- ### Environment Variables for CI Workflows Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md Defines common environment variables used in CI workflows, such as .NET versions. These variables configure the build and test environment. ```yaml env: DOTNET_VERSION: '8.0.x' DOTNET_VERSIONS: '["6.0.x", "7.0.x", "8.0.x"]' ``` -------------------------------- ### Install FluentTestScaffold.Bdd Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Bdd/README.md Installs the FluentTestScaffold.Bdd package using the .NET CLI. ```bash dotnet add package FluentTestScaffold.Bdd ``` -------------------------------- ### CI Workflow Configuration (ci.yml) Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ci-cd-setup.md This YAML defines the Continuous Integration workflow for the FluentTestScaffold project. It triggers on pushes to the main branch and pull requests, performing build, test, code coverage, security scanning, and code quality checks across multiple .NET versions. ```yaml # CI Workflow (ci.yml) # Triggers: Push to main, pull requests # Jobs: # 1. Build and Test: Builds and tests on multiple .NET versions (6.0, 7.0, 8.0) # 2. Code Coverage: Generates coverage reports with 90% threshold enforcement # 3. Security Scan: Runs security analysis # 4. Code Quality: Runs code formatting and style analysis ``` -------------------------------- ### Setup with Default IOC Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Demonstrates how to initialize the TestScaffold using the default .NET IOC container and register a service as a singleton. ```csharp var testScaffold = new TestScaffold() .UseIoc(ctx => ctx.Container.AddSingleton()); ``` -------------------------------- ### Install Fluent Test Scaffold Entity Framework Core Package Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Installs the FluentTestScaffold package specifically for Entity Framework Core integration using the .NET CLI. ```bash dotnet add package FluentTestScaffold.EntityFrameworkCore ``` -------------------------------- ### Fluent API Initialization Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Demonstrates the starting point of the Fluent Test Scaffold's fluent API, showing how to instantiate the TestScaffold class. ```csharp // Start with TestScaffold constructor var testScaffold = new TestScaffold() ``` -------------------------------- ### Install FluentTestScaffold.Nunit Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Nunit/README.md Command to add the FluentTestScaffold.Nunit package to your .NET project. ```bash dotnet add package FluentTestScaffold.Nunit ``` -------------------------------- ### Install FluentTestScaffold.Autofac Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Autofac/README.md Adds the Autofac integration package for FluentTestScaffold to your .NET project. ```bash dotnet add package FluentTestScaffold.Autofac ``` -------------------------------- ### Install FluentTestScaffold.AspNetCore Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.AspNetCore/README.md This snippet shows how to add the FluentTestScaffold.AspNetCore package to your .NET project using the dotnet CLI. ```bash dotnet add package FluentTestScaffold.AspNetCore ``` -------------------------------- ### FluentTestScaffold Package Dependencies Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/setup.md Visualizes the core package and its extensions, including Autofac, Entity Framework Core, BDD, and ASP.NET Core integration, showing their relationships. ```mermaid %%{init: {'theme':'base', 'themeVariables': {'primaryColor':'#ffffff','primaryTextColor':'#000000','primaryBorderColor':'#000000','lineColor':'#000000','secondaryColor':'#f0f0f0','tertiaryColor':'#ffffff'}}}%% flowchart TB subgraph "Core Package" CORE[FluentTestScaffold.Core
Required Base Package] end subgraph "IOC Extensions" AUTOFAC[FluentTestScaffold.Autofac
Autofac Container Support] end subgraph "Database Extensions" EF[FluentTestScaffold.EntityFrameworkCore
EF Core Builder Support] end subgraph "Testing Extensions" BDD[FluentTestScaffold.Bdd
BDD Style API] ASPNET[FluentTestScaffold.AspNetCore
Controller Integration Tests] end CORE --> AUTOFAC CORE --> EF CORE --> BDD CORE --> ASPNET style CORE fill:#e3f2fd,stroke:#000,stroke-width:2px,color:#000 style AUTOFAC fill:#f3e5f5,stroke:#000,stroke-width:2px,color:#000 style EF fill:#e8f5e8,stroke:#000,stroke-width:2px,color:#000 style BDD fill:#fff3e0,stroke:#000,stroke-width:2px,color:#000 style ASPNET fill:#ffebee,stroke:#000,stroke-width:2px,color:#000 ``` -------------------------------- ### EF Core Quick Start with FluentTestScaffold Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.EntityFrameworkCore/README.md Demonstrates how to use FluentTestScaffold with Entity Framework Core to set up a test database and seed data. It initializes a DbContext, registers an EfCoreBuilder, and adds a User entity. ```csharp using FluentTestScaffold.EntityFrameworkCore; var dbContext = TestDbContextFactory.Create(); var userId = Guid.Parse("65579043-8112-480C-A885-C6157947F0F3"); new TestScaffold() .UseIoc(ctx => { ctx.Container.RegisterSingleton(_ => dbContext); ctx.RegisterBuilder>(); }) .UsingBuilder>() .With(new User( id: userId, email: "Bob@test.com", password: "", name: "Bob", dateOfBirth: DateOnly.FromDateTime(DateTime.Now.AddYears(-15)) )) .Build(); ``` -------------------------------- ### Verbose Test Output with Coverlet Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/coverage.md This command runs .NET tests with detailed verbosity and specifies a Coverlet runsettings file for coverage collection. ```bash dotnet test --verbosity detailed --settings coverlet.runsettings ``` -------------------------------- ### List Tests and Validate Coverage Configuration Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/coverage.md This command lists all tests in the project and validates the coverlet.runsettings file without running the tests. ```bash dotnet test --settings coverlet.runsettings --list-tests ``` -------------------------------- ### Mocking Services with Moq Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Illustrates how to integrate Moq for mocking services within the TestScaffold's IOC setup, including configuring mock behavior. ```csharp var timeService = new TestScaffold() .UseIoc(serviceBuilder => { serviceBuilder.WithMock(mock => { mock.Setup(c => c.GetTime()).Returns(TimeOnly.Parse(timeString, CultureInfo.CurrentCulture)); return mock; }); }) .Resolve(); ``` -------------------------------- ### Conditional Enqueue with IfElse Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/builders/README.md Example demonstrating conditional enqueuing with different actions for true and false conditions. ```csharp new TestScaffold() .UseIoc(ctx => ctx.Container.RegisterSingleton(_ => dbContext)) .UsingBuilder() .IfElse(IsAdmin, b => b.With(new User { Id: userId, Amail: "test@email.com", Role = "Admin" }), b => b.With(new User( Id: userId, Email: "test@email.com", ))) ``` -------------------------------- ### Builder Workflow Diagram Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/builders/README.md Illustrates the step-by-step process of using builders within the Fluent Test Scaffold, from initial setup to executing queued actions and persisting changes. ```mermaid flowchart TD START[TestScaffold.UsingBuilder<T>] --> RESOLVE[IOC Resolves Builder] RESOLVE --> FLUENT[Builder Fluent API Available] FLUENT --> WITH[With/WithRange Methods] FLUENT --> COND[If/IfElse Methods] FLUENT --> CONTEXT[SetTestContext Methods] WITH --> ENQUEUE[Actions Enqueued] COND --> ENQUEUE CONTEXT --> ENQUEUE ENQUEUE --> SWITCH{Switch Context?} SWITCH -->|UsingBuilder<Other>| AUTOBUILD[Auto Build Current] SWITCH -->|UsingTestScaffold| AUTOBUILD SWITCH -->|Manual Build| BUILD[Build Method Called] AUTOBUILD --> EXECUTE[Execute Queued Actions] BUILD --> EXECUTE EXECUTE --> PERSIST[Persist Changes
e.g., SaveChanges] PERSIST --> RETURN[Return New Context] style START fill:#e3f2fd style FLUENT fill:#f1f8e9 style ENQUEUE fill:#fff3e0 style EXECUTE fill:#fce4ec style PERSIST fill:#e8f5e8 ``` -------------------------------- ### .NET Service Builder Implementation Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Example of a custom service builder using .NET's default IOC container. It demonstrates registering services like DbContext, request context, auth service, and shopping cart. ```csharp public class AppServicesBuilder : DotnetServiceBuilder { public void RegisterAppServices() { Container.AddSingleton(_ => TestDbContextFactory.Create()); Container.AddTransient(); Container.AddTransient(); Container.AddTransient(); RegisterBuilder(); } } ``` -------------------------------- ### C# Example: Data Template Method with Multiple Parameters Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/data-templates/README.md Defines a Data Template method that accepts multiple parameters and sets them into the TestScaffoldContext. ```csharp [DataTemplate] public TestScaffold SetContextFromTemplateMultipleParameters(TestScaffold testScaffold, int param1, Guid param2, string param3) { testScaffold.TestScaffoldContext.Set(param1, nameof(param1)); testScaffold.TestScaffoldContext.Set(param2, nameof(param2)); testScaffold.TestScaffoldContext.Set(param3, nameof(param3)); return testScaffold; } ``` -------------------------------- ### C# Example: Calling a Data Template with Multiple Parameters Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/data-templates/README.md Demonstrates how to instantiate a TestScaffold and invoke a Data Template method with multiple parameters using the WithTemplate method. ```csharp var param1 = 32; var param2 = Guid.NewGuid(); var param3 = "Hello World"; var testScaffold = new TestScaffold(new ConfigOptions { AutoDiscovery = AutoDiscovery.All, Assemblies = new List {typeof(TestScaffoldDataTemplates).Assembly} }) .UseIoc() .WithTemplate(nameof(TestScaffoldDataTemplates.SetContextFromTemplateMultipleParameters), param1, param2, param3); ``` -------------------------------- ### Resolving Services with TestScaffold Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Shows how to resolve services from the IOC container using the TestScaffold's Resolve method, including an example with a fluent API approach. ```csharp var testScaffold = new TestScaffold() .UseIoc(ctx => ctx.Container.AddTransient()); var service = testScaffold.Resolve(); /// or using fluent api MyService? service = null; new TestScaffold() .UseIoc(ctx => { ctx.RegisterBuilder(); ctx.Container.AddTransient(); }) .Resolve(out service) .UsingBuilder(); ``` -------------------------------- ### Autofac Service Builder Implementation Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Example of a custom service builder using Autofac. It shows how to register services with Autofac's container, including single instance and type-as mappings. ```csharp public class AutofacAppServicesBuilder : AutofacServiceBuilder { public void RegisterAppServices() { Container.Register(_ => TestDbContextFactory.Create()).SingleInstance(); Container.RegisterType().As(); Container.RegisterType().As(); Container.RegisterType(); RegisterBuilder(); } } ``` -------------------------------- ### Builder Pattern & Data Setup Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Utilizes the builder pattern to define and populate test data. Supports adding single entities, ranges of entities, and predefined default data sets for various builders. ```csharp // Switch to specific builders for data setup .UsingBuilder() .With(new User { Name = "John", Email = "john@test.com" }) .WithRange(users) .UsingBuilder() .WithDefaultProducts() .With(new Product { Name = "Widget", Price = 10.99m }) ``` -------------------------------- ### BDD Workflow Diagram Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/bdd/README.md Illustrates the standard BDD pattern and how it maps to the FluentTestScaffold's BDD API, showing the flow from setup to assertion. ```mermaid %%{init: {'theme':'base', 'themeVariables': {'primaryColor':'#ffffff','primaryTextColor':'#000000','primaryBorderColor':'#000000','lineColor':'#000000','secondaryColor':'#f0f0f0','tertiaryColor':'#ffffff'}}}%% flowchart LR subgraph "BDD Pattern" GIVEN[Given
Setup Context] --> WHEN[When
Execute Action] WHEN --> THEN[Then
Assert Results] end subgraph "FluentTestScaffold BDD" SETUP[TestScaffold Setup] --> BDD_GIVEN[Given - WithBuilder] BDD_GIVEN --> BDD_WHEN[When - ExecuteAction] BDD_WHEN --> BDD_THEN[Then - AssertResult] end GIVEN -.-> BDD_GIVEN WHEN -.-> BDD_WHEN THEN -.-> BDD_THEN style GIVEN fill:#e8f5e8,stroke:#000,stroke-width:2px,color:#000 style WHEN fill:#fff3e0,stroke:#000,stroke-width:2px,color:#000 style THEN fill:#ffebee,stroke:#000,stroke-width:2px,color:#000 style BDD_GIVEN fill:#e8f5e8,stroke:#000,stroke-width:2px,color:#000 style BDD_WHEN fill:#fff3e0,stroke:#000,stroke-width:2px,color:#000 style BDD_THEN fill:#ffebee,stroke:#000,stroke-width:2px,color:#000 style SETUP fill:#e3f2fd,stroke:#000,stroke-width:2px,color:#000 ``` -------------------------------- ### Performing API Actions and Assertions Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/asp-net-core/README.md Provides an example of how to obtain an HttpClient from the TestScaffold to make API calls to the ASP.Net Core application and assert the responses. ```csharp var httpClient = testScaffold.GetWebApplicationHttpClient(); var response = await httpClient.PostAsJsonAsync( "/maths/add", new AddNumbers { A = 12, B = 2 } ); // assert 200 response response.StatusCode.Should().Be(HttpStatusCode.Ok); // extract the response message and assertions var answer = await response.Content.ReadFromJsonAsync(); answer.Result .Should() .Be(14); ``` -------------------------------- ### IOC Container Setup Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Configures the Inversion of Control (IOC) container using either the .NET default IServiceCollection or Autofac. This allows for managing dependencies and service lifetimes within the test scaffold. ```csharp // .NET Default IOC Container .UseIoc(services => { services.AddSingleton(); services.AddTransient(); }) // Autofac IOC Container .UseAutofac(ctx => { ctx.Container.RegisterType().As(); ctx.Container.Register(_ => dbContext).SingleInstance(); }) ``` -------------------------------- ### Component Integration Test: User Can Add To Cart Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md An example integration test demonstrating how a user can add an item to their shopping cart using the Fluent Test Scaffold. It showcases dependency injection with Autofac, setting up test data, and asserting the outcome. ```csharp [Test] public void ComponentIntegrationTest_UserCanAddToCart() { using var dbContext = TestDbContextFactory.Create(); var email = "Jim@test.com"; var password = "SupperSecretPa$$word"; // Arrange var userId = Guid.Parse("A5A743C3-A02F-4CA3-94F8-B0ECAF4A6345"); var testScaffold = new TestScaffold() .UseAutofac(ctx => { ctx.Container.Register(_ => dbContext).SingleInstance(); ctx.Container.RegisterType().As(); ctx.Container.Register(c => { var requestContext = new UserRequestContext(c.Resolve()); requestContext.AuthenticateUser(email, password); return requestContext; }) .As() .InstancePerLifetimeScope(); ctx.Container.RegisterType(); }) .UsingBuilder() .WithTemplate("DefaultCatalogueTemplate") .WithDefaultCatalogue() .With(new User( id: userId, email: email, password: password, name: "Jimmy", dateOfBirth: DateOnly.FromDateTime(DateTime.Now.AddYears(-8)) )) .WithShoppingCart(userId) .Build(); var item = dbContext.Items.FirstOrDefault(i => i.Title == Defaults.CatalogueItems.DeadPool); // Act var shoppingCartService = testScaffold.Resolve(); shoppingCartService.AddItemToCart(item!.Id); // Assert var cart = dbContext.ShoppingCart.Include(s => s.Inventory).FirstOrDefault(u => u.UserId == userId); Assert.IsTrue(cart?.Inventory.Any(i => i.Id == item.Id)); } ``` -------------------------------- ### BDD Logging with NUnit Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/bdd/README.md Shows how to configure the TestScaffold to use NUnit for logging BDD scenario steps, ensuring that `UsingNunit` is called before `UseIoc` for correct setup. ```csharp var testScaffold = new TestScaffold() // Will be use to log scenario steps .UsingNunit() .UseIoc(new AppServicesBuilder()); ``` -------------------------------- ### Conditional Enqueue with If Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/builders/README.md Example of enqueuing an action only if a specified condition is true. ```csharp new TestScaffold() .UseIoc(ctx => ctx.Container.RegisterSingleton(_ => dbContext)) .UsingBuilder() .If(true, b => b.With(new User( id: userId, email: "test@email.com" ))) ``` -------------------------------- ### Initialize Database with EF Core Builder Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/builders/ef-builder.md Demonstrates initializing a database using the EfCoreBuilder, registering the DBContext, and adding a User entity. ```csharp var dbContext = TestDbContextFactory.Create(); var userId = Guid.Parse("65579043-8112-480C-A885-C6157947F0F3"); new TestScaffold() .UseIoc(ctx => { ctx.Container.RegisterSingleton(_ => dbContext); ctx.RegisterBuilder>(); }) .UsingBuilder>() .With(new User( id: userId, email: "Bob@test.com", password: "", name: "Bob", dateOfBirth: DateOnly.FromDateTime(DateTime.Now.AddYears(-15)) )) .Build(); ``` -------------------------------- ### Exclude Class from Code Coverage Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/coverage.md This C# attribute can be applied to a class to exclude it and its members from code coverage analysis by Coverlet. ```csharp [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public class ExcludedClass { // This class will be excluded from coverage } ``` -------------------------------- ### Coverlet Collector Package Reference Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/coverage.md This XML snippet shows how to include the coverlet.collector NuGet package in a .NET test project file. ```xml all runtime; build; native; contentfiles; analyzers; buildtransitive ``` -------------------------------- ### Method Chaining Flow Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Illustrates the typical method chaining flow for setting up and using the fluent test scaffold, from initialization to service resolution. ```mermaid %%{init: {'theme':'base', 'themeVariables': {'primaryColor':'#ffffff','primaryTextColor':'#000000','primaryBorderColor':'#000000','lineColor':'#000000','secondaryColor':'#f0f0f0','tertiaryColor':'#ffffff'}}}%% flowchart LR NEW[new TestScaffold] --> IOC[UseIoc/UseAutofac] IOC --> BUILDER[UsingBuilder T] BUILDER --> DATA[With/WithRange/WithDefault] DATA --> TEMPLATE[WithTemplate] TEMPLATE --> BUILD[Build] BUILD --> RESOLVE[Resolve T] BUILDER -.->|"Switch Context"| BUILDER2[UsingBuilder U] BUILDER2 --> DATA2[With/WithRange] DATA2 --> TEMPLATE style NEW fill:#e3f2fd,stroke:#000,stroke-width:2px,color:#000 style IOC fill:#fff3e0,stroke:#000,stroke-width:2px,color:#000 style BUILDER fill:#e8f5e8,stroke:#000,stroke-width:2px,color:#000 style BUILDER2 fill:#e8f5e8,stroke:#000,stroke-width:2px,color:#000 style DATA fill:#f3e5f5,stroke:#000,stroke-width:2px,color:#000 style DATA2 fill:#f3e5f5,stroke:#000,stroke-width:2px,color:#000 style TEMPLATE fill:#e1f5fe,stroke:#000,stroke-width:2px,color:#000 style BUILD fill:#ffebee,stroke:#000,stroke-width:2px,color:#000 style RESOLVE fill:#c8e6c9,stroke:#000,stroke-width:2px,color:#000 ``` -------------------------------- ### Exclude Files/Directories from Coverage in coverlet.runsettings Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/coverage.md This XML configuration within coverlet.runsettings specifies file or directory patterns to exclude from code coverage collection. ```xml **/path/to/exclude/**/* ``` -------------------------------- ### Test Scaffold Initialization with ConfigOptions Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/config-options/README.md Demonstrates how to initialize the TestScaffold with default ConfigOptions. ```csharp new TestScaffold(new ConfigOptions()); ``` -------------------------------- ### FluentTestScaffold Packages Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/README.md Lists the available packages for FluentTestScaffold and their descriptions. ```csharp | Package | Description | |-------------------------------|-----------------------------------| | `FluentTestScaffold.Core` | Core framework and interfaces | | `FluentTestScaffold.AspNetCore` | ASP.NET Core integration | | `FluentTestScaffold.Autofac` | Autofac DI container support | | `FluentTestScaffold.Bdd` | BDD testing support | | `FluentTestScaffold.EntityFrameworkCore` | Entity Framework Core support | | `FluentTestScaffold.Nunit` | NUnit testing framework support | ``` -------------------------------- ### BDD Scenario with FluentTestScaffold Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/FluentTestScaffold.Bdd/README.md Demonstrates how to define a BDD scenario using the FluentTestScaffold.Bdd library, including Given, When, and Then steps with dependency injection. ```csharp using FluentTestScaffold.Bdd; var testScaffold = new TestScaffold() .UseIoc(services => { services.AddScoped(); }) .Build(); testScaffold.Scenario("User can add item to shopping cart") .Given("a user is authenticated", scaffold => { // Setup user authentication }) .When("the user adds an item to cart", cartService => { // Perform the action cartService.AddItem(itemId); }) .Then("the item should be in the cart", scaffold => { // Assert the result var cart = scaffold.Resolve().GetCart(); Assert.Contains(itemId, cart.Items); }); ``` -------------------------------- ### Accessing Test Context in C# Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/test-context/README.md Demonstrates how to access values stored in the Test Context using the TestScaffoldContext property of the TestScaffold. It shows retrieving a Guid value for 'Over18UserId'. ```csharp var testScaffold = new TestScaffold() .UseAutofac(new AutofacAppServicesBuilder(), serviceBuilder => { // Custom App Service Builder to register common services. serviceBuilder.RegisterAppServices(); // Register service under test serviceBuilder.Container.RegisterType(); }) .WithTemplate(ApplicationTemplates.DefaultCatalogueTemplate); // Authenticate user initialised with the DataTemplate var requestContext = testScaffold.Resolve(); requestContext.AuthenticateUser(UserBuilder.Over18User.Email, UserBuilder.Over18User.Password); //Resolved the dbContext registered by the AutofacAppServicesBuilder var dbContext = testScaffold.Resolve(); var item = dbContext.Items.FirstOrDefault(i => i.Title == Defaults.CatalogueItems.DeadPool); // Attempt to add age restricted content with under age user var shoppingCartService = testScaffold.Resolve(); shoppingCartService.AddItemToCart(item!.Id); // Get the UserId stored by the DataTemplate var userId = testScaffold.TestScaffoldContext.Get("Over18UserId"); var cart = dbContext.ShoppingCart.Include(s => s.Inventory).FirstOrDefault(u => u.UserId == userId); Assert.IsTrue(cart?.Inventory.Any(i => i.Id == item.Id)); ``` ```csharp var contect = testScaffold.Resolve(); var userId = context.Get("Over18UserId"); ``` -------------------------------- ### Usage of Custom Service Builders Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/ioc/README.md Demonstrates how to integrate custom service builders into the TestScaffold using the UseIoc and UseAutofac methods, passing the builder instance and a registration action. ```csharp // Default IOC var testScaffold = new TestScaffold() .UseIoc( new DefaultIocAppServicesBuilder(), ctx => ctx.RegisterAppServices()); // Autofac IOC var testScaffold = new TestScaffold() .UseAutofac( new AutofacAppServicesBuilder(), ctx => ctx.RegisterAppServices())); ``` -------------------------------- ### Switching Between Builders and TestScaffold Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/builders/README.md Illustrates how to chain builder operations and switch back to the main TestScaffold context. It demonstrates using a builder, switching back, resolving a service, and the auto-build behavior when context switching. ```csharp MockService? service; var testScaffold = new TestScaffold() .UseIoc(ctx => ctx.Container.RegisterSingleton(_ => dbContext)) .UsingBuilder() .WithDefaultCatalogue() .UsingTestScaffold() .Resolve(out service); ``` -------------------------------- ### Basic Builder Usage with EF Core Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/builders/README.md Demonstrates how to initialize the TestScaffold, configure IOC for an EF Core DbContext, and use a builder to add a user to the database. The deferred execution is highlighted by fetching the user after the build. ```csharp new TestScaffold() .UseIoc(ctx => ctx.Container.RegisterSingleton(_ => dbContext)) .UsingBuilder>() .With(new User( id: userId, email: "Bob@test.com", password: "", name: "Bob", dateOfBirth: DateOnly.FromDateTime(DateTime.Now.AddYears(-15)) )) .Build(); var user = dbContext.Users.FirstOrDefault(u => u.Id == userId); ``` -------------------------------- ### Creating a Data Template Method Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/data-templates/README.md Demonstrates how to create a Data Template by applying the `DataTemplate` attribute to a method that accepts a `TestScaffold` parameter. It shows matching by method name or by attribute name. ```csharp // Match by method name [DataTemplate] // OR Match by Attribute Name [DataTemplate(Name = "Default Catalogue & Users")] public TestScaffold DefaultCatalogueAndUsers(TestScaffold testScaffold) { testScaffold.UsingBuilder() //Setup standard users .WithOver18User(out var over18UserId) .WithUnder18User(out var under18UserId) //Setup User Shopping Carts .WithShoppingCart(under18UserId) .WithShoppingCart(over18UserId) .Build() .UsingBuilder() //Setup Inventory .WithRange(new List() { new() {Id = Guid.NewGuid(), Title = Defaults.CatalogueItems.Minions, Price = 21}, new() {Id = Guid.NewGuid(), Title = Defaults.CatalogueItems.Avengers, Price = 24}, new() {Id = Guid.NewGuid(), Title = Defaults.CatalogueItems.DeadPool, Price = 14, AgeRestriction = 15} }).Build(); return testScaffold; } ``` -------------------------------- ### Basic BDD Scenario Definition Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/bdd/README.md Demonstrates how to define a BDD scenario using the FluentTestScaffold's BDD API, including setting up the TestScaffold, defining Given, When, and Then steps. ```csharp var testScaffold = new TestScaffold() // Will be use to log scenario steps .UsingNunit() .UseIoc(new AppServicesBuilder()) .WithTemplate(new DefaultCatalogueTemplate()) .Build(); testScaffold .Scenario("User can not add age restricted item to cart when under aged") .Given("A user is authenticated", AUserIsAuthenticated) .When("The user attempts to add an item to the shopping cart", WhenTheUserAddsItemToCart) .Then("The user should not be able to add the item to the shopping cart", ThenTheUserCanNotAddAgeRestrictedContent); ``` -------------------------------- ### Maintain Session State with WebApplicationHttpClient Source: https://github.com/rburnham52/fluent-test-scaffold/blob/main/docs/asp-net-core/README.md Demonstrates how to obtain an HTTP client that maintains session state and cookies, using the `GetWebApplicationHttpClient()` extension method. It shows an example of making unauthenticated and then authenticated requests to a sensitive endpoint, verifying the session state is preserved. ```csharp var httpClient = testScaffold.GetWebApplicationHttpClient(); // Initial unauthenticated call is expected to fail var response = await httpClient.PostAsJson( "/test/sensitive", new Sensitive { ... } ); response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); // Perform a successful login request to set the Authentication cookie await httpClient.PostAsJson( "/authentication/login", new Login { Username = "testuser", Password = "Password123!" } ); // New authenticated call is expected to pass as the request is now authenticated response = await httpClient.PostAsJson( "/test/sensitive", new Sensitive { ... } ); response.StatusCode.Should().Be(HttpStatusCode.Ok); ```