Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 24 of 30
❮Prev Next❯

Generate Sample Data and Modernize Legacy Code with Copilot

Module 5: Productivity ⏱ 9 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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.

    Simulate it » No Azure account needed

    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.

    VS Code & GitHub: Modernize legacy code and generate sample data Explain legacy code, modernize it and generate fake data.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading…

    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
    1. Start with /explain on the legacy file so you understand it before changing it.
    2. 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.
    3. 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.

    😟 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
    🛠️ Solved with: Legacy code + sample 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 forWhy
    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 typeField names and types match your code
    Clearly fake valuesexample.com emails, “Test Customer” names, made-up IDs
    Edge cases on purposeEmpty lists, zero, very large numbers, unusual characters
    A generator for big volumesFor 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:

    1. Understand it. Select the file and run /explain. Ask follow-ups: who calls it, what happens with an empty array, any hidden side effects.
    2. Pin the behaviour. Ask for characterization tests that capture the current output, including odd cases. Run them against the old code; they must pass.
    3. Modernize in small steps. “Convert to an ES module with the same CSV output.” Then, separately, “update the two callers”.
    4. Let agent mode do the legwork. It can find callers, edit them and run npm test after you approve the command, then fix failures it sees.
    5. 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

    Online retail

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    A developer needs realistic order records for unit tests. The records must not contain personal information. How should the developer use GitHub Copilot?

    Question 2

    Question 2 of 5

    A developer is assigned to modernize a legacy JavaScript module that has no documentation and no tests. What should the developer do first?

    Question 3

    Question 3 of 5 · Select 2

    A team uses GitHub Copilot to convert a callback-based Node.js module to async/await. Which TWO practices reduce the risk of introducing defects?

    Question 4

    Question 4 of 5

    A developer uses GitHub Copilot to translate business logic from an older, rarely used programming language to C#. The translated code compiles. What should the developer consider before deploying it?

    Question 5

    Question 5 of 5

    A developer wants GitHub Copilot to modernize a legacy report module, update the two files that call it, and run the test suite, with the developer approving terminal commands. Which Copilot Chat mode should the developer use?

    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. 1.Which slash command helps you understand a legacy file?Show

      /explain

    2. 2.What kind of email domain should fake data use?Show

      example.com (a reserved example domain).

    3. 3.What tests should you write before modernizing?Show

      Characterization tests that capture current behaviour.

    4. 4.Which chat mode can update callers and run tests?Show

      Agent mode.

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.