C# - C Sharp: PRN232-PT1


Khóa học qua video:
Lập trình Python All Lập trình C# All SQL Server All Lập trình C All Java PHP HTML5-CSS3-JavaScript
Đăng ký Hội viên
Tất cả các video dành cho hội viên

(nhấn nút 'Result' để biết kết quả)

Q1: Which of the following best describes a model in ASP.NET Web API?
A database table
A class representing application data
A controller action
A routing configuration

Q2: In Web API, models are typically used to:
Define routing rules
Represent and transfer data
Configure middleware
Authenticate users

Q3: Where are model classes usually stored in an ASP.NET Core Web API project?
Controllers folder
Models folder
Views folder
Startup.cs

Q4: What is model binding in Web API?
Mapping HTTP requests to controllers
Mapping data from HTTP requests to action method parameters
Converting controllers into views
Binding database entities to controllers

Q5: Which attribute is used for input validation in a model?
[Route]
[HTTPGet]
[Required]
[ApiController]

Q6: What does the [Range] attribute do in model validation?
Ensures a string is not empty
Restricts a numeric value to a specified range
Validates a regular expression
Converts a model to JSON

Q7: What happens if a model validation fails in Web API?
The request is ignored
The controller executes normally
A 400 Bad Request response is returned
A 500 Internal Server Error is thrown

Q8: Which property in a controller contains model validation errors?
Request.Errors
ModelState
ErrorList
ValidationContext

Q9: What is the default response when ModelState is invalid in ASP.NET Core Web API with [ApiController]?
200 OK
201 Created
400 Bad Request with validation details
500 Internal Server Error

Q10: Which namespace contains data annotations for models?
System.Web.Mvc
Microsoft.AspNetCore.Routing
System.ComponentModel.DataAnnotations
Microsoft.EntityFrameworkCore

Q11: Which attribute ensures a string has a maximum length?
[StringLength]
[Max]
[Required]
[MinLength]

Q12: What is the purpose of [Bind] attribute?
Restricts which properties of a model can be bound from request data
Creates a binding between two controllers
Forces a model to be required
Configures dependency injection

Q13: In Web API, a Data Transfer Object (DTO) is used to:
Replace the database model entirely
Optimize data sent to clients
Encrypt model properties
Configure controllers

Q14: Why use DTOs instead of models directly?
To expose all database fields
To avoid exposing sensitive data and reduce payload
To enable routing
To generate API documentation

Q15: Which of the following is true about model binding?
It only works with JSON data
It supports multiple sources like query string, body, headers
It can only bind integers
It works only with GET requests

Q16: Which attribute specifies the property must match a regex pattern?
[StringLength]
[Range]
[RegularExpression]
[Validate]

Q17: Which action parameter keyword explicitly binds data from the request body?
[FromQuery]
[FromBody]
[FromHeader]
[FromRoute]

Q18: Which keyword explicitly binds a parameter from the query string?
[FromQuery]
[FromBody]
[FromHeader]
[FromRoute]

Q19: What does [FromRoute] attribute do?
Binds parameter from query string
Binds parameter from route data
Binds parameter from request body
Binds parameter from headers

Q20: Which of the following can be used to implement custom validation?
IRouteHandler
IValidatableObject
IActionResult
IHttpActionResult

Q21: What is the default behavior if multiple sources can bind a parameter?
The request fails
Body binding always wins
Binding source precedence is applied
The last parameter wins

Q22: Which of the following ensures a field is not null or empty?
[MaxLength]
[Required]
[Range]
[Bind]

Q23: What does the [ApiController] attribute enable automatically?
Database migrations
Automatic model validation responses
JSON encryption
Custom exception handling

Q24: Which type is returned by ModelState.IsValid?
int
string
bool
object

Q25: What does Fluent Validation provide compared to DataAnnotations?
SQL queries
Strongly typed, extensible validation rules
Automatic routing
Encryption of models

Q26: In Web API, complex types are bound from:
Query strings only
Request body by default
Route values only
Response headers

Q27: Which tool can generate client code from Web API models?
Swagger (OpenAPI)
Entity Framework
IIS
MVC Scaffolding

Q28: Which attribute controls the minimum string length of a property?
[MinLength]
[StringLength]
[Required]
[Range]

Q29: Which of the following is NOT a model binding source?
Route data
Query string
Request body
Server memory cache

Q30: Which statement about model binding in Web API is true?
Only primitive types can be bound
Binding automatically handles JSON and XML
Binding requires manual parsing
Binding only works in MVC, not Web API

