public static void ArgumentNullExceptionIsThrown(Action action, string expectedArgumentName) { if (action == null) { throw new ArgumentNullException("method"); } if (expectedArgumentName == null) { throw new ArgumentNullException("expectedArgumentName"); } if (expectedArgumentName == string.Empty) { throw new ArgumentException(ValidationPredicateMessages.NullOrEmptyStringMessage, "expectedArgumentName"); } ArgumentNullException ex = null; try { action(); } catch (ArgumentNullException e) { ex = e; } Assert.AreEqual(typeof(ArgumentNullException), ex.GetType()); Assert.IsNotNull(ex); Assert.AreEqual(expectedArgumentName, ex.ParamName); }
private void ArgumentNullExceptionHandler(IInvocation invocation, ArgumentNullException exception) { var methodName = invocation.Method.Name; var message = $"Parameter in method {methodName} is not valid."; this._loggerService.LogMessage(message, LogLevel.Error); this._loggerService.LogMessage( new LogMessage { ClassName = this.ToString(), Message = exception.Message, MethodName = invocation.Method.Name }, LogLevel.Debug); throw new System.ServiceModel.FaultException <ExceptionDetail>( new ExceptionDetail( false, exception.Message, methodName, status: ErrorCode.ArgumentNullError, exceptionType: exception.GetType()), message ); }
public void TestExtractAllInnerExceptions() { // the implementation only concatenates exception type and message (no stacktrace) // format is: excp.GetType().Name + " : " + excp.Message + "\n" and this same is repeated as long there are innerexceptions ArgumentNullException nex = new ArgumentNullException("nex", "Parameter cannot be null."); ArgumentException argEx = new ArgumentException("Invalid argument supplied.", nex); Exception ex = new Exception("An error occured when calling typography service.", argEx); string extractedMessage = CoreExtensions.ExtractAllInnerExceptions(ex); extractedMessage.Should().NotBeNullOrWhiteSpace(); // create the expected message parts separated with the \n // remove \r\n so that we can split with \n easily string partOne = $"{ex.GetType().Name} : {ex.Message}".Replace("\r\n", string.Empty); string partTwo = $"{argEx.GetType().Name} : {argEx.Message}".Replace("\r\n", string.Empty); string partThree = $"{nex.GetType().Name} : {nex.Message}".Replace("\r\n", string.Empty); // remove \r\n also from the result (when parameter name is given it will be part of the ex.Message) extractedMessage = extractedMessage.Replace("\r\n", string.Empty); // don't remove empty entries var splittedMsgs = extractedMessage.Split(new string[] { "\n" }, StringSplitOptions.None); splittedMsgs.Length.Should().Be(4, "Count should be 4 because there are 3 exceptions and after last exception there will be '\n' which will produce the extra string in the array."); splittedMsgs[0].Should().Be(partOne); splittedMsgs[1].Should().Be(partTwo); splittedMsgs[2].Should().Be(partThree); }
public void TestJoinWithNull() { this.names.Add("Pesho"); this.names.Add("Stamat"); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => this.names.JoinWith(null)); Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); }
public void ValidateName_Component_Null() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => _container.InvokeValidateName((IComponent)null, "A")); Assert.Equal(typeof(ArgumentNullException), ex.GetType()); Assert.Null(ex.InnerException); Assert.NotNull(ex.Message); Assert.Equal("component", ex.ParamName); }
//MMZ :) private static string GetMessage(ArgumentNullException ex) { var errors = new StringBuilder(); errors.AppendLine(); #if DEBUG errors.AppendLine($"[{ex.GetType().Name}]"); #endif if (ex.Message.Contains("Value cannot be null")) { errors.Clear(); errors.AppendLine("مقادیر لازم به طور کامل پر نشده اند "); } else { errors.AppendLine($"{ex.GetType().Name}: {ex.Message}"); } return(errors.ToString()); }
public void Append_Context_Null() { ContextStack stack = new ContextStack(); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => stack.Append(null)); Assert.Equal(typeof(ArgumentNullException), ex.GetType()); Assert.Null(ex.InnerException); Assert.NotNull(ex.Message); Assert.Equal("context", ex.ParamName); }
public virtual void AttachItem(TEntity item) { if (item == (TEntity)null) { var err = new ArgumentNullException("item", "Argument is null"); _tracer.LogError(err.GetType().ToString(), err); } (CreateSet()).Attach(item); }
public void ValidateName_Component_Null() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => _container.InvokeValidateName((IComponent)null, "A")); Assert.Equal(typeof(ArgumentNullException), ex.GetType()); Assert.Null(ex.InnerException); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away exception messages and paramnames. { Assert.NotNull(ex.Message); Assert.Equal("component", ex.ParamName); } }
[Fact] // Item (Type) public void Indexer2_Type_Null() { ContextStack stack = new ContextStack(); stack.Push(new Foo()); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => stack[(Type)null]); Assert.Equal(typeof(ArgumentNullException), ex.GetType()); Assert.Null(ex.InnerException); Assert.NotNull(ex.Message); Assert.Equal("type", ex.ParamName); }
/// <summary> /// ArgumentNullException A null argument was passed to a method that doesn't accept it. /// </summary> /// <param name="ex"></param> /// <returns></returns> private static SqlMessage SqlException(ArgumentNullException ex) { SqlMessage meResul = new SqlMessage { Status = sqlMessagerType.SystemError, Title = ex.GetType().FullName, Message = ex.Message, ExceptionMesseger = ex.Message }; return(meResul); }
public void Append_Context_Null() { ContextStack stack = new ContextStack(); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => stack.Append(null)); Assert.Equal(typeof(ArgumentNullException), ex.GetType()); Assert.Null(ex.InnerException); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away exception messages and paramnames. { Assert.NotNull(ex.Message); Assert.Equal("context", ex.ParamName); } }
public void CheckRecordException() { var message = "message"; var exception = new ArgumentNullException(message, new Exception(message)); var activity = new Activity("test-activity"); activity.RecordException(exception); var @event = activity.Events.FirstOrDefault(e => e.Name == SemanticConventions.AttributeExceptionEventName); Assert.Equal(message, @event.Tags.FirstOrDefault(t => t.Key == SemanticConventions.AttributeExceptionMessage).Value); Assert.Equal(exception.GetType().Name, @event.Tags.FirstOrDefault(t => t.Key == SemanticConventions.AttributeExceptionType).Value); }
[Fact] // Item (Type) public void Indexer2_Type_Null() { ContextStack stack = new ContextStack(); stack.Push(new Foo()); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => stack[(Type)null]); Assert.Equal(typeof(ArgumentNullException), ex.GetType()); Assert.Null(ex.InnerException); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away exception messages and paramnames. { Assert.NotNull(ex.Message); Assert.Equal("type", ex.ParamName); } }
public virtual void Remove(TEntity item) { _tracer.LogInfo("Remove called"); if (item == (TEntity)null) { var err = new ArgumentNullException("item", "Argument is null"); _tracer.LogError(err.GetType().ToString(), err); } IDbSet <TEntity> objectSet = CreateSet(); objectSet.Attach(item); objectSet.Remove(item); UnitOfWork.Commit(); }
public virtual IEnumerable <TEntity> GetBySpec(ISpecification <TEntity> specification) { _tracer.LogInfo("Get By Specification Called"); if (specification == (ISpecification <TEntity>)null) { var err = new ArgumentNullException("specification"); _tracer.LogError(err.GetType().ToString(), err); throw err; } return(CreateSet().Where(specification.SatisfiedBy()) .AsEnumerable <TEntity>()); }
public void ForceClientAndAuthenticationClientThrowSameError() { //check that the ForceClient and AuthenticationClient both throw the same argument exception AuthenticationClient auth = new AuthenticationClient(); ArgumentNullException acex = Assert.Throws <ArgumentNullException>(() => { var client = new ForceClient("ClientId", "ClientSecret", "username", "", DefaultTokenRequestEndpoint); }); ArgumentNullException fcex = Assert.Throws <ArgumentNullException>(() => auth.UsernamePassword("ClientId", "ClientSecret", "username", "", DefaultTokenRequestEndpoint) ); Assert.True(fcex.GetType() == acex.GetType()); Assert.True(acex.Message == fcex.Message); }
public virtual IEnumerable <TEntity> GetFilteredElements(System.Linq.Expressions.Expression <Func <TEntity, bool> > filter) { _tracer.LogInfo("Get Filtered Elements called"); //checking query arguments if (filter == (Expression <Func <TEntity, bool> >)null) { var err = new ArgumentNullException("filter", "Filter Cannot Be null"); _tracer.LogError(err.GetType().ToString(), err); throw err; } //Create IDbSet and perform query return(CreateSet().Where(filter).ToList()); }
public void WriteTest() { FeatureSheet target = new FeatureSheet(); // TODO: Initialize to an appropriate value CommonTestMethod.DisableDebugAsserts(); try { target.Write(); Assert.Fail("Write succeeded with no sheet name!"); } catch (Exception e) { ArgumentNullException expectedException = new ArgumentNullException(); Assert.AreEqual(expectedException.GetType(), e.GetType()); } finally { CommonTestMethod.EnableDebugAsserts(); } }
public async Task WithNullCarAddThrowsArgumentNullException() { // Arrange Car carInput = null; Exception exc = new ArgumentNullException(); Type expected = exc.GetType(); Type actual = null; // Act try { await repository.AddAsync(carInput); } catch (Exception e) { actual = e.GetType(); } // Assert Assert.Equal(expected, actual); }
public void LogErrorEvent() { var message = Guid.NewGuid().ToString(); var exception = new ArgumentNullException(); try { throw exception; } catch (Exception ex) { _logger.Error(message, ex); } var le = ApplicationEventLog.First(message); Assert.That(le.CategoryNumber, Is.EqualTo((short)LevelCategory.Error)); Assert.That(le.InstanceId, Is.EqualTo(EventLogAppender.TypeHashAlgorithm(exception.GetType()))); Assert.That(le.Source, Is.EqualTo(TEST_SOURCE)); }
public virtual IEnumerable <TEntity> GetFilteredElements <S>( System.Linq.Expressions.Expression <Func <TEntity, bool> > filter, int pageIndex, int pageCount, System.Linq.Expressions.Expression <Func <TEntity, S> > orderByExpression, bool ascending) { _tracer.LogInfo("Get Filtered Elements and Sort called"); if (filter == (Expression <Func <TEntity, bool> >)null) { var err = new ArgumentNullException("filter", "Filter Cannot Be null"); _tracer.LogError(err.GetType().ToString(), err); throw err; } if (orderByExpression == (Expression <Func <TEntity, S> >)null) { var err = new ArgumentNullException("orderByExpression", ""); _tracer.LogError(err.GetType().ToString(), err); throw err; } //Create IObjectSet for this type and perform query IDbSet <TEntity> objectSet = CreateSet(); return((ascending) ? objectSet .Where(filter) .OrderBy(orderByExpression) .Skip(pageIndex * pageCount).Take(pageCount) .ToList() : objectSet .Where(filter) .OrderByDescending(orderByExpression) .Skip(pageIndex * pageCount).Take(pageCount) .ToList()); }
public void GetLoadExceptionDetailsShouldReturnLoaderExceptionMessagesForMoreThanOneException() { var loaderException1 = new ArgumentNullException("DummyLoaderExceptionMessage1", (Exception)null); var loaderException2 = new AccessViolationException("DummyLoaderExceptionMessage2"); var exceptions = new ReflectionTypeLoadException( null, new Exception[] { loaderException1, loaderException2 }); StringBuilder errorDetails = new StringBuilder(); errorDetails.AppendFormat( CultureInfo.CurrentCulture, Resource.EnumeratorLoadTypeErrorFormat, loaderException1.GetType(), loaderException1.Message).AppendLine(); errorDetails.AppendFormat( CultureInfo.CurrentCulture, Resource.EnumeratorLoadTypeErrorFormat, loaderException2.GetType(), loaderException2.Message).AppendLine(); Assert.AreEqual(errorDetails.ToString(), this.assemblyEnumerator.GetLoadExceptionDetails(exceptions)); }
public virtual IEnumerable <TEntity> GetFilteredElements(System.Linq.Expressions.Expression <Func <TEntity, bool> > filter, params string[] includes) { _tracer.LogInfo("Get Filtered Elements called"); //checking query arguments if (filter == (Expression <Func <TEntity, bool> >)null) { var err = new ArgumentNullException("filter", "Filter Cannot Be null"); _tracer.LogError(err.GetType().ToString(), err); throw err; } //Create IDbSet and perform query var set = CreateSet().AsQueryable(); foreach (var inc in includes) { set = set.Include(inc); } return(set.Where(filter).ToList()); }
public bool UniqueName(System.Linq.Expressions.Expression <Func <TEntity, bool> > filter) { _tracer.LogInfo("Get Filtered Elements called"); //Create IDbSet and perform query //checking query arguments if (filter == (Expression <Func <TEntity, bool> >)null) { var err = new ArgumentNullException("filter", "Filter Cannot Be null"); _tracer.LogError(err.GetType().ToString(), err); throw err; } var set = CreateSet().AsQueryable(); if (set.Where(filter).SingleOrDefault() == null) { return(true); } else { return(false); } }
public void TestAddNullThrowsExeption() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => this.names.Add(null)); Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException)); }
public void ArgumentNullExceptionĆeBitiUhvaćenKaoArgumentException() { Assert.IsTrue(ProvjeriCatchBlokove()); Exception e = new ArgumentNullException(); Iznimke.VišestrukiBlokoviCatch.HvatanjeIznimkePremaTipu(e); Assert.AreEqual(string.Format(Iznimke.VišestrukiBlokoviCatch.FormatFiltraArgumentException, e.GetType().Name), cw.GetString()); }