Generate Sample Data and Modernize Legacy Code with Copilot
30-second answer
For sample data, ask Copilot for the exact shape you need (JSON, CSV, SQL inserts) with clearly fake values such as example.com emails and "Test Customer" names, and never paste real customer data into a prompt. For legacy code, start with /explain so you understand what it does, add tests that pin the current behaviour, then ask Copilot to modernize it in small steps that keep the same output. Agent mode can update callers and run the tests for you after you approve. Copilot can also translate between languages, but it's weaker on rare or old languages, so review and test every change.
Exam objective: 5.1.3 Generate sample data and modernize legacy code. (Skills measured as of August 7, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Start with <strong>/explain</strong> on the legacy file so you understand it before changing it.
👆 Click the glowing item on screen to continue
Read the steps as text
- Start with /explain on the legacy file so you understand it before changing it.
- Ask for the same output in modern code, and let agent mode update the callers and run the tests. Keep changes small so they’re easy to review.
- Copilot is handy for sample data for tests and demos. Ask for clearly fake values (example.com, test names), and never paste real customer data into a prompt.
🧪 Simulation for learning. Screens are simplified versions of Visual Studio Code and github.com with GitHub Copilot; names, files and suggestions are examples. Not affiliated with GitHub or Microsoft, and nothing here touches your real account.
🖱️ Drag to rotate · scroll or pinch to zoom
Agent mode
Agent works out which files to touch, edits them, runs commands and tests, reads errors and keeps going until the task is done. It asks before running terminal commands unless you’ve approved them.
🤔 What happens if…
Read this tour as text
- Ask mode. Ask answers questions about code and concepts and can suggest code blocks. It doesn’t change your files by itself.
- Edit mode (Copilot Edits). Edit applies changes to the files you choose, across several files at once. You see each diff and Keep or Undo it.
- Agent mode. Agent works out which files to touch, edits them, runs commands and tests, reads errors and keeps going until the task is done. It asks before running terminal commands unless you’ve approved them.
- MCP servers add tools. The Model Context Protocol (MCP) lets Copilot use external tools: the GitHub MCP server, a browser, a docs search or your own API. Configure servers in
.vscode/mcp.json(VS Code) or with/mcp(CLI). Organizations can restrict which servers are allowed. - Sessions and sub-agents. Long tasks fill the context window. Agent sessions keep work separate, and a sub-agent can do a side task in its own context and hand back only a summary.
- Copilot coding agent. Assign an issue to Copilot on github.com (or
/delegatefrom the CLI). The coding agent works in a GitHub Actions environment on its own branch and opens a draft pull request with its changes. - Review stays human. You review the agent’s PR like any other. Copilot code review can comment and suggest changes, but its review doesn’t count as an approval. A person merges.
- Copilot CLI. The same agent in the terminal:
copilotfor a session with slash commands,copilot -p "…"for one prompt, and--allow-tool/--deny-toolto control what it may run.
A free terminal with GitHub Copilot CLI, git and gh. No tasks: install the CLI, start a session, try slash commands and tool permissions, or call the seats API.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
A 2014 module still runs payroll reports and nobody understands it.
😊 THE SOLUTION
Use Copilot to explain, modernize and test legacy code, and to make fake data.
- Old syntax and callbacks✓ Modernize, same output
- Nobody knows what it does✓ /explain first
- No safe test data✓ Generated fake data
Start with a question
Would you rewire a house you'd never seen, with no plan, while people still lived in it?
That’s what touching legacy code feels like. contoso-shop still runs src/legacy/report.js, written in 2014. It uses var, string concatenation in a loop and a Node-style callback. Nobody on the team wrote it, and the finance department relies on its CSV every morning.
Meena didn’t start by asking Copilot to rewrite it. She asked /explain first, wrote two tests that captured today’s exact output, and only then asked agent mode to “modernize report.js to an ES module, keep the same output, and update the callers”. The tests passed, the diff was twelve lines, and finance never noticed a thing. That’s the goal.
Explain it like I’m 10
The technical explanation
Generate sample data
Copilot is quick at producing data shaped like your real data:
Generate 5 sample orders as JSON matching #file:src/types/order.js.
Fake data only: "Test Customer N" names, customerN@example.com emails,
totals between 50 and 5000, one order with an empty items array.
What makes a good sample data prompt:
| Ask for | Why |
|---|---|
The exact format (JSON, CSV, SQL INSERT) | So you can drop it straight into a test or seed script |
The schema, via #file or a type | Field names and types match your code |
| Clearly fake values | example.com emails, “Test Customer” names, made-up IDs |
| Edge cases on purpose | Empty lists, zero, very large numbers, unusual characters |
| A generator for big volumes | For thousands of rows, ask for a script using a fake-data library instead of pasting rows |
The rule that matters most: never paste real customer or employee data into a prompt to “show the shape”. Give the schema or one invented example. Using fake data is one of the responsible-AI mitigations the exam expects you to know.
Modernize legacy code
Here’s the before:
// 2014 code, still in production
var report = function (rows, cb) {
var out = '';
for (var i = 0; i < rows.length; i++) {
out = out + rows[i].name + ',' + rows[i].total + '\n';
}
cb(null, out);
};
module.exports = report;
And a safe path to the after:
- Understand it. Select the file and run
/explain. Ask follow-ups: who calls it, what happens with an empty array, any hidden side effects. - Pin the behaviour. Ask for characterization tests that capture the current output, including odd cases. Run them against the old code; they must pass.
- Modernize in small steps. “Convert to an ES module with the same CSV output.” Then, separately, “update the two callers”.
- Let agent mode do the legwork. It can find callers, edit them and run
npm testafter you approve the command, then fix failures it sees. - Review every diff and keep the tests in the repo.
// Modernized with Copilot: same CSV output as before
export function report(rows) {
return rows.map((r) => `${r.name},${r.total}`).join('\n') + '\n';
}
Notice the + '\n' at the end. The old code added a newline after every row, including the last. Without the characterization test, a “cleaner” version would drop it and the finance import could break.
Translating between languages
Copilot can translate code, for example COBOL to Java or VB6 to C#, and explain old idioms along the way. Treat that output with extra care. Models see far less code in older or rarer languages, so suggestions are less reliable, and details such as rounding, integer division, date handling and character encoding can change silently. Tests built from the old system’s outputs are your safety net.
Architect level Why small steps beat one big rewrite
Each Copilot request works within a limited context window. A 3,000-line file asked to “modernize everything” means the model can’t see all of it at once in detail, and you get a huge diff that nobody reviews properly. Small steps keep each request focused, keep each diff readable, and let the tests catch a mistake right where it was introduced. In agent mode, a long task also fills the session’s context; splitting the work, or letting a sub-agent do research in its own context, keeps answers sharp.
Real-world business scenario
Contoso (fictional)
- The problem
- contoso-shop's legacy reporting module blocked an upgrade to ES modules. Developers avoided it because it had no tests, and they'd been copying real order exports into test fixtures.
- What they used
- Copilot Chat /explain for each legacy file, characterization tests generated and reviewed, agent mode to modernize one file at a time and update callers, and Copilot-generated fake fixtures with example.com emails.
- Why that choice
- The tests proved each change kept the same output, small steps kept diffs reviewable, and fake fixtures removed real customer data from the repo.
- The result
- The module moved to ES modules over two sprints with no change in the finance CSV, and the real-data fixtures were deleted from the repository.
When to use it and when not to
✓ Use it when…
- Fake data for tests, demos and seed scripts in a precise shape.
- Explaining legacy code you didn't write before changing it.
- Modernizing in small steps, backed by tests that pin current behaviour.
✕ Think twice when…
- Pasting real personal or customer data into a prompt, even to show the format.
- A one-shot rewrite of a large untested module.
↔ Alternatives to consider
- A fake-data library in a script when you need thousands of rows repeatably.
- Copilot coding agent for a well-scoped modernization issue delivered as a draft pull request you review.
Test yourself with exercises
5 original practice questions in the GH-300 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner How would you get test data from Copilot?
Model answer
I'd say exactly what I need, like "10 sample orders as JSON with id, customer, email and total, fake data only, example.com emails". I'd point it at the type or schema with #file so the fields match, and check the result before using it.
Interviewer follows up
Can you give Copilot a few real rows so it gets the shape right?
You
Not real ones. I'd give it the schema or one made-up example instead. Real customer data doesn't belong in a prompt.
Intermediate What's your first step before modernizing a legacy file with Copilot?
Model answer
Understand it. I run /explain on the file, ask what calls it, and write characterization tests that capture today's output, including the odd cases. Only then do I ask for the rewrite, so the tests tell me if behaviour changed.
Experienced developer Your team wants to convert a 3,000-line callback-based module to async/await with agent mode in one go. What do you advise?
Model answer
Break it up. One function or one file per change, with tests running after each step, and a diff small enough to review. A single huge edit is hard to review and easy to break. Agent mode is great for updating callers and re-running tests, but each step should still be reviewable.
Scenario Copilot's translation of an old VB6 routine to C# compiles but gives different totals. What happened and what now?
Model answer
Copilot's suggestions are less reliable for older, rarer languages, and subtle things like rounding or integer division can change in translation. I'd write tests from the old system's real outputs (with fake inputs), run the new code against them, and fix the differences one by one.
Quick revision
Key points
- Ask for sample data in an exact shape, pointing Copilot at the schema or type.
- Use clearly fake values (example.com, test names); never put real personal data in a prompt.
- Legacy first step: /explain, then characterization tests that pin current behaviour.
- Modernize in small steps that keep the same output, reviewing each diff.
- Agent mode can update callers and run tests after you approve commands.
- Copilot is weaker on rare or old languages, so translations need careful testing.
Important terminology
- Sample data
- Made-up records used for tests, demos and development, shaped like real data but containing no real personal information.
- Legacy code
- Older code still in production, often without tests or documentation, written with outdated language features or frameworks.
- Characterization test
- A test that records what existing code currently does, so you can tell if a rewrite changes its behaviour.
- Modernization
- Updating old code to current language features, libraries or frameworks while keeping its behaviour.
- example.com
- A domain reserved for documentation and examples, safe to use in fake email addresses.
Common mistakes
- Pasting production records into chat to get realistic test data.
- Rewriting legacy code before understanding or testing it.
- Asking for one giant modernization change instead of small reviewable ones.
Exam tips
- "Create test data without exposing personal information" = ask for fake/synthetic data.
- "Understand old code before changing it" = /explain.
- "Make sure the modernized code behaves the same" = tests first, small steps, review diffs.
Five quick revision questions
-
1.Which slash command helps you understand a legacy file?Show
/explain
-
2.What kind of email domain should fake data use?Show
example.com (a reserved example domain).
-
3.What tests should you write before modernizing?Show
Characterization tests that capture current behaviour.
-
4.Which chat mode can update callers and run tests?Show
Agent mode.
-
5.Why test translations from older languages extra carefully?Show
Copilot is less reliable on rare or older languages.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Unit Tests, Integration Tests and Edge Cases
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.