exam questions

Exam 70-486 All Questions

View all questions & answers for the 70-486 exam

Exam 70-486 topic 3 question 5 discussion

Actual exam question from Microsoft's 70-486
Question #: 5
Topic #: 3
[All 70-486 Questions]

You need to modify the application to meet the product Id requirement.
What should you do?

  • A. Modify the RegisterGlobalFilters method of the Global.asax.cs file as follows.Contract.Assume<ArgumentException>(productId != 0);
  • B. Modify the GetDealPrice method of ProductController as follows.Contract.Requires<ArgumentException>(productId > 0);
  • C. Modify the RegisterGlobalFilters method of the Global.asax.cs file as follows. Contract.Requires<ArgumentException>(productId > 0);
  • D. Modify the GetDealPrice method of ProductController as follows.Contract.Assume<ArgumentException>(productId != 0);
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
Scenario: The value of the product Id property must always be greater than 0.
The GetDealPrice method, in the ProductController, has ProductID as input parameter.
Note: The Contract.Requires(Of TException) method specifies a precondition contract for the enclosing method or property, and throws an exception if the condition for the contract fails.
Syntax:
'Declaration
Public Shared Sub Requires(Of TException As Exception) ( _ condition As Boolean _)

Type Parameters -

TException -
The exception to throw if the condition is false.

Parameters -
condition
Type:

System.Boolean -
The conditional expression to test.
Incorrect:
Not D: The Contract.Assume method instructs code analysis tools to assume that a condition is true, even if it cannot be statically proven to always be true.
Reference: Contract.Requires(Of TException) Method (Boolean)
https://msdn.microsoft.com/en-us/library/dd782896(v=vs.110).aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
markcowell
4 years, 8 months ago
1. Contract.Requires, so only B or C 2. RegisterGlobalFilters method is in FilterConfig.cs in App_Start...So C is not right. But in Global.asax.as, you apply the custom filters by calling FilterConfig.RegisterGlobalFilters method. So, B is the only correct and legitimate answer when there is no better option.
upvoted 2 times
...
rhysabray
5 years, 3 months ago
The requirement is "The value of the product ID property must always be greater than 0". Adding a "Contract.Requires" to a single method that takes in PropertyID as an argument only ensures that PropertyID is > 0 for that method. Not that a PropertyID cannot be set to 0 or less on a product, thus allowing for products with a ProductID of 0 or less when creating instances of Product. Surely you would handle this in the "set" method of the ProductID on the Product class? Or at least create a Global Filter so that instances can be created with a ProductID of <= 0 but cannot be used in any method? .. I could be wrong, just seems like the requirement isn't satisfied.
upvoted 3 times
memou
5 years ago
Agreed,hell make it an auto increment from 1 and call it a day.
upvoted 2 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...