//----------------------------------------------------------------------------------------------------------------------------------------------------- protected ApiContractException(SerializationInfo info, StreamingContext context) : base(info, context) { m_ParamName = info.GetString("ParamName"); m_FailedCheck = (ApiContractCheckType)info.GetInt32("FailedCheck"); m_FailedCheckDirecton = (ApiContractCheckDirection)info.GetInt32("FailedCheckDirection"); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public ApiContractException(string paramName, ApiContractCheckType failedCheck, bool isOutput) : base(FormatMessage(paramName, failedCheck)) { m_ParamName = paramName; m_FailedCheck = failedCheck; m_FailedCheckDirecton = (isOutput ? ApiContractCheckDirection.Output : ApiContractCheckDirection.Input); }
public void CheckPerCollectionItem_OneItemViolatesCheck_Throw() { //-- Arrange m_ExpectedExceptionParamName = "values"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.GreaterThan; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithArrayOfPositiveInts(values: new int[] { 10, 0, 30 }); }
public void ArgumentNotNull_PassNull_Throw() { //-- Arrange m_ExpectedExceptionParamName = "str"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithNotNullString(str: null); }
public void ItemsNotNull_CustomCollectionWithNullItem_Throw() { //-- Arrange m_ExpectedExceptionParamName = "items"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithNotNullCollectionItems(items: new CustomCollection(new object[] { "A", null, "C" })); }
public void ItemsNotNullAndNotEmpty_ArrayWithNullItem_ThrowNotNull() { //-- Arrange m_ExpectedExceptionParamName = "items"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithNotNullListItems(items: new[] { "A", null, "C" }); }
public void CollectionArgumentNotEmpty_PassEmptyCollection_Throw() { //-- Arrange m_ExpectedExceptionParamName = "items"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotEmpty; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithNotEmptyCollection(items: new string[0]); }
public void StringArgumentNotEmpty_PassEmptyString_Throw() { //-- Arrange m_ExpectedExceptionParamName = "str"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotEmpty; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithNotEmptyString(str: ""); }
public void ItemsNotEmpty_ArrayWithEmptyString_Throw() { //-- Arrange m_ExpectedExceptionParamName = "items"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotEmpty; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithNotEmptyListItems(items: new string[] { "A", "", "C" }); }
public void StringLength_LengthOutOfRange_Throw( string str1, string str2, string str3, ApiContractCheckType failedCheckType, string failedParamName) { //-- Arrange m_ExpectedExceptionParamName = failedParamName; m_ExpectedExceptionFailedCheck = failedCheckType; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithStringLength(str1, str2, str3); }
public void InRangeOfTypeDouble_ValueOutOfRange_Throw( double number1, double number2, double number3, double number4, string failedParamName, ApiContractCheckType failedCheckType) { //-- Arrange m_ExpectedExceptionParamName = failedParamName; m_ExpectedExceptionFailedCheck = failedCheckType; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act m_ApiContractWrapper.AMethodWithDoubleRanges(number1, number2, number3, number4); }
public void ReturnValueNotNull_ReturnNull_Throw() { //-- Arrange m_ExpectedExceptionParamName = "(Return Value)"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Output; m_ExpectedExceptionLog = new[] { "ANotNullFunction(0)" }; //-- Act m_ApiContractWrapper.ANotNullFunction(x: 0); }
public void StringReturnValueNotEmpty_ReturnEmptyString_Throw() { //-- Arrange m_ExpectedExceptionParamName = "(Return Value)"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotEmpty; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Output; m_ExpectedExceptionLog = new[] { "ANotEmptyStringFunction(-1)" }; //-- Act m_ApiContractWrapper.ANotEmptyStringFunction(x: -1); }
public void RefArgumentNotNull_PassNull_Throw() { //-- Arrange m_ExpectedExceptionParamName = "data"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Input; //-- Act Stream data = null; m_ApiContractWrapper.AMethodWithNotNullRefParam(size: 0, data: ref data); }
public void RefArgumentNotNull_SetToNull_Throw() { //-- Arrange m_ExpectedExceptionParamName = "data"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Output; m_ExpectedExceptionLog = new[] { "AMethodWithNotNullRefParam(-1,Stream[123])" }; //-- Act Stream data = new MemoryStream(new byte[123]); m_ApiContractWrapper.AMethodWithNotNullRefParam(size: -1, data: ref data); }
public void OutArgumentNotNull_SetToNull_Throw() { //-- Arrange m_ExpectedExceptionParamName = "data"; m_ExpectedExceptionFailedCheck = ApiContractCheckType.NotNull; m_ExpectedExceptionFailedCheckDirection = ApiContractCheckDirection.Output; m_ExpectedExceptionLog = new[] { "AMethodWithNotNullOutParam(0)" }; //-- Act Stream data; m_ApiContractWrapper.AMethodWithNotNullOutParam(size: 0, data: out data); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private static string FormatMessage(string paramName, ApiContractCheckType failedCheck) { return(string.Format("API contract violation. Parameter [{0}] has failed [{1}] check.", paramName, failedCheck)); }