ASP.NET Core MVC Interview Question #175
What are best practices for testing and advanced MVC development?
Testing, AJAX/JavaScript Integration, Localization & Advanced MVC Senior Advanced
Quick Interview Answer
Place most business behavior in testable application/domain services and keep controllers focused on HTTP flow. Use controller unit tests for meaningful action decisions and integration tests for routing, middleware, filters, authentication, model binding, and other pipeline behavior.
Detailed Explanation
Place most business behavior in testable application/domain services and keep controllers focused on HTTP flow. Use controller unit tests for meaningful action decisions and integration tests for routing, middleware, filters, authentication, model binding, and other pipeline behavior.
For dynamic pages, choose partial HTML or JSON according to who owns rendering, and apply normal authorization, validation, CSRF, and XSS protections to JavaScript requests. Use View Components, localization, custom Tag Helpers, binders, validation attributes, and conventions only when they provide clear reusable value. Prefer explicit, maintainable MVC conventions over unnecessary framework customization.
Code Example
// A maintainable MVC action remains small:
[HttpGet]
public async Task<IActionResult> Details(
int id,
CancellationToken token)
{
var model = await _service.GetAsync(id, token);
if (model == null)
return NotFound();
return View(model);
}