sitecore
진단 : 주장
수색…
통사론
- Assert.ArgumentCondition (부울 조건, 문자열 argumentName, 문자열 메시지)
- Assert.ArgumentNotNull (객체 인수, 문자열 argumentName)
- Assert.ArgumentNotNull (개체 인수, Func <string> getArgumentName)
- Assert.ArgumentNotNullOrEmpty (ID 인수, string argumentName)
- Assert.ArgumentNotNullOrEmpty (문자열 인수, 문자열 argumentName)
- Assert.ArgumentNotNullOrEmpty (문자열 인수, Func <문자열> getArgumentName)
- Assert.AreEqual (int value1, int value2, string message)
- Assert.AreEqual (int value1, int value2, string 형식, params 객체 [] args)
- Assert.AreEqual (문자열 값 1, 문자열 값 2, 문자열 메시지)
- Assert.AreEqual (문자열 값 1, 문자열 값 2, 문자열 형식, params 객체 [] args)
- Assert.AreEqual (bool 값 1, bool 값 2, 문자열 메시지)
- Assert.AreEqual (bool 값 1, bool 값 2, 문자열 형식, params 객체 [] args)
- Assert.CanRunApplication (문자열 응용 프로그램)
- Assert.HasAccess (bool accessAllowed, 문자열 메시지)
- Assert.HasAccess (부울 accessAllowed, 문자열 형식, params 객체 [] args)
- Assert.IsEditing (항목 항목)
- Assert.IsFalse (부울 조건, 문자열 메시지)
- Assert.IsFalse (부울 조건, Func <문자열> getMessage)
- Assert.IsTrue (부울 조건, 문자열 형식, params 객체 [] args)
- Assert.IsNotNull (객체 값, 문자열 메시지)
- Assert.IsNotNull (객체 값, 문자열 형식, params 객체 [] args)
- Assert.IsNotNull (객체 값, 유형 유형)
- Assert.IsNotNull (객체 값, 유형 유형, 문자열 형식, params 객체 [] args)
- Assert.IsNotNullOrEmpty (문자열 값, 문자열 메시지)
- Assert.IsNotNullOrEmpty (문자열 값, 문자열 형식, params 객체 [] args)
- Assert.IsNull (객체 값, 문자열 메시지)
- Assert.IsNull (객체 값, 문자열 형식, params 객체 [] args)
- Assert.IsTrue (bool 상태, 문자열 메시지)
- Assert.IsTrue (부울 조건, Func <문자열> getMessage)
- Assert.IsTrue (부울 조건, 문자열 형식, params 객체 [] args)
- Assert.Required (객체 obj, 문자열 메시지)
- Assert.Required (객체 obj, 문자열 형식, params 객체 [] args)
- Assert.ResultNotNull <T> (T 결과, 문자열 메시지)
- Assert.ResultNotNull <T> (T 결과)
두 값이 같은지 확인하십시오.
두 값이 동일한 지 비교합니다. 문자열, 정수 및 부울 값만 비교할 수 있습니다.
Assert.AreEqual(documentElement.LocalName, "xamlControls", "Xaml files must have a root node named 'xamlControls'.");
값이 true 또는 false인지 확인하십시오.
값이 true 또는 false임을 주장하려면 다음을 수행하십시오.
Assert.IsFalse(Settings.DoBadThings, "Bad things should not happen, disable DoBadThings.");
Assert.IsTrue(magicNumber =< 42, "The magic number is greater than 42!");
예외 메시지에 대한 서식 지정 매개 변수를 전달할 수도 있습니다
Assert.IsFalse(myValue > 5, "The value should not be greater than 5, it's currently {0}", myValue);
ResultNotNull
ResultNotNull()
은 전달 된 객체가 null이 아닌지를 검사합니다. 오브젝트와 메세지가 null가 아닌 경우는, 건네받은 오브젝트를 돌려 InvalidOperationException
, 그렇지 않은 경우는 InvalidOperationException
를 Throw InvalidOperationException
.
return Assert.ResultNotNull(this.Database.GetItem(this.ItemRootId), string.Concat("Root item not found. ID: ", this.ItemRootId));
필수 개체
지정된 객체가 null인가 어떤가를 판정 해, 그 경우에 RequiredObjectIsNullException
를 Throw합니다.
Assert.Required(parameter, "parameter is required.");
Null / Empty 체크
IsNotNull
이는 항목이 null이 아닌지 확인하는 데 매우 간단하고 널리 사용되는 방법입니다. 전달 된 객체를 검사하여 null인지 확인합니다.
Assert.IsNotNull(database, type, "Name: {0}", item);
IsNotNullOrEmpty
위의 IsNotNull과 동일하지만 객체 대신 문자열 값에서 작동합니다.
Assert.IsNotNullOrEmpty(propertyName, "user");
IsNull
이것은 단순히 IsNotNull()
메서드의 반대입니다. 이 메서드는 객체가 null임을 나타냅니다.
Assert.IsNull(this.StandardValues, "A Standard Values item has already been created for this template ");
인수 검사
ArgumentCondition
이 메소드는 지정된 인수가 true인지 확인합니다. 또한 조건이 실패 할 경우 기록되는 인수의 이름을 사용합니다.
Assert.ArgumentCondition(pageIndex >= 0, "pageIndex", "Value must be greater than or equal to zero.");
ArgumentNotNull
이 메서드는 전달 된 인수가 null이 아닌지 확인합니다. 이 방법에는 두 가지 서명이 있습니다. 첫 번째는 객체와 매개 변수 이름을 가져 와서 간단한 null 확인을 수행합니다.
Assert.ArgumentNotNull(item, "item");
ArgumentNotNullOrEmpty
이것은 ArgumentNotNull 메서드와 비슷하지만 개체가 비어 있는지 확인합니다. 이 방법에는 세 가지 변형이 있습니다. 첫 번째 변형은 Sitecore ID와 인수 이름을 가져 와서 ID가 null인지 확인합니다.
var nullId = new new ID("{00000000-0000-0000-0000-000000000000}");
// Both of these calls will result in an exception
Assert.ArgumentNotNullOrEmpty((ID)null, "null");
Assert.ArgumentNotNullOrEmpty(nullId, nameof(nullId));
두 번째 방법은 주어진 문자열이 null인지 또는 비어 있는지 확인하는 검사를 추가합니다.
// Both of these calls will result in an exception
Assert.ArgumentNotNullOrEmpty((string)null, "null");
Assert.ArgumentNotNullOrEmpty("", nameof(emptyString));
항목이 편집 모드에 있음을 확인하십시오.
건네받은 Item
이 편집 모드인가 어떤가를 확인합니다. 그렇지 않은 경우 EditingNotAllowedException
.
Assert.IsEditing(Sitecore.Context.Item);
보안 주장
CanRunApplication
사용자에게 주어진 응용 프로그램을 실행할 권한이 있는지 확인하려면. 그렇지 않은 경우 AccessDeniedException
이 발생합니다.
Assert.CanRunApplication("WebEdit");
HasAccess
HasAccess
는, 지정된 파라미터가 true HasAccess
를 체크합니다. 그렇지 않은 경우, AccessDeniedException
가 Throw됩니다.
Assert.HasAccess(Context.User.IsAdministrator, "Only administrators can create new domains");