Unit 5: ASP.NET Core MVC, Entity Framework Core and Security - Practice Quiz

CSE253 — .Net Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of the middleware request pipeline in ASP.NET Core?

Middleware Request Pipeline Easy
A. To compile Razor views only
B. To store user passwords
C. To process HTTP requests and responses
D. To create database tables

2 In an ASP.NET Core application, middleware components are generally executed in what order?

Middleware Request Pipeline Easy
A. The order in which they are registered
B. Random order for each request
C. Reverse database table order
D. Alphabetical order by class name

3 Which middleware is commonly used to serve static files in ASP.NET Core?

Built-In Middleware and Custom Middleware Easy
A. Database Migration Middleware
B. Entity Framework Middleware
C. Static File Middleware
D. Model Binding Middleware

4 What is custom middleware?

Built-In Middleware and Custom Middleware Easy
A. A compiler setting for controllers
B. A built-in HTML validation rule
C. A database table generated by a model
D. Middleware written for a specific application need

5 What is the main purpose of dependency injection in ASP.NET Core?

Dependency Injection in ASP.NET Core Easy
A. To create browser cookies automatically
B. To provide required objects to classes
C. To convert HTML into SQL
D. To encrypt every database column

6 Where are application services commonly registered for dependency injection?

Dependency Injection in ASP.NET Core Easy
A. In the database connection string
B. In the browser history
C. In the application service container
D. In the CSS stylesheet

7 What is Entity Framework Core primarily used for?

Introduction to Entity Framework Core Easy
A. Working with databases through .NET objects
B. Managing operating system users
C. Creating image files
D. Designing web page colors

8 What does ORM stand for?

Introduction to Entity Framework Core Easy
A. Open Resource Model
B. Object Routing Module
C. Object-Relational Mapper
D. Online Request Manager

9 What is the role of the DbContext class in Entity Framework Core?

DbContext and Entity Configuration Easy
A. It replaces all controller classes
B. It defines the application's visual theme
C. It manages database interaction and entity tracking
D. It handles only browser navigation

10 Which property type in a DbContext usually represents a database table?

DbContext and Entity Configuration Easy
A. IActionResult
B. HttpRequest
C. ViewDataDictionary
D. DbSet<TEntity>

11 What is created first in the Entity Framework Core Code First approach?

Code First Approach Easy
A. The production database backup
B. The SQL server log file
C. The browser user interface
D. The application classes and model

12 Which feature is commonly used to apply Code First model changes to a database?

Code First Approach Easy
A. CSS selectors
B. Razor comments
C. Entity Framework migrations
D. HTTP headers

13 What is the starting point in the Database First approach?

Database First Approach Easy
A. An empty controller
B. An existing database
C. A browser session
D. A CSS framework

14 What is commonly generated from an existing database in the Database First approach?

Database First Approach Easy
A. Entity classes and a DbContext
B. Only HTML images
C. Only CSS variables
D. Only authentication cookies

15 What is the purpose of a database migration in Entity Framework Core?

Database Migrations Easy
A. To compress web page images
B. To format controller source code
C. To record and apply model structure changes
D. To authenticate database users

16 Which command is commonly used to create a new Entity Framework Core migration?

Database Migrations Easy
A. dotnet mvc controller start
B. dotnet web database open
C. dotnet core schema view
D. dotnet ef migrations add

17 What does the letter C represent in CRUD?

CRUD Operations using Entity Framework Core Easy
A. Create
B. Configure
C. Compile
D. Connect

18 Which method marks a new entity for insertion into the database?

CRUD Operations using Entity Framework Core Easy
A. Remove
B. Find
C. Add
D. Update

19 What does authentication verify?

Authentication and Authorization in Web Applications Easy
A. The size of a database
B. The identity of a user
C. The style of a web page
D. The order of middleware

20 What does authorization determine?

Authentication and Authorization in Web Applications Easy
A. Which CSS file loads first
B. Whether a password is typed quickly
C. How a database is backed up
D. What an authenticated user may access

21 An ASP.NET Core application must log both the incoming request and the outgoing response status. Where should the logging middleware call await next(context)?

Middleware Request Pipeline Medium
A. Only when the response status indicates failure
B. Before writing both request and response logs
C. Between the request log and the response log
D. After writing both request and response logs

22 A middleware component returns a response without invoking the next middleware. What is the effect on the request pipeline?

