Sitecore - Assert.IsNotNull

I saw several examples of sitecore applications that use the following code in business logic:

 Database database = Factory.GetDatabase(itemUri.DatabaseName);
 Assert.IsNotNull(database, itemUri.DatabaseName);
 return database.GetItem(attribute);

Can anyone clarify if this is an agreement with the site. I used only Assert for unit testing scripts, but not within the logic framework.

Thank.

+5
source share
2 answers

This is the convention that heviliy can see in the sitecore.dll file. It is used to throw an exception if this condition is not met.

For example, if you look at Assert.IsTrue, if the condition is not met, the system will throw an "InvalidOperationException"

Decompiling a method from the search API I found this.

  Assert.IsTrue(local_0 != null, "SearchConfiguration is missing");

Then if we decompile IsTrue, it gives us

   [AssertionMethod]
public static void IsTrue([AssertionCondition(AssertionConditionType.IS_TRUE)] bool condition, string message)
{
  if (!condition)
    throw new InvalidOperationException(message);
}

, , , .

assert, , , #.NET. , Sitecore , , .

+5

, . :

  • .NET Sitecore. , Sitecore Assert .
  • Sitecore Asserts . ( Asserts Sitecore Sitecore community ( , NULL.))

, , , , , Sitecore, - , . , ArgumentIsNotNull , , NullObjectException, Assert . , , . Assert , .

+8

All Articles