當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。