Middleware Request Pipeline Medium
A. The remaining middleware run in reverse order
B. The request is automatically sent to an MVC controller
C. The pipeline restarts from the first middleware
D. The remaining middleware components are skipped

23 An application should serve files from wwwroot without routing those requests through MVC controllers. Which built-in middleware should be added?

Built-In Middleware and Custom Middleware Medium
A. app.UseAuthorization()
B. app.UseRouting()
C. app.UseStaticFiles()
D. app.UseExceptionHandler()

24 A conventional custom middleware class receives a RequestDelegate through its constructor. Which method signature allows ASP.NET Core to execute it?

Built-In Middleware and Custom Middleware Medium
A. Task InvokeAsync(HttpContext context)
B. IResult HandleAsync(HttpResponse response)
C. Task ExecuteAsync(HttpRequest request)
D. void Configure(HttpContext context)

25 A service stores information that must be shared within one HTTP request but isolated from other requests. Which lifetime should be used?

Dependency Injection in ASP.NET Core Medium
A. Singleton
B. Scoped
C. Transient
D. Static

26 A controller constructor requires IEmailSender, but no implementation has been registered. What normally happens when ASP.NET Core tries to create the controller?

Dependency Injection in ASP.NET Core Medium
A. The parameter receives a null value
B. A default implementation is generated
C. Service resolution throws an exception
D. The controller is created without its constructor

27 A queried entity is modified in memory and SaveChangesAsync() is called without explicitly calling Update. Why can Entity Framework Core persist the modification?

Introduction to Entity Framework Core Medium
A. The change tracker detects modified property values
B. The LINQ query immediately updates the database
C. The entity class executes an implicit SQL command
D. The database compares every table row automatically

28 The same EF Core model must run against SQL Server in production and SQLite during local testing. Which EF Core feature primarily enables this?

Introduction to Entity Framework Core Medium
A. Automatic controller discovery
B. Replaceable database providers
C. Razor view compilation
D. Middleware environment branches

29 A Blog has many Post entities, and every Post has one required Blog. Which Fluent API configuration best represents this relationship?

DbContext and Entity Configuration Medium
A. HasMany(b => b.Posts).WithOne(p => p.Blog).IsRequired()
B. HasMany(b => b.Posts).WithMany(p => p.Blog).IsRequired()
C. HasOne(b => b.Posts).WithMany(p => p.Blog).IsRequired()
D. HasOne(b => b.Posts).WithOne(p => p.Blog).IsRequired()

30 An entity property must map to a database column named product_code and have a maximum length of 20. Where can both rules be configured centrally?

DbContext and Entity Configuration Medium
A. In OnModelCreating using the Fluent API
B. In Program.cs using endpoint routing
C. In SaveChanges using change tracking
D. In the controller using model binding

31 In a Code First project, a developer adds a required Email property to the Customer entity. What should normally be done to apply this model change to the database?

Code First Approach Medium
A. Rescaffold all entities from the database
B. Modify only the MVC controller and restart
C. Create a migration and update the database
D. Delete the DbContext and rebuild the project

32 A Code First model uses a property named CustomerId in the Customer class without explicit key configuration. How does EF Core usually treat this property?

Code First Approach Medium
A. As the primary key by convention
B. As an optional foreign key by convention
C. As a computed column by convention
D. As an ignored property by convention

33 A team has an existing SQL Server database and needs to generate EF Core entity classes and a DbContext. Which command is appropriate?

Database First Approach Medium
A. dotnet ef database update
B. dotnet ef dbcontext scaffold
C. dotnet ef migrations add
D. dotnet ef migrations script

34 A developer needs to add custom behavior to a scaffolded entity while allowing the entity to be regenerated later. Which approach best protects the custom code?

Database First Approach Medium
A. Move the behavior into the migration snapshot
B. Add the behavior directly to the generated file
C. Store the behavior in the database connection string
D. Add the behavior in a separate partial class

35 A migration has been created locally but has not been applied or shared. The developer discovers that it is incorrect. Which command is most appropriate for removing it?

Database Migrations Medium
A. dotnet ef migrations remove
B. dotnet ef migrations list
C. dotnet ef dbcontext optimize
D. dotnet ef database drop

36 A production administrator needs a reviewable SQL script containing database changes between two migrations. Which command should the developer use?

