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


C# InvalidOperationException.ToString方法代码示例

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


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

示例1: ShouldLogAnErrorWhenUpgradeFails

 public void ShouldLogAnErrorWhenUpgradeFails()
 {
     var ex = new InvalidOperationException();
     ScriptProvider.GetScripts(Arg.Any<Func<IDbConnection>>()).Returns(provider => { throw ex; });
     DbUpgrader.PerformUpgrade();
     Log.Received().WriteError("Upgrade failed due to an unexpected exception:\r\n{0}", ex.ToString());
 }
开发者ID:ariesy,项目名称:DbUp,代码行数:7,代码来源:CreatingANewDatabase.cs

示例2: WhenExceptionMessageHasOnlyException_ThenMessageContainsExceptionMessageAndStacktrace

		public void WhenExceptionMessageHasOnlyException_ThenMessageContainsExceptionMessageAndStacktrace()
		{
			var exception = new InvalidOperationException("Foo");
			var traceEvent = new ExceptionTraceEvent(TraceEventType.Error, 0, exception);

			Assert.Contains("Foo", traceEvent.MessageOrFormat);
			Assert.Contains(exception.ToString(), traceEvent.MessageOrFormat);
		}
开发者ID:netfx,项目名称:extensions,代码行数:8,代码来源:TraceEventsSpec.cs

示例3: InvalidOperationException

		public void WhenExceptionMessageHasMessageFormat_ThenMessageContainsFormattedMessageAndExceptionMessageAndStacktrace()
		{
			var exception = new InvalidOperationException("Foo");
			var traceEvent = new ExceptionTraceEvent(TraceEventType.Error, 0, exception, "Hello {0}", "World");

			Assert.Contains("Hello World", traceEvent.MessageOrFormat);
			Assert.Contains("Foo", traceEvent.MessageOrFormat);
			Assert.Contains(exception.ToString(), traceEvent.MessageOrFormat);
		}
开发者ID:netfx,项目名称:extensions,代码行数:9,代码来源:TraceEventsSpec.cs

示例4: WhenAddingMessageAndThrowsShouldLogError

        public void WhenAddingMessageAndThrowsShouldLogError()
        {
            var message = new Message(new Uri("http://www.google.com"), string.Empty);
            var exception = new InvalidOperationException("Error");

            this.PersistentStore.Setup(s => s.Add(message)).Throws(exception);
            this.StoreService.Put(message);
            this.PersistentStore.Verify(r => r.Add(message), Times.AtLeast(1));
            this.Logger.Verify(l => l.Err("StoreService.ThreadStart. Error {0}", exception.ToString()), Times.AtLeast(1));
        }
开发者ID:B2MSolutions,项目名称:reyna.net,代码行数:10,代码来源:GivenAStoreService.cs

示例5: SerializesProperties

        public void SerializesProperties()
        {
            var exception = new InvalidOperationException("Some message") { HelpLink = "http://example.com" };
            var errors = new ErrorSerializer().Serialize(new ApiError(exception))["errors"][0];

            Assert.Equal(exception.Message, errors.Value<string>("title"));
            Assert.Equal(exception.HelpLink, errors["links"].Value<string>("about"));
            Assert.Equal(exception.GetType().FullName, errors.Value<string>("code"));
            Assert.Equal(exception.ToString(), errors.Value<string>("detail"));
        }
开发者ID:markwalsh-liverpool,项目名称:saule,代码行数:10,代码来源:ErrorSerializerTests.cs

示例6: ScenarioOptionThrowingException

                public void ScenarioOptionThrowingException()
                {
                    var injector = new MockInjector();
                    var program = injector.Create<Program>();
                    var runner = injector.GetMock<IRunner>();
                    var output = injector.GetMock<IOutput>();
                    var options = new Options
                    {
                        Scenario = "s"
                    };

                    var exception = new InvalidOperationException("moo");
                    runner.Setup(r =>
                                 r.Run(It.IsAny<string>(),
                                       It.IsAny<string[]>(), null))
                          .Throws(exception);

                    program.Run(options)
                           .Should().Be(1);

                    output.Verify(o => o.Display(It.Is<ResultModel>(r =>
                        r.Result == Result.Fail && r.Message == exception.ToString())));
                }
