Home » Microsoft » 70-486 v.2 » What should you do?
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);
Correct Answer: B
Explanation/Reference:
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