📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Phase 19 — Testing

Testing .NET 10 systems with confidence: the test types and when each pays off, the .NET testing tools (xUnit, NSubstitute, Testcontainers, WebApplicationFactory), good testing practice, and senior topics such as legacy code, async and time, flaky tests and contract testing.

  1. How do you unit test code that depends on the current time in .NET 10? Explain TimeProvider and FakeTimeProvider, how you test expiry rules, timers and delays deterministically, and the gotchas when a timer continuation runs on another thread.

    Testing time-dependent .NET code with the TimeProvider abstraction and FakeTimeProvider: injecting the clock, advancing virtual time, testing PeriodicTimer and Task.Delay, and avoiding races with asynchronous continuations.

    Mid-Level Coding Senior Testing Topics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. How do you write reliable tests for asynchronous .NET code? Explain awaiting correctly instead of blocking, testing cancellation and timeouts, testing a Channel-based BackgroundService, and the xUnit features and analysers that help.

    Testing async .NET code: async test methods, avoiding .Result and async void, asserting cancellation with ThrowsAnyAsync, timeouts with TestContext.Current.CancellationToken, and testing Channel-driven BackgroundService workers deterministically.

    Mid-Level Coding Senior Testing Topics Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  3. How do you manage test data for a .NET system that handles personal information? Compare test data builders, seeding, masked production copies and synthetic data, and explain how the Privacy Act shapes what you are allowed to use.

    Test data strategy for systems with personal information: object mothers and test data builders, Bogus with fixed seeds, per-test seeding and reset, masked production copies versus synthetic data, and Australian Privacy Act and Notifiable Data Breaches implications.

    Mid-Level Theory Senior Testing Topics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. You inherit a ten-year-old .NET codebase with almost no tests, and you need to change a core billing calculation safely. How do you get it under test? Explain characterisation tests, seams, and the dependency-breaking techniques you would use first.

    Testing legacy .NET code: characterisation (golden master) tests, Michael Feathers' seams, sprout and wrap methods, extract-interface and parameterise-constructor refactorings, snapshotting outputs with Verify, and choosing safe first refactorings.

    Senior Theory Senior Testing Topics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. Your CI pipeline fails about one run in ten with different tests each time, and they all pass locally. Developers have started clicking re-run. How do you diagnose the flaky tests, decide what to quarantine, and fix the root causes?

    Debugging flaky .NET tests: reproducing with repeat runs and constrained resources, classifying causes (time, ordering, shared state, parallelism, async races, external dependencies), xUnit collections and parallelism, blame-hang diagnostics, quarantine policy and permanent fixes.

    Senior Debugging Senior Testing Topics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. How would you set up consumer-driven contract testing between two .NET services with Pact? Show a consumer test and provider verification, explain provider states, and how a Pact Broker and can-i-deploy fit into CI.

    Consumer-driven contract testing in .NET with PactNet: writing consumer tests against the Pact mock server with matchers, verifying the provider against a real host with provider states, and using a Pact Broker, pending pacts and can-i-deploy to gate deployments.

    Senior Coding Senior Testing Topics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. How do you test a distributed .NET system made of several services, queues and databases? What can you test locally and in CI, what can only be tested in production, and how would you run chaos experiments safely?

    Testing distributed .NET systems: component tests with real dependencies in containers, .NET Aspire integration tests, contract tests, asserting eventual consistency, fault injection with Polly chaos strategies and Azure Chaos Studio, and testing in production with synthetic monitoring, canaries and feature flags.

    Senior Theory Senior Testing Topics Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me