Skip to content

Cesivi Data Generation Guide

This guide explains how to use the data generation scripts to create sample Cesivi data for testing and development.

Quick Start

# Generate basic data and start server (one command!)
.\Start-MockServerWithData.ps1

That's it! The server will start on http://localhost:5010 (or your branch-specific port) with basic test data.


Scripts Overview

1. Generate-BasicMockData.ps1

Creates a minimal SharePoint structure with fixed, predictable IDs for testing.

What it creates: - 1 Web Application - 1 Site Collection (/sites/basic) - 1 Root Web - 1 List with 4 fields (Title, DateTime, Note, Bool) and 10 items - 1 Document Library with 10 files (2 DOCX, 3 PDF, 3 TXT, 2 PNG) with actual content - 2 Users with site collection admin permissions: - administrator (ID: 1) - kenaflow (ID: 2) - 3 SharePoint Groups: - Site Owners (ID: 3) - administrator is member - Site Members (ID: 4) - kenaflow is member - Site Visitors (ID: 5) - no members - 5 Role Definitions: - Full Control, Design, Contribute, Read, Limited Access

Fixed GUIDs used: - Web App ID: 11111111-1111-1111-1111-111111111111 - Site Collection ID: 22222222-2222-2222-2222-222222222222 - Root Web ID: 33333333-3333-3333-3333-333333333333 - List ID: 44444444-4444-4444-4444-444444444444 - Library ID: 55555555-5555-5555-5555-555555555555

Usage:

# Generate to default location (./MockData)
.\Generate-BasicMockData.ps1

# Generate to custom location
.\Generate-BasicMockData.ps1 -OutputPath "R:/MockData"

# Generate to branch-specific location (reads from .branch-config.json)
.\Generate-BasicMockData.ps1 -OutputPath "./MockData-main1"

When to use: - Unit testing (predictable IDs for assertions) - Quick smoke testing - Demonstrating basic functionality - Learning how the mock server works


2. Generate-MediumMockData.ps1

Creates a more realistic SharePoint structure with multiple site collections, subwebs, and varied content.

What it creates: - 1 Web Application - 3 Site Collections: 1. Corporate Intranet (/sites/intranet) - Announcements list (5 items) - Documents library (15 PDF files) - Subweb: Departments - Subweb: IT Department - IT Documents library (8 DOCX files) 2. Project Sites (/sites/projects) - Tasks list (20 items with varying statuses, priorities, completion %) 3. Human Resources (/sites/hr) - Employees list (10 items with departments, hire dates) - 5 Users with different roles: - administrator (Site Collection Admin) - john.doe, jane.smith, bob.wilson, alice.brown (Regular users)

Usage:

# Generate to default location
.\Generate-MediumMockData.ps1

# Generate to custom location
.\Generate-MediumMockData.ps1 -OutputPath "R:/MockData"

When to use: - Integration testing with multiple site collections - Testing navigation, web hierarchies (subwebs) - Testing with realistic data volumes - Demonstrating complex SharePoint structures - Performance testing with moderate data


3. Start-MockServerWithData.ps1

Convenience script that ensures mock data exists and starts the server with correct settings for your current git branch.

What it does: 1. Detects current git branch 2. Reads .branch-config.json to get port and data path settings 3. Checks if mock data exists 4. Generates mock data if missing (or if -Force specified) 5. Sets environment variables (CESIVI_DATA_PATH, CESIVI_HTTP_PORT, etc.) 6. Starts the mock server with dotnet run

Usage:

# Start server with basic data (generates if missing)
.\Start-MockServerWithData.ps1

# Force regenerate data and start
.\Start-MockServerWithData.ps1 -Force

# Use medium dataset
.\Start-MockServerWithData.ps1 -DataSet Medium

# Use custom data path
.\Start-MockServerWithData.ps1 -DataPath "R:/MockData"

# Combine options
.\Start-MockServerWithData.ps1 -Force -DataSet Medium

When to use: - Everyday development workflow - Quickly starting server with fresh data - Working with multiple git worktrees/branches (uses branch-specific ports/paths) - Demos and presentations


