当前位置: 首页>>代码示例>>C#>>正文


C# System.ArgumentNullException类代码示例

本文整理汇总了C#中System.ArgumentNullException的典型用法代码示例。如果您正苦于以下问题:C# ArgumentNullException类的具体用法?C# ArgumentNullException怎么用?C# ArgumentNullException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ArgumentNullException类属于System命名空间,在下文中一共展示了ArgumentNullException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Verify_ExceptionThrownAndMessageContainsExpectedStrng_DoesnThrowExpection

        public void Verify_ExceptionThrownAndMessageContainsExpectedStrng_DoesnThrowExpection()
        {
            var constraint = CreateConstraint(typeof(ArgumentNullException), "argument1");
            var actualException = new ArgumentNullException("argument1");

            constraint.Verify(actualException);
        }
开发者ID:olegd,项目名称:MSTest.Contrib,代码行数:7,代码来源:ExpectedExceptionConstraintTests.cs

示例2: ActivateOptionsTestLogFolderSet

        public void ActivateOptionsTestLogFolderSet()
        {
            string tempPath = Path.Combine(System.IO.Path.GetTempPath() + "foobar");
            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }

            LogExceptionToFileFilter filter = new LogExceptionToFileFilter();
            filter.ExceptionLogFolder = tempPath;

            filter.ActivateOptions();

            var exception = new ArgumentNullException();
            ILoggerRepository logRepository = Substitute.For<ILoggerRepository>();

            var evt = new LoggingEvent(typeof(LogExceptionToFileFilterTests), logRepository, "test logger", Level.Debug, "test message", exception);

            var filterResult = filter.Decide(evt);
            Assert.AreEqual(FilterDecision.Neutral, filterResult);

            Assert.IsTrue(evt.Properties.Contains("log4net:syslog-exception-log"), "has an exception log param");
            Assert.IsTrue(Directory.Exists(tempPath));

            Assert.IsTrue(File.Exists(evt.Properties["log4net:syslog-exception-log"].ToString()), "exception file exists");

            Directory.Delete(tempPath, true);
        }
开发者ID:JackFong,项目名称:syslog4net,代码行数:28,代码来源:LogExceptionToFileFilterTests.cs

示例3: TestBackupRestoreCallbackExceptionHandling

 public void TestBackupRestoreCallbackExceptionHandling()
 {
     var ex = new ArgumentNullException();
     var test = new DatabaseFileTestHelper("database", "backup", true);
     Assert.Inconclusive("ESENT bug means instance isn't torn down correctly");
     test.TestRestoreCallbackExceptionHandling(ex);
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:7,代码来源:BackupRestoreTests.cs

示例4: Verify_ExceptionThrownMessageDoesntContainExpectedString_ThrowsException

        public void Verify_ExceptionThrownMessageDoesntContainExpectedString_ThrowsException()
        {
            var constraint = CreateConstraint(typeof(ArgumentNullException), "argument1");
            var actualException = new ArgumentNullException("argument52");

            NUnit.Framework.Assert.Throws<AssertFailedException>(() => constraint.Verify(actualException));
        }
开发者ID:olegd,项目名称:MSTest.Contrib,代码行数:7,代码来源:ExpectedExceptionConstraintTests.cs

示例5: Authenticate

        public HttpResponseMessage Authenticate([FromBody] SystemUser user)
        {
            if (user == null)
            {
                var ex = new ArgumentNullException("user");
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }

            if ((user = SystemUser.Authenticate(user.Username, user.Password)) != null)
            {
                var authUser = new SystemUser
                {
                    Id = user.Id,
                    Username = user.Username,
                };
                authUser.GenerateAuthToken();
                ApplicationContext.AddAuthenticatedUser(authUser);

                return Request.CreateResponse(HttpStatusCode.OK, authUser);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.Forbidden);
            }
        }
开发者ID:kameshkamz,项目名称:PlantMonitoringSystem,代码行数:25,代码来源:UserController.cs

示例6: AcquireTokenHandlerBase

        protected AcquireTokenHandlerBase(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey, TokenSubjectType subjectType, bool callSync)
        {
            this.Authenticator = authenticator;
            this.CallState = CreateCallState(this.Authenticator.CorrelationId, callSync);
            Logger.Information(this.CallState, 
                string.Format("=== Token Acquisition started:\n\tAuthority: {0}\n\tResource: {1}\n\tClientId: {2}\n\tCacheType: {3}\n\tAuthentication Target: {4}\n\t",
                authenticator.Authority, resource, clientKey.ClientId,
                (tokenCache != null) ? tokenCache.GetType().FullName + string.Format(" ({0} items)", tokenCache.Count) : "null",
                subjectType));

            this.tokenCache = tokenCache;

            if (string.IsNullOrWhiteSpace(resource))
            {
                var ex = new ArgumentNullException("resource");
                Logger.Error(this.CallState, ex);
                throw ex;
            }

            this.Resource = (resource != NullResource) ? resource : null;
            this.ClientKey = clientKey;
            this.TokenSubjectType = subjectType;

            this.LoadFromCache = (tokenCache != null);
            this.StoreToCache = (tokenCache != null);
            this.SupportADFS = false;
        }
开发者ID:ankurchoubeymsft,项目名称:azure-activedirectory-library-for-dotnet,代码行数:27,代码来源:AcquireTokenHandlerBase.cs

示例7: Constructor_StoresException

        public void Constructor_StoresException()
        {
            var exception = new ArgumentNullException("foo");
            var poison = new Poison<int>(42, exception);

            Assert.Equal(new ExceptionDetails(exception), poison.Exception, GenericEqualityComparer<ExceptionDetails>.ByAllMembers());
        }