Database Migrations Medium
A. dotnet ef dbcontext scaffold
B. dotnet ef migrations script
C. dotnet ef database update
D. dotnet ef migrations add

37 A read-only product listing loads thousands of rows and does not modify them. Which query is generally more efficient?

CRUD Operations using Entity Framework Core Medium
A. context.Products.RemoveRange().ToListAsync()
B. context.Products.AsNoTracking().ToListAsync()
C. context.Products.UpdateRange().ToListAsync()
D. context.Products.AddRange().ToListAsync()

38 A controller must delete an order only when it exists. Which sequence correctly performs the operation?

CRUD Operations using Entity Framework Core Medium
A. Find the order, call Remove, then call SaveChangesAsync
B. Find the order, call Add, then call SaveChangesAsync
C. Create a migration, remove the entity, then scaffold the context
D. Query the order with AsNoTracking, then call AddRange

39 An ASP.NET Core application uses cookie authentication and protected endpoints. Which middleware order is required after routing and before endpoint execution?

Authentication and Authorization in Web Applications Medium
A. UseStaticFiles() followed by UseAuthentication()
B. UseAuthorization() followed by UseAuthentication()
C. UseAuthentication() followed by UseAuthorization()
D. UseExceptionHandler() followed by UseAuthorization()

40 An action should be accessible only to authenticated users who satisfy a policy named CanApproveOrders. Which attribute is appropriate?

Authentication and Authorization in Web Applications Medium
A. [Authorize(Role = "CanApproveOrders")]
B. [Authorize(Policy = "CanApproveOrders")]
C. [AllowAnonymous(Policy = "CanApproveOrders")]
D. [ValidateAntiForgeryToken(Policy = "CanApproveOrders")]

41 In an ASP.NET Core application, middleware is registered in this order: UseExceptionHandler, UseStaticFiles, UseRouting, UseAuthentication, UseAuthorization, and MapControllers. A controller throws an exception while executing an authorized action. Which component can reliably handle the exception?

Middleware Request Pipeline Hard
A. UseStaticFiles
B. UseAuthorization
C. UseRouting
D. UseExceptionHandler

42 A middleware executes code before and after await _next(context). A later middleware short-circuits the request and never calls its own next delegate. Which behavior is expected?

Middleware Request Pipeline Hard
A. The current middleware is skipped automatically
B. The current before-code and after-code both execute
C. Only the current middleware's before-code executes
D. The after-code executes before the short-circuiting middleware

43 A custom middleware needs to redirect unauthenticated requests to /login, but must allow static assets and the login endpoint through. Which placement is most appropriate?

Built-In Middleware and Custom Middleware Hard
A. After MapControllers and before Run
B. Before UseStaticFiles and before UseRouting
C. Inside UseExceptionHandler after the exception branch
D. After UseStaticFiles and before endpoint execution

44 A custom middleware stores a request-specific correlation identifier in an instance field of the middleware class. Under concurrent requests, what is the primary defect?

Built-In Middleware and Custom Middleware Hard
A. The middleware is forced into scoped lifetime
B. The identifier cannot be added to response headers
C. The middleware cannot access HttpContext
D. The field may be overwritten by another request

45 A singleton service directly depends on a scoped DbContext. What is the correct assessment of this dependency graph?

Dependency Injection in ASP.NET Core Hard
A. It is valid only when the context uses no tracking
B. It is invalid only when the application uses multiple databases
C. It is invalid because a singleton captures a shorter-lived dependency
D. It is valid because the singleton resolves the context per method call

46 A controller constructor requests IEnumerable<INotificationHandler>. Three handlers are registered, and one registration is repeated for the same implementation type. What does the default container normally inject?

Dependency Injection in ASP.NET Core Hard
A. Only the last registered handler
B. All registered descriptors in registration order
C. Only the first registered handler
D. A single composite handler created automatically

47 An EF Core query projects entities into DTOs and uses AsNoTracking(). Later, the application modifies one projected DTO and calls SaveChanges(). What happens?

Introduction to Entity Framework Core Hard
A. No update occurs unless an entity is explicitly attached
B. An update occurs because projections are always tracked
C. EF updates only scalar properties matching DTO names
D. EF automatically tracks and updates the source entity

48 A LINQ query contains a custom C# method inside its Where predicate. EF Core cannot translate that method to SQL. In a modern EF Core version, what is the usual result when the query executes?