4. Generate-SampleMockData.ps1

Legacy script - creates a single Team Site with basic content.

What it creates: - 1 Site Collection (/sites/plain) - Documents library (1 document, 1 subfolder) - Site Pages library (Home page) - Tasks list (2 items, 1 with attachment) - Term Store with Department terms

When to use: - Compatibility with existing tests that expect /sites/plain - Testing Term Store functionality - Testing attachments


Common Workflows

First Time Setup

# 1. Generate basic data
.\Generate-BasicMockData.ps1

# 2. Start server
cd ../Cesivi.Server
dotnet run

# Server runs on http://localhost:5000 (or branch-specific port)
# One command - ensures data exists and starts server
.\Start-MockServerWithData.ps1

Testing with Fresh Data

# Regenerate and start with basic data
.\Start-MockServerWithData.ps1 -Force

# Regenerate and start with medium data
.\Start-MockServerWithData.ps1 -Force -DataSet Medium

Working with Multiple Branches

The project supports running multiple server instances on different ports using git worktrees. The .branch-config.json file maps branches to ports and data paths.

# Branch: main → Port 5010, Data: ./MockData
# Branch: main1 → Port 5020, Data: ./MockData-main1
# Branch: main2 → Port 5030, Data: ./MockData-main2
# etc.

# Switch to different branch
git checkout main1

# Start server (automatically uses port 5020 and ./MockData-main1)
.\Start-MockServerWithData.ps1

Data Storage Structure

All scripts generate data following SharePoint's hierarchical folder structure:

MockData/
└── WebApplications/
    └── Default/
        ├── settings.json          # Web Application metadata
        └── SiteCollections/
            ├── BasicSite/                      # From Generate-BasicMockData.ps1
            │   ├── settings.json               # Site collection metadata
            │   ├── Users/                      # Site collection users
            │   │   ├── user_1.json            # administrator
            │   │   └── user_2.json            # kenaflow
            │   ├── Groups/                     # SharePoint groups
            │   │   ├── group_3.json           # Site Owners
            │   │   ├── group_4.json           # Site Members
            │   │   └── group_5.json           # Site Visitors
            │   ├── Roles/                      # Role definitions
            │   │   ├── role_1073741825.json   # Full Control
            │   │   ├── role_1073741826.json   # Design
            │   │   ├── role_1073741827.json   # Contribute
            │   │   ├── role_1073741828.json   # Read
            │   │   └── role_1073741829.json   # Limited Access
            │   └── RootWeb/
            │       ├── settings.json           # Web metadata
            │       ├── Lists/
            │       │   └── Test List/          # Custom list
            │       │       └── settings.json   # List metadata with items
            │       └── Libraries/
            │           └── Test Library/       # Document library
            │               ├── settings.json   # Library metadata with items
            │               └── Files/          # Actual file content
            │                   ├── Document1.docx  (13.4 KB)
            │                   ├── Document2.docx  (13.4 KB)
            │                   ├── Report.pdf      (14.8 KB)
            │                   ├── Guide.pdf       (14.8 KB)
            │                   ├── Notes.txt       (88 bytes)
            │                   ├── Readme.txt      (89 bytes)
            │                   ├── Image1.png      (821 bytes)
            │                   ├── Image2.png      (821 bytes)
            │                   ├── Data.txt        (87 bytes)
            │                   └── Summary.pdf     (14.8 KB)
            ├── Intranet/                       # From Generate-MediumMockData.ps1
            ├── Projects/
            └── HR/

Key conventions: - settings.json - Container settings (site collection, web, list, library) - user_{id}.json - User objects (e.g., user_1.json) - group_{id}.json - Group objects (e.g., group_3.json) - role_{id}.json - Role definition objects - Lists and Libraries stored separately at same level under web - Files stored in Libraries/{LibraryName}/Files/ directory - File content includes real binary data (DOCX with embedded sample document, PDF with valid structure, PNG with actual image data) - List items embedded in settings.json (not separate files for small datasets)


Branch Configuration

