Grad.Codebook.Testing
2.1.1
dotnet add package Grad.Codebook.Testing --version 2.1.1
NuGet\Install-Package Grad.Codebook.Testing -Version 2.1.1
<PackageReference Include="Grad.Codebook.Testing" Version="2.1.1" />
<PackageVersion Include="Grad.Codebook.Testing" Version="2.1.1" />
<PackageReference Include="Grad.Codebook.Testing" />
paket add Grad.Codebook.Testing --version 2.1.1
#r "nuget: Grad.Codebook.Testing, 2.1.1"
#:package Grad.Codebook.Testing@2.1.1
#addin nuget:?package=Grad.Codebook.Testing&version=2.1.1
#tool nuget:?package=Grad.Codebook.Testing&version=2.1.1
Grad.Codebook.Testing
Testing utilities for Grad Codebook. This package allows projects that depend on Codebook to test functionality that requires database access.
Purpose
The Grad.Codebook package exposes data through database views that query from the EDW (Enterprise Data Warehouse).
For testing purposes, projects need a way to set up a test database without depending on the EDW. This package
provides that capability by creating EDW schema tables (edw.t_*) and populating them with test data, then
creating views (dbo.*) that match the production schema. This approach ensures that test data behaves exactly
like production data and prevents drift between mock tables and real views.
Usage
using Grad.Codebook.Testing;
// Create an instance with your test database connection string
var testDb = new CodebookTestDatabase(connectionString);
// Set up the database (creates tables and inserts test data)
testDb.Setup();
// Or use async version
await testDb.SetupAsync();
Test Data Constants
Instead of using magic strings in your tests, use the TestData class to access test data objects with all their properties:
using Grad.Codebook.Testing;
// Access test data as full objects with properties
var csProgram = TestData.GradPrograms.ComputerScienceMS;
Assert.Equal("10KS0112MS", csProgram.ProgramCode);
Assert.Equal("Computer Science", csProgram.MajorTitle);
// Use department codes
var csDepartment = TestData.Departments.ComputerScience;
Assert.Equal("434", csDepartment.DepartmentCode);
Assert.Equal("Department of Computer Science", csDepartment.FullName);
// Access all types of test data
var engineering = TestData.Colleges.Engineering;
var phdDegree = TestData.Degrees.PhD;
var mathMinor = TestData.Minors.Mathematics;
var csSubject = TestData.Subjects.ComputerScience;
Available test data categories:
TestData.Colleges- Test collegesTestData.Departments- Test departmentsTestData.Degrees- Test degreesTestData.GradPrograms- Test graduate programsTestData.Minors- Test minorsTestData.Majors- Test majorsTestData.Subcolleges- Test subcollegesTestData.Subjects- Test subjectsTestData.Concentrations- Test concentrationsTestData.Curriculums- Test curriculums
What it Does
The CodebookTestDatabase class:
- Creates the Codebook database if it doesn't exist
- Creates the edw schema if it doesn't exist
- Drops existing views and tables if they exist (to ensure a clean state)
- Creates edw schema tables that match the EDW structure:
- edw.t_coll (colleges)
- edw.t_dept (departments)
- edw.t_conc (concentrations)
- edw.t_curr (curriculums)
- edw.t_deg (degrees)
- edw.t_school_sub_coll (subcolleges)
- edw.t_subj (subjects)
- edw.t_pgm (programs)
- edw.t_minor (minors)
- edw.t_major (majors)
- edw.t_joint_pgm (joint programs)
- edw.t_pgm_joint_pgm (program-joint program mapping)
- edw.t_pgm_major (program-major mapping)
- edw.t_conc_pgm_major (concentration-program-major mapping)
- edw.t_pgm_rule_conc (program rule concentrations)
- edw.t_pgm_deg_title (program degree titles)
- Inserts test data into the edw tables
- Creates dbo views using DatabaseMigrator, which runs the same migrations used in production:
- colleges
- departments
- concentrations
- curriculums
- degrees
- subcolleges
- subjects
- grad_programs
- minors
- majors
- joint_programs
- major_concentrations
- program_concentrations
- department_names
- program_names
Test Data
The package includes sample data for:
- 3 colleges (Engineering, Liberal Arts & Sciences, Graduate College)
- 3 departments (Computer Science, Mathematics, ECE)
- 4 graduate programs (CS MS, CS PhD, Math MS, Math PhD)
- 2 minors (CS, Math)
- 2 majors (CS, Math)
- 2 concentrations (AI, Database Systems)
- And corresponding relationships between these entities
Notes
This approach mirrors the production database structure by:
- Using the same edw schema tables as production
- Using DatabaseMigrator to create views with the same migrations used in production
- Ensuring test data behaves identically to production data
- Preventing drift between test and production schemas
While it's not ideal for dependent projects to use the database directly, this approach is necessary for scenarios involving complex joins that aren't feasible with API calls.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Dapper (>= 2.1.66)
- Grad.Codebook (>= 2.1.1)
- Grad.CsLib.Data (>= 2.0.12)
- Microsoft.Data.SqlClient (>= 6.1.4)
- Respawn (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.