Introduction to Entity Framework Core Hard
A. EF throws an exception for unsupported client evaluation
B. The entire table is always loaded before filtering
C. EF silently replaces the method with a constant
D. The method runs automatically on the database server

49 An entity has a property Code configured with IsRequired().HasMaxLength(20), while its database column is manually changed to allow NULL. During migration generation, what does EF Core compare?

DbContext and Entity Configuration Hard
A. The provider's default conventions against SQL metadata
B. The database data against entity instances
C. Only the current database schema
D. The model snapshot against the current model

50 A required one-to-many relationship is configured with a non-nullable foreign key, but the navigation property is not marked virtual and lazy-loading proxies are enabled. What should be expected?

DbContext and Entity Configuration Hard
A. Lazy loading does not occur for the non-virtual navigation
B. Lazy loading works because foreign keys imply proxies
C. Lazy loading works only for required relationships
D. The relationship becomes optional at runtime

51 A Code First model changes a property from string to int while existing rows contain nonnumeric values. A migration is generated successfully. When is the likely failure observed?

Code First Approach Hard
A. Only when an invalid row is queried later
B. During model class compilation
C. During migration creation only
D. When the migration is applied to the database

52 A Code First application uses a non-nullable DateTime property with no explicit database default. A new entity is inserted without setting that property. Which value is generally sent by EF Core?

Code First Approach Hard
A. A value generated from the migration timestamp
B. A NULL value despite the non-nullable property
C. The CLR default value for DateTime
D. The database server's current UTC timestamp

53 A database-first model is scaffolded, then the generated entity class is edited to add validation attributes. The database is scaffolded again. What is the main risk?

Database First Approach Hard
A. The generated context stops tracking entities
B. The database schema is reverted automatically
C. The custom edits may be overwritten
D. The connection string is encrypted permanently

54 A database-first scaffold sees a nullable database column and generates a nullable CLR property. Application code later treats the value as non-nullable without checking it. Which issue is most likely?

Database First Approach Hard
A. Scaffolding automatically adds a required validation rule
B. The provider converts every NULL to zero
C. The compiler or runtime exposes a nullability mismatch
D. EF changes the database column to NOT NULL

55 Two application instances start simultaneously after a new migration has been deployed but not applied. Both call Database.Migrate(). What is the principal operational concern?

Database Migrations Hard
A. The migration history table is ignored by both instances
B. Concurrent migration execution can cause locking or race failures
C. Each instance always creates a different schema
D. The migration runs only in development environments

56 A migration adds a non-nullable column to a populated table without a default value. What must usually be handled for the migration to succeed?

Database Migrations Hard
A. The column must be converted to a primary key
B. The table must be recreated without indexes
C. The migration must disable foreign-key constraints permanently
D. Existing rows must receive a value or the column must be nullable

57 Two requests load the same row with a rowversion concurrency token. Both modify it, and the first request saves successfully. What normally happens when the second request calls SaveChanges()?

CRUD Operations using Entity Framework Core Hard
A. EF merges both property sets automatically
B. EF throws DbUpdateConcurrencyException
C. The second update is ignored without an exception
D. The second update overwrites the first unconditionally

58 A controller receives an entity graph from a client and calls Update(graph) directly. The graph omits a sensitive property that should remain unchanged. What is the major risk?

CRUD Operations using Entity Framework Core Hard
A. EF may mark omitted or defaulted values as modified
B. EF disables concurrency checks for the graph
C. EF refuses to track graphs from HTTP requests
D. EF always converts the graph into an insert

59 An ASP.NET Core application calls UseAuthorization() before UseAuthentication(). An endpoint requires an authenticated user. What is the likely consequence?

Authentication and Authorization in Web Applications Hard
A. Authentication runs automatically after endpoint execution
B. The endpoint becomes anonymous because authorization is disabled
C. Authorization may evaluate before the user is populated
D. Authorization always authenticates using every configured scheme

60 A policy requires claim scope=orders.read. A bearer token contains scope as the single string orders.read orders.write. A simple claim-value equality requirement is used. What is the likely result?

Authentication and Authorization in Web Applications Hard
A. The requirement succeeds only for cookie authentication
B. The requirement fails because the value is one claim string
C. The requirement succeeds because token scopes are always split
D. The requirement fails because scope claims cannot be authorized