The .branch-config.json file at the project root defines port and path settings for each branch:

{
  "defaultBranch": "main",
  "branches": {
    "main": {
      "httpPort": 5010,
      "httpsPort": 5011,
      "dataPath": "./MockData",
      "logPath": "./MockData/Logs/Server"
    },
    "main1": {
      "httpPort": 5020,
      "httpsPort": 5021,
      "dataPath": "./MockData-main1",
      "logPath": "./MockData-main1/Logs/Server"
    }
  },
  "fallbackConfig": {
    "httpPort": 5000,
    "httpsPort": 5001,
    "dataPath": "./MockData"
  }
}

Benefits: - Run multiple server instances simultaneously (different worktrees) - Isolated data per branch - No port conflicts - Automatic configuration based on current branch


Environment Variables

The server can be configured via environment variables (useful for Docker, CI/CD):

Variable Description Default
CESIVI_DATA_PATH Root path for mock data ./MockData
CESIVI_HTTP_PORT HTTP port 5000 (or branch config)
CESIVI_HTTPS_PORT HTTPS port 5001 (or branch config)
CESIVI_LOG_PATH Log file directory {DataPath}/Logs/Server
CESIVI_SHOW_CONSOLE Show console window (empty = auto)

Example:

$env:CESIVI_DATA_PATH = "R:/MockData"
$env:CESIVI_HTTP_PORT = 8080
cd Cesivi.Server
dotnet run


Troubleshooting

Port Already in Use

Error: Failed to bind to address http://127.0.0.1:5000

Solution: - Check if another server instance is running - Change port in .branch-config.json or via environment variable - Kill process using the port: netstat -ano | findstr :5000

Mock Data Not Found

Warning: Mock data not found - generating...

Solution: - Let the script generate it automatically - Or manually run Generate-BasicMockData.ps1 first - Check CESIVI_DATA_PATH points to correct location

Permission Denied Writing Files

Error: Access to the path 'C:\...\MockData\...' is denied

Solution: - Run PowerShell as Administrator - Use a path you have write permissions to (e.g., R:/MockData) - Check folder isn't locked by another process

Server Crashes on Startup

Check logs in {DataPath}/Logs/Server/cesivi-{date}.log for details.

Common issues: - Invalid JSON in mock data files - Missing required fields in #settings.json - Corrupted binary files


Advanced Usage

Custom Data Generation

You can modify the scripts to create custom data structures:

# Edit Generate-BasicMockData.ps1
# Change GUIDs, add more lists, modify field schemas, etc.

# Then generate
.\Generate-BasicMockData.ps1 -OutputPath "./MockData-Custom"

Combining Datasets

# Generate basic data
.\Generate-BasicMockData.ps1 -OutputPath "./MockData"

# Generate medium data to same location (adds more site collections)
.\Generate-MediumMockData.ps1 -OutputPath "./MockData"

# Now you have both /sites/basic AND /sites/intranet, /sites/projects, /sites/hr

Automated Testing

# In your test script
$testDataPath = Join-Path $env:TEMP "SPMockTest-$(New-Guid)"
.\Generate-BasicMockData.ps1 -OutputPath $testDataPath

# Start server in background
$env:CESIVI_DATA_PATH = $testDataPath
$env:CESIVI_HTTP_PORT = 9999
$serverProcess = Start-Process -FilePath "dotnet" -ArgumentList "run" `
    -WorkingDirectory "./Cesivi.Server" -PassThru

# Run tests
Invoke-Pester -Path "./Tests"

# Cleanup
Stop-Process $serverProcess
Remove-Item $testDataPath -Recurse -Force

Script Comparison

Feature Basic Medium Sample (Legacy)
Site Collections 1 3 1
Subwebs 0 2 levels 0
Lists 1 4 1
Libraries 1 3 2
Files 10 23 1
Users 2 5 1
Fixed IDs ✅ Yes ❌ No ❌ No
Term Store ❌ No ❌ No ✅ Yes
Best For Unit tests, quick start Integration tests Legacy compatibility


Last Updated: 2025-11-20 Version: 1.0