开发者ID:NSWPlanning,项目名称:edais,代码行数:23,代码来源:ProgramTest.cs

示例7: MainPresenter_VersionChecker_Logs_Exceptions

        public void MainPresenter_VersionChecker_Logs_Exceptions()
        {
            _Presenter.Initialise(_View.Object);

            var exception = new InvalidOperationException("Exception text here");
            _Log.Verify(o => o.WriteLine(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
            _NewVersionChecker.Setup(c => c.CheckForNewVersion()).Callback(() => { throw exception; });

            _HeartbeatService.Raise(h => h.SlowTick += null, EventArgs.Empty);

            _Log.Verify(o => o.WriteLine(It.IsAny<string>(), exception.ToString()), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:12,代码来源:MainPresenterTests.cs

示例8: Plugin_Shutdown_Logs_Exceptions_Raised_During_Session_Shutdown

        public void Plugin_Shutdown_Logs_Exceptions_Raised_During_Session_Shutdown()
        {
            var exception = new InvalidOperationException();
            _BaseStationDatabase.Setup(d => d.UpdateSession(It.IsAny<BaseStationSession>())).Callback(() => { throw exception; });

            SetEnabledOption(true);
            _Plugin.Startup(_StartupParameters);
            _Plugin.Shutdown();

            _Log.Verify(g => g.WriteLine(It.IsAny<string>(), exception.ToString()), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:11,代码来源:PluginTests.cs

示例9: Plugin_Startup_Records_Exception_In_Log_If_Session_Start_Throws

        public void Plugin_Startup_Records_Exception_In_Log_If_Session_Start_Throws()
        {
            var exception = new InvalidOperationException();
            SetEnabledOption(true);
            _BaseStationDatabase.Setup(d => d.InsertSession(It.IsAny<BaseStationSession>())).Callback(() => { throw exception; });

            _Plugin.Startup(_StartupParameters);

            _Log.Verify(g => g.WriteLine(It.IsAny<string>(), exception.ToString()), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:10,代码来源:PluginTests.cs

示例10: Plugin_Reports_Exceptions_During_Flight_Update

        public void Plugin_Reports_Exceptions_During_Flight_Update()
        {
            var exception = new InvalidOperationException();
            SetEnabledOption(true);
            _BaseStationDatabase.Setup(d => d.UpdateFlight(It.IsAny<BaseStationFlight>())).Callback(() => { throw exception; });

            var startTime = SetProviderTimes(DateTime.Now);
            _Plugin.Startup(_StartupParameters);

            _Plugin.StatusChanged += _StatusChangedEvent.Handler;
            _StatusChangedEvent.EventRaised += (s, a) => {
                Assert.AreEqual(String.Format("Exception caught: {0}", exception.Message), _Plugin.StatusDescription);
            };

            var message = new BaseStationMessage() { AircraftId = 99, Icao24 = "X", MessageType = BaseStationMessageType.Transmission, TransmissionType = BaseStationTransmissionType.AirToAir };
            _Listener.Raise(r => r.Port30003MessageReceived += null, new BaseStationMessageEventArgs(message));

            var endTime = SetProviderTimes(startTime.AddMinutes(MinutesBeforeFlightClosed));
            _HeartbeatService.Raise(s => s.SlowTick += null, EventArgs.Empty);

            Assert.AreEqual(1, _StatusChangedEvent.CallCount);
            Assert.AreSame(_Plugin, _StatusChangedEvent.Sender);
            _Log.Verify(g => g.WriteLine(It.IsAny<string>(), exception.ToString()), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:24,代码来源:PluginTests.cs

示例11: Plugin_Reports_Exceptions_During_Database_EndTransaction

        public void Plugin_Reports_Exceptions_During_Database_EndTransaction()
        {
            var exception = new InvalidOperationException();
            SetEnabledOption(true);
            _BaseStationDatabase.Setup(d => d.EndTransaction()).Callback(() => { throw exception; });

            _Plugin.Startup(_StartupParameters);

            _Plugin.StatusChanged += _StatusChangedEvent.Handler;
            _StatusChangedEvent.EventRaised += (s, a) => {
                Assert.AreEqual(String.Format("Exception caught: {0}", exception.Message), _Plugin.StatusDescription);
            };

            var message = new BaseStationMessage() { AircraftId = 99, Icao24 = "X", MessageType = BaseStationMessageType.Transmission, TransmissionType = BaseStationTransmissionType.AirToAir };
            _Listener.Raise(r => r.Port30003MessageReceived += null, new BaseStationMessageEventArgs(message));

            Assert.AreEqual(1, _StatusChangedEvent.CallCount);
            Assert.AreSame(_Plugin, _StatusChangedEvent.Sender);
            _Log.Verify(g => g.WriteLine(It.IsAny<string>(), exception.ToString()), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:20,代码来源:PluginTests.cs

示例12: ShutdownPresenter_ShutdownApplication_Logs_Exceptions_Raised_By_Plugins

        public void ShutdownPresenter_ShutdownApplication_Logs_Exceptions_Raised_By_Plugins()
        {
            var log = TestUtilities.CreateMockSingleton<ILog>();
            var exception = new InvalidOperationException();
            var plugin = new Mock<IPlugin>();
            plugin.Setup(p => p.Shutdown()).Callback(() => { throw exception; });
            _Plugins.Add(plugin.Object);

            _Presenter.Initialise(_View.Object);
            _Presenter.ShutdownApplication();

            log.Verify(g => g.WriteLine(It.IsAny<string>(), It.IsAny<string>(), exception.ToString()), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:13,代码来源:ShutdownPresenterTests.cs

示例13: SplashPresenter_StartApplication_Reports_Exceptions_Raised_During_Load_Of_Standing_Data

        public void SplashPresenter_StartApplication_Reports_Exceptions_Raised_During_Load_Of_Standing_Data()
        {
            var exception = new InvalidOperationException("oops");
            _StandingDataManager.Setup(m => m.Load()).Callback(() => { throw exception; });

            _Presenter.Initialise(_View.Object);
            _Presenter.StartApplication();

            _Log.Verify(g => g.WriteLine("Exception caught during load of standing data: {0}", exception.ToString()), Times.Once());
            _View.Verify(v => v.ReportProblem(String.Format(Strings.CannotLoadFlightRouteDataFull, exception.Message), Strings.CannotLoadFlightRouteDataTitle, false), Times.Once());
        }
开发者ID:cihanozhan,项目名称:virtual-radar-server,代码行数:11,代码来源:SplashPresenterTests.cs

示例14: ValidateForHtmlContent

 private bool ValidateForHtmlContent(InvalidOperationException exp)
 {
     return exp.ToString().Contains("<html xmlns=''> was not expected");
 }
开发者ID:karbazol,项目名称:FBReaderCS,代码行数:4,代码来源:OpdsCatalogReader.cs

示例15: MessageWithExceptionTest

        public void MessageWithExceptionTest()
        {
            LogManager.Configuration = CreateConfigurationFromString(@"
            <nlog>
                <targets><target name='debug' type='Debug' layout='${message:withException=true}' /></targets>
                <rules>
                    <logger name='*' minlevel='Debug' writeTo='debug' />
                </rules>
            </nlog>");

            Logger logger = LogManager.GetLogger("A");
            logger.Debug("a");
            AssertDebugLastMessage("debug", "a");

            var ex = new InvalidOperationException("Exception message.");
            logger.DebugException("Foo", ex);
#if !SILVERLIGHT && !NET_CF
            string newline = Environment.NewLine;
#else
            string newline = "\r\n";
#endif

            AssertDebugLastMessage("debug", "Foo" + newline + ex.ToString());
        }
开发者ID:Loopt,项目名称:NLog,代码行数:24,代码来源:MessageTests.cs


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