Q31: What is a Media Formatter in Web API?
A tool for configuring routes
A component for serializing and deserializing data
A middleware for authentication
A database connector

Q32: Which of the following is a built-in formatter in Web API?
CSV formatter
YAML formatter
JSON formatter
Binary formatter

Q33: Which header is used for content negotiation?
Host
Accept
Authorization
Content-Length

Q34: What does content negotiation determine?
Which controller is executed
The format of the response returned
The route template
The database query executed

Q35: Which header specifies the format of request body?
Accept
Content-Type
Host
Cache-Control

Q36: Default media type for JSON formatter is:
application/json
text/plain
application/xml
text/json

Q37: Default media type for XML formatter is:
application/json
application/xml
text/xml
both B and C

Q38: If no Accept header is specified, Web API defaults to:
XML
JSON
HTML
Plain text

Q39: Which namespace contains MediaTypeFormatter class?
Microsoft.AspNetCore.Http
System.Net.Http.Formatting
Microsoft.Extensions.DependencyInjection
System.Text.Json

Q40: Which formatter uses System.Text.Json or Newtonsoft.Json internally?
JSON formatter
XML formatter
BSON formatter
HTML formatter

Q41: Which formatter uses DataContractSerializer or XmlSerializer?
JSON formatter
XML formatter
CSV formatter
BSON formatter

Q42: Which of the following can be used to implement custom media formatters?
Inheriting from MediaTypeFormatter
Modifying appsettings.json
Using [Bind] attribute
Adding middleware

Q43: Which property in HttpRequestMessage specifies media type of request body?
Content.Headers.ContentType
Request.Headers.Accept
Request.ContentType
Request.Encoding

Q44: Which property in HttpResponseMessage defines response media type?
Headers.Accept
Content.Headers.ContentType
ResponseType
Output.ContentType

Q45: Content negotiation is handled by:
Routing middleware
Model binder
IContentNegotiator
IHttpHandler

Q46: Which is TRUE about content negotiation?
It only works for JSON
It considers Accept header and formatters
It requires custom middleware
It always returns XML

Q47: If Accept: application/xml is sent but XML formatter is removed, what happens?
Returns XML
Returns JSON instead
Returns CSV
Request fails automatically

Q48: How to force a Web API method to return JSON regardless of Accept header?
Return JsonResult
Add [Produces("application/json")] attribute
Change Accept header
Use [Bind] attribute

Q49: How to force return XML regardless of Accept header?
Use [Produces("application/xml")]
Modify Startup.cs
Return ViewResult
Disable JSON formatter

Q50: Which class selects a formatter during negotiation?
MediaTypeFormatterSelector
ModelBinder
JsonSerializerOptions
HttpContext

Q51: What is the default character encoding for JSON responses in Web API?
ASCII
UTF-8
UTF-16
Latin-1

Q52: Which tool is commonly used to test content negotiation?
IIS
Postman
Entity Framework
NuGet

Q53: Which of the following is NOT a valid content type?
application/json
application/xml
application/html
text/plain

Q54: In ASP.NET Core, which method registers XML formatters?
services.AddXmlSerializerFormatters()
services.AddXml()
app.UseXml()
config.EnableXml()

Q55: How can you support both JSON and XML in an API?
Add both formatters to configuration
Use only JSON formatter
Use only XML formatter
Set Content-Type header

Q56: If the client sends Accept: */*, what does the server return?
Always JSON
Always XML
Chooses based on server defaults
Request fails

Q57: Which HTTP header communicates the format of response body?
Content-Type
Accept
Authorization
User-Agent

Q58: What is the function of JsonMediaTypeFormatter?
Convert JSON data to/from .NET objects
Compress JSON data
Validate JSON schema
Encrypt JSON payload

Q59: Which of the following is TRUE about custom formatters?
They must inherit from MediaTypeFormatter
They cannot support multiple media types
They are only for XML
They cannot handle deserialization

Q60: Why is content negotiation important in Web API?
To choose the best authentication method
To decide routing rules
To return responses in a format the client understands
To configure dependency injection

(Ghi chú: Phần câu hỏi Qi có màu Green thể hiện đáp án đúng)

(Ghi chú: Phần câu hỏi Qi có màu Green thể hiện đáp án đúng)
» Tiếp: Practical 1
« Trước: Bài tập phần Windows Forms
Khóa học qua video:
Lập trình Python All Lập trình C# All SQL Server All Lập trình C All Java PHP HTML5-CSS3-JavaScript
Đăng ký Hội viên
Tất cả các video dành cho hội viên
Copied !!!