// Test the ArgumentNullException class. public void TestArgumentNullException() { ArgumentNullException e; e = new ArgumentNullException(); AssertNull("ArgumentNullException (1)", e.ParamName); AssertNotNull("ArgumentNullException (2)", e.Message); ExceptionTester.CheckHResult ("ArgumentNullException (3)", e, unchecked((int)0x80004003)); e = new ArgumentNullException("p"); AssertEquals("ArgumentNullException (4)", "p", e.ParamName); AssertNotNull("ArgumentNullException (5)", e.Message); ExceptionTester.CheckHResult ("ArgumentNullException (6)", e, unchecked((int)0x80004003)); e = new ArgumentNullException("p", "msg"); AssertEquals("ArgumentNullException (7)", "p", e.ParamName); AssertEquals("ArgumentNullException (8)", "msg", e.Message); ExceptionTester.CheckHResult ("ArgumentNullException (9)", e, unchecked((int)0x80004003)); }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type AmbiguousMatchException using an emtpy string message"; string errorDesc; string message = string.Empty; Exception innerException = new ArgumentNullException(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { AmbiguousMatchException e = new AmbiguousMatchException(message, innerException); if (null == e || e.Message != message || e.InnerException != innerException) { errorDesc = "Failed to initialize an instance of type AmbiguousMatchException."; errorDesc += "\nInput message is emtpy string"; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is emtpy string"; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public void StateCannotBeNull() { var expectedEx = new ArgumentNullException("state"); var actualEx = Assert.Throws<ArgumentNullException>(() => new Snapshot(Guid.NewGuid(), 1, null)); Assert.Equal(expectedEx.Message, actualEx.Message); }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type TargetInvocationException via default constructor"; string errorDesc; Exception innerException = new ArgumentNullException(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { TargetInvocationException ex = new TargetInvocationException(innerException); if (null == ex) { errorDesc = "Failed to initialize an instance of type TargetInvocationException via default constructor."; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Call ctor with a null argument to construct a new instance"); try { string randValue = null; ArgumentNullException argumentNullException = new ArgumentNullException(randValue); if (argumentNullException == null) { TestLibrary.TestFramework.LogError("004", "argumentNullException is null"); retVal = false; } string expected = "Value cannot be null."; if ((argumentNullException.Message != expected) & (!argumentNullException.Message.Contains("[ArgumentNull_Generic]"))) { TestLibrary.TestFramework.LogError("005", "The result is not the value as expected"); TestLibrary.TestFramework.LogInformation("Expected: " + expected + "; Actual: " + argumentNullException.Message); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e); retVal = false; } return retVal; }
public void PageRetrieverCannotBeNull() { var expectedEx = new ArgumentNullException("pageRetriever"); var actualEx = Assert.Throws<ArgumentNullException>(() => new PagedResult<Object>(10, null)); Assert.Equal(expectedEx.Message, actualEx.Message); }
/// <summary> /// Method to determine whether the counter set given by 'counterSetName' is /// registered with the system. If true, then counterSetId is populated. /// </summary> public bool IsCounterSetRegistered(string counterSetName, out Guid counterSetId) { counterSetId = new Guid(); if (counterSetName == null) { ArgumentNullException argNullException = new ArgumentNullException("counterSetName"); _tracer.TraceException(argNullException); return false; } return _CounterSetNameToIdMapping.TryGetValue(counterSetName, out counterSetId); }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call ctor with a random string argument to construct a new instance"); try { string randValue = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH); ArgumentNullException argumentNullException = new ArgumentNullException(randValue); if (argumentNullException == null) { TestLibrary.TestFramework.LogError("001", "argumentNullException is null"); retVal = false; } string expectedWindows = "Value cannot be null.\r\nParameter name: " + randValue; string expectedMac = "Value cannot be null.\nParameter name: " + randValue; if (!argumentNullException.Message.Contains("[ArgumentNull_Generic]")) { if (!Utilities.IsWindows) { if (argumentNullException.Message != expectedMac) { TestLibrary.TestFramework.LogError("002", "The result is not the value as expected"); TestLibrary.TestFramework.LogInformation("Expected: " + expectedMac + "; Actual: " + argumentNullException.Message); retVal = false; } } else if (argumentNullException.Message != expectedWindows) { TestLibrary.TestFramework.LogError("002", "The result is not the value as expected"); TestLibrary.TestFramework.LogInformation("Expected: " + expectedWindows + "; Actual: " + argumentNullException.Message); retVal = false; } } } catch (Exception e) { TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call ctor to construct a new instance"); try { ArgumentNullException argumentNullException = new ArgumentNullException(); if (argumentNullException == null) { TestLibrary.TestFramework.LogError("001", "The result is not the value as expected"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return retVal; }
/// <summary>${Mapping_TiledDynamicRESTLayer_method_Initialize_D}</summary> public override void Initialize() { if (!this.isInitializing && !base.IsInitialized) { if (string.IsNullOrEmpty(this.Url)) { //Error = new ArgumentNullException(SuperMap.Web.iServerJava6R.Resources.ExceptionStrings.InvalidUrl); Initialize(); return; } if (IsSkipGetSMMapServiceInfo) { if (Bounds.IsEmpty) { Error = new ArgumentNullException("Bounds"); } Dpi = ScaleHelper.GetSmDpi(ReferViewBounds, ReferViewer, ReferScale); Dpi *= AdjustFactor; this.isInitializing = true; base.Initialize(); return; } this.isInitializing = true; EventHandler<SuperMap.Connector.Utility.MapParameterEventArgs> completed = (sender, e) => { if (base.Error != null) { base.Initialize(); } else { if (CRS == null) { CRS = new CoordinateReferenceSystem { Unit = (Core.Unit)e.MapParameter.CoordUnit, WKID = e.MapParameter.PrjCoordSys.EpsgCode }; } Bounds = new Rectangle2D(e.MapParameter.Bounds.LeftBottom.X, e.MapParameter.Bounds.LeftBottom.Y, e.MapParameter.Bounds.RightTop.X, e.MapParameter.Bounds.RightTop.Y); Dpi = ScaleHelper.GetSmDpi(new Rectangle2D(e.MapParameter.ViewBounds.LeftBottom.X, e.MapParameter.ViewBounds.LeftBottom.Y, e.MapParameter.ViewBounds.RightTop.X, e.MapParameter.ViewBounds.RightTop.Y), new Rect(0, 0, e.MapParameter.Viewer.Width, e.MapParameter.Viewer.Height), e.MapParameter.Scale); Dpi *= AdjustFactor; base.Initialize(); } }; EventHandler<SuperMap.Connector.Utility.FailedEventArgs> failed = (sender, e) => { base.Error = e.Exception; base.Initialize(); }; string[] splitItems = this.Url.Split(new char[] { '/' }); string mapName = splitItems[splitItems.Length - 1]; int restIndex = this.Url.LastIndexOf("maps"); string compomentUrl = this.Url.Substring(0, restIndex); SuperMap.Connector.Map map = new Connector.Map(compomentUrl); map.GetDefaultMapParameter(mapName, false, completed, failed); } }
public static PropertyInfo SelectProperty(PropertyInfo[] match, Type returnType, Type[] indexes) { // Allow a null indexes array. But if it is not null, every element must be non-null as well. if (indexes != null && !Contract.ForAll(indexes, delegate (Type t) { return t != null; })) { Exception e; // Written this way to pass the Code Contracts style requirements. e = new ArgumentNullException("indexes"); throw e; } if (match == null || match.Length == 0) throw new ArgumentException(SR.Arg_EmptyArray, "match"); Contract.EndContractBlock(); PropertyInfo[] candidates = (PropertyInfo[])match.Clone(); int i, j = 0; // Find all the properties that can be described by type indexes parameter int CurIdx = 0; int indexesLength = (indexes != null) ? indexes.Length : 0; for (i = 0; i < candidates.Length; i++) { if (indexes != null) { ParameterInfo[] par = candidates[i].GetIndexParameters(); if (par.Length != indexesLength) continue; for (j = 0; j < indexesLength; j++) { Type pCls = par[j].ParameterType; // If the classes exactly match continue if (pCls == indexes[j]) continue; if (pCls == typeof(Object)) continue; if (pCls.GetTypeInfo().IsPrimitive) { if (!CanConvertPrimitive(indexes[j], pCls)) break; } else { if (!pCls.GetTypeInfo().IsAssignableFrom(indexes[j].GetTypeInfo())) break; } } } if (j == indexesLength) { if (returnType != null) { if (candidates[i].PropertyType.GetTypeInfo().IsPrimitive) { if (!CanConvertPrimitive(returnType, candidates[i].PropertyType)) continue; } else { if (!candidates[i].PropertyType.GetTypeInfo().IsAssignableFrom(returnType.GetTypeInfo())) continue; } } candidates[CurIdx++] = candidates[i]; } } if (CurIdx == 0) return null; if (CurIdx == 1) return candidates[0]; // Walk all of the properties looking the most specific method to invoke int currentMin = 0; bool ambig = false; int[] paramOrder = new int[indexesLength]; for (i = 0; i < indexesLength; i++) paramOrder[i] = i; for (i = 1; i < CurIdx; i++) { int newMin = FindMostSpecificType(candidates[currentMin].PropertyType, candidates[i].PropertyType, returnType); if (newMin == 0 && indexes != null) newMin = FindMostSpecific(candidates[currentMin].GetIndexParameters(), paramOrder, null, candidates[i].GetIndexParameters(), paramOrder, null, indexes, null); if (newMin == 0) { newMin = FindMostSpecificProperty(candidates[currentMin], candidates[i]); if (newMin == 0) ambig = true; } if (newMin == 2) { ambig = false; currentMin = i; } } if (ambig) throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException); return candidates[currentMin]; }
internal static ArgumentNullException ArgumentNull(string parameter) { ArgumentNullException e = new ArgumentNullException(parameter); return e; }
public void WIPTest08() { var ex = new ArgumentNullException(DateTime.Now.ToString(CultureInfo.CurrentCulture)); WIPTests.InTest02(ex); }
public void NullNullableThrowsArgumentNullException() { var expectedEx = new ArgumentNullException("paramName"); var actualEx = Assert.Throws<ArgumentNullException>(() => Verify.NotNull(default(Int32?), "paramName")); Assert.Equal(expectedEx.Message, actualEx.Message); }
public bool SetCounterValue( string counterSetName, string counterName, long counterValue = 1, bool isNumerator = true) { if (counterSetName == null) { ArgumentNullException argNullException = new ArgumentNullException("counterSetName"); _tracer.TraceException(argNullException); return false; } Guid counterSetId; if (this.IsCounterSetRegistered(counterSetName, out counterSetId)) { CounterSetInstanceBase counterSetInst = _CounterSetIdToInstanceMapping[counterSetId]; return counterSetInst.SetCounterValue(counterName, counterValue, isNumerator); } else { InvalidOperationException invalidOperationException = new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, "No Counter Set Instance with name '{0}' is registered", counterSetName)); _tracer.TraceException(invalidOperationException); return false; } }
/// <summary> /// Method to register a counter set with the Performance Counters Manager. /// </summary> public bool AddCounterSetInstance(CounterSetRegistrarBase counterSetRegistrarInstance) { if (counterSetRegistrarInstance == null) { ArgumentNullException argNullException = new ArgumentNullException("counterSetRegistrarInstance"); _tracer.TraceException(argNullException); return false; } Guid counterSetId = counterSetRegistrarInstance.CounterSetId; string counterSetName = counterSetRegistrarInstance.CounterSetName; CounterSetInstanceBase counterSetInst = null; if (this.IsCounterSetRegistered(counterSetId, out counterSetInst)) { InvalidOperationException invalidOperationException = new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, "A Counter Set Instance with id '{0}' is already registered", counterSetId)); _tracer.TraceException(invalidOperationException); return false; } try { if (!string.IsNullOrWhiteSpace(counterSetName)) { Guid retrievedCounterSetId; // verify that there doesn't exist another counter set with the same name if (this.IsCounterSetRegistered(counterSetName, out retrievedCounterSetId)) { InvalidOperationException invalidOperationException = new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, "A Counter Set Instance with name '{0}' is already registered", counterSetName)); _tracer.TraceException(invalidOperationException); return false; } _CounterSetNameToIdMapping.TryAdd(counterSetName, counterSetId); } _CounterSetIdToInstanceMapping.TryAdd( counterSetId, counterSetRegistrarInstance.CounterSetInstance); } catch (OverflowException overflowException) { _tracer.TraceException(overflowException); return false; } return true; }
static internal ArgumentNullException ArgumentNull(string parameter, string error) { ArgumentNullException e = new ArgumentNullException(parameter, error); return e; }
public void OnException() { // Arrange HandleErrorAttribute attr = new HandleErrorAttribute() { View = "SomeView", Master = "SomeMaster", ExceptionType = typeof(ArgumentException) }; Exception exception = new ArgumentNullException(); Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>(MockBehavior.Strict); mockHttpContext.Setup(c => c.IsCustomErrorEnabled).Returns(true); mockHttpContext.Setup(c => c.Session).Returns((HttpSessionStateBase)null); mockHttpContext.Setup(c => c.Response.Clear()).Verifiable(); mockHttpContext.SetupSet(c => c.Response.StatusCode = 500).Verifiable(); mockHttpContext.SetupSet(c => c.Response.TrySkipIisCustomErrors = true).Verifiable(); TempDataDictionary tempData = new TempDataDictionary(); IViewEngine viewEngine = new Mock<IViewEngine>().Object; Controller controller = new Mock<Controller>().Object; controller.TempData = tempData; ExceptionContext context = GetExceptionContext(mockHttpContext.Object, controller, exception); // Exception attr.OnException(context); // Assert mockHttpContext.Verify(); ViewResult viewResult = context.Result as ViewResult; Assert.NotNull(viewResult); Assert.Equal(tempData, viewResult.TempData); Assert.Equal("SomeView", viewResult.ViewName); Assert.Equal("SomeMaster", viewResult.MasterName); HandleErrorInfo viewData = viewResult.ViewData.Model as HandleErrorInfo; Assert.NotNull(viewData); Assert.Same(exception, viewData.Exception); Assert.Equal("SomeController", viewData.ControllerName); Assert.Equal("SomeAction", viewData.ActionName); }
/// <summary> /// This method retrieves the counter value associated with counter 'counterName' /// based on isNumerator parameter. /// </summary> public override bool GetCounterValue(string counterName, bool isNumerator, out long counterValue) { counterValue = -1; if (_Disposed) { ObjectDisposedException objectDisposedException = new ObjectDisposedException("PSCounterSetInstance"); _tracer.TraceException(objectDisposedException); return false; } // retrieve counter id associated with the counter name if (counterName == null) { ArgumentNullException argNullException = new ArgumentNullException("counterName"); _tracer.TraceException(argNullException); return false; } try { int targetCounterId = this._counterNameToIdMapping[counterName]; return this.GetCounterValue(targetCounterId, isNumerator, out counterValue); } catch (KeyNotFoundException) { InvalidOperationException invalidOperationException = new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, "Lookup for counter corresponding to counter name {0} failed", counterName)); _tracer.TraceException(invalidOperationException); return false; } }
public void NullValueThrowsArgumentNullException() { var expectedEx = new ArgumentNullException("paramName"); var ex = Assert.Throws<ArgumentNullException>(() => Verify.NotNullOrWhiteSpace(default(String), "paramName")); Assert.Equal(expectedEx.Message, ex.Message); }
public BTCPayWallet GetWallet(BTCPayNetworkBase network) { ArgumentNullException.ThrowIfNull(network); return(GetWallet(network.CryptoCode)); }
/// <inheritdoc/> static void IEndpointMetadataProvider.PopulateMetadata(EndpointMetadataContext context) { ArgumentNullException.ThrowIfNull(context); context.EndpointMetadata.Add(new ProducesResponseTypeMetadata(StatusCodes.Status201Created)); }
public BTCPayWallet GetWallet(string cryptoCode) { ArgumentNullException.ThrowIfNull(cryptoCode); _Wallets.TryGetValue(cryptoCode.ToUpperInvariant(), out var result); return(result); }