开发者ID:netngn,项目名称:Burden,代码行数:7,代码来源:PoisonTest.cs

示例8: ExceptionMessages_are_concatenated_by_GetSafeMessage

        public void ExceptionMessages_are_concatenated_by_GetSafeMessage()
        {
            var inner = new InvalidOperationException();
            var outer = new ArgumentNullException("Eine Message", inner);

            Assert.Equal(outer.Message + " ---> " + inner.Message, outer.GetSafeMessage());
        }
开发者ID:ExRam,项目名称:ExRam.Extensions,代码行数:7,代码来源:ExceptionExtensionsTest.cs

示例9: ConstructorTestFailedNoLanguage

        public void ConstructorTestFailedNoLanguage()
        {
            ArgumentNullException expected = new ArgumentNullException("language", "Provided language must not be null or empty.");
            ArgumentNullException actual = Assert.Throws<ArgumentNullException>(() => new SeriesDetails(this.testExtractionPath, string.Empty));

            Assert.Equal(expected.Message, actual.Message);
        }
开发者ID:StefanZi,项目名称:TheTVDBApi,代码行数:7,代码来源:SeriesDetailsTest.cs

示例10: Arrange

        internal void Arrange()
        {
            try
            {
                this.AppointmentGroups.ToDictionary(ag => ag.GroupId);
            }
            catch (ArgumentNullException ane)
            {
                ArgumentNullException ex = new ArgumentNullException(EX_ANEMSG, ane);
                throw ex;
            }
            catch (ArgumentException ae)
            {
                ArgumentException ex = new ArgumentException(EX_AEMSG, "AppointmentGroups", ae);
                throw ex;
            }

            foreach (var group in this.AppointmentGroups)
            {
                var movedItem = group.Where(a => a.GroupId != group.GroupId).FirstOrDefault();
                if (movedItem != default(Appointment))
                {
                    group.Remove(movedItem);
                    this.AppointmentGroups.Where(g => g.GroupId == movedItem.GroupId).First().Add(movedItem);
                }
            }
        }
开发者ID:roger1218,项目名称:ROIS,代码行数:27,代码来源:ResolveAppointmentsEventArgs.cs

示例11: BuildExceptionStringMessageTest

        public void BuildExceptionStringMessageTest()
        {
            var ex = new ArgumentNullException("", "fakeMessage") { Source = "fakeSource" };
            var expected = "<strong>myMessage</strong><br /><br /><strong>fakeMessage</strong><br /><br />";

            Assert.AreEqual(expected, ExceptionsHelper.BuildExceptionString(ex, "myMessage"));
        }
开发者ID:n3wt0n,项目名称:BugGuardian,代码行数:7,代码来源:ExceptionsHelperTests.cs

示例12: ConstructorWithParamNameWorks

		public void ConstructorWithParamNameWorks() {
			var ex = new ArgumentNullException("someParam");
			Assert.IsTrue((object)ex is ArgumentNullException, "is ArgumentNullException");
			Assert.AreEqual(ex.ParamName, "someParam", "ParamName");
			Assert.IsTrue(ex.InnerException == null, "InnerException");
			Assert.AreEqual(ex.Message, "Value cannot be null.\nParameter name: someParam");
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:7,代码来源:ArgumentNullExceptionTests.cs

示例13: ConstructorWithParamNameAndMessageWorks

		public void ConstructorWithParamNameAndMessageWorks() {
			var ex = new ArgumentNullException("someParam", "The message");
			Assert.IsTrue((object)ex is ArgumentNullException, "is ArgumentNullException");
			Assert.AreEqual(ex.ParamName, "someParam", "ParamName");
			Assert.IsTrue(ex.InnerException == null, "InnerException");
			Assert.AreEqual(ex.Message, "The message");
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:7,代码来源:ArgumentNullExceptionTests.cs

示例14: LoadAssembly

        public static Assembly LoadAssembly(string assemblyPath)
        {
            Assembly assembly = null;

            try
            {
                if (WzdUtils.FAddIn == null)
                {
                    ArgumentNullException exception = new ArgumentNullException("WzdUtils.FAddIn");

                    WzdUtils.Application_ThreadException(null, new ThreadExceptionEventArgs(exception));
                }
                else
                {
                    string path = WzdUtils.GetServerPath(WzdUtils.FAddIn, true);
                    path = path.Remove(path.LastIndexOf('\\')) + assemblyPath;
                    String fullDllName = path;
                    buffer = System.IO.File.ReadAllBytes(fullDllName);
                    assembly = Assembly.Load(buffer);
                }
            }
            catch (Exception ex)
            {
                WzdUtils.Application_ThreadException(null, new ThreadExceptionEventArgs(ex));
            }

            return assembly;
        }
开发者ID:san90279,项目名称:UK_OAS,代码行数:28,代码来源:EFAssembly.cs

示例15: DefaultConstructorWorks

		public void DefaultConstructorWorks() {
			var ex = new ArgumentNullException();
			Assert.IsTrue((object)ex is ArgumentNullException, "is ArgumentNullException");
			Assert.IsTrue(ex.ParamName == null, "ParamName");
			Assert.IsTrue(ex.InnerException == null, "InnerException");
			Assert.AreEqual(ex.Message, "Value cannot be null.");
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:7,代码来源:ArgumentNullExceptionTests.cs


注:本文中的System.ArgumentNullException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。