Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 26, 2025

Developers need pre-populated blog posts to test pagination, navigation, and search without manual data entry. In-memory SQLite loses data on restart, making this particularly painful during feature development.

Changes

  • DummyDataOptions: Configurable number of blog posts (default: 20)
  • DummyDataSeeder: Hosted service that seeds test data on startup with realistic titles, tags, dates, and content
  • UseDummyData() extension: Uses SQLite in-memory database with the existing SQL Repository<> implementation
  • Enabled in development: Automatically active via Program.cs when IsDevelopment()

Implementation

Uses SQLite in-memory with shared cache (DataSource=file::memory:?cache=shared) and the existing Repository<> from LinkDotNet.Blog.Infrastructure.Persistence.Sql. Data is seeded via a hosted service on application startup.

Usage

// Default configuration (20 posts)
builder.Services.UseDummyData();

// Custom count
builder.Services.UseDummyData(new DummyDataOptions { NumberOfBlogPosts = 50 });

Called after AddStorageProvider() in the service registration chain - removes existing IRepository<> registrations and sets up SQLite in-memory with the SQL repository.

Screenshot

20 blog posts with realistic titles, descriptions, tags, and dates. Fixed random seed ensures reproducible test data across sessions.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Idea] Load test blog posts for testing/development</issue_title>
<issue_description>I would find it beneficial to have something like a load/generate X blog posts just for testing/development purposes. Currently if I need to test behavior like the next/previous buttons I need to manually enter X blog posts to test my new changes. Also if you are using the Sqlite in memory option (I do this for developing new features as its the default with no extra config) your test blog posts will be removed upon reloading.

Or is there an easy way I am missing? Maybe I just need to setup a local test blog database and point to that. Or could we include a small test database in repo?</issue_description>

<agent_instructions>Create a new extension method called "UseDummyData" that fulfills the requirement and uses its own implementation of the "IRepository" (use in memory for example via SQLite).
DummyData should have an optional "DummyDataOptions" object for example how many blog posts have to be created. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@linkdotnet That is a good idea - to make that work across the board, we can also offer something like: ```diff if (builder.Environment.IsDevelopment()) { builder.Services.UseDummyAuthentication(); + builder.Services.UseDummyData(); } ```

We probably don't need this enabled all the time. We basically can create our own IRepository<BlogPost> for that behind the facade so we have a very specific (and predefined) set of blog posts.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add method to load test blog posts for development Add UseDummyData extension for in-memory test blog posts Dec 26, 2025
Copilot AI requested a review from linkdotnet December 26, 2025 10:21
@linkdotnet
Copy link
Owner

@copilot 1. Remove the tests
2. Remove the lock
3. Try to derive from SqlRepository and setup the Extensions so that only SQLite is used with an inmemory database provider for BlogPost

Copy link
Contributor Author

Copilot AI commented Dec 26, 2025

@copilot 1. Remove the tests
2. Remove the lock
3. Try to derive from SqlRepository and setup the Extensions so that only SQLite is used with an inmemory database provider for BlogPost

Done in commit 6b36075.

The implementation now:

  • Uses SQLite in-memory with Repository<> from the Infrastructure layer
  • Removes all tests and the custom repository implementation (no lock needed)
  • Seeds data via DummyDataSeeder hosted service on startup
  • Registers IRepository<> for all entity types using the SQL repository

The refactored code uses DataSource=file::memory:?cache=shared connection string and leverages the existing AddPooledDbContextFactory<BlogDbContext> pattern.

Copilot AI changed the title Add UseDummyData extension for in-memory test blog posts Add UseDummyData extension for SQLite in-memory test blog posts Dec 26, 2025
@linkdotnet linkdotnet force-pushed the copilot/add-load-test-blog-posts branch from 6b36075 to da256f2 Compare December 26, 2025 12:07
@linkdotnet linkdotnet force-pushed the copilot/add-load-test-blog-posts branch from da256f2 to 9137bb7 Compare December 26, 2025 12:08
@linkdotnet linkdotnet marked this pull request as ready for review December 26, 2025 12:09
@linkdotnet linkdotnet merged commit 23ba17a into master Dec 26, 2025
3 checks passed
@linkdotnet linkdotnet deleted the copilot/add-load-test-blog-posts branch December 26, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Idea] Load test blog posts for testing/development

2 participants