本文整理汇总了C#中System.InvalidOperationException.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# InvalidOperationException.GetType方法的具体用法?C# InvalidOperationException.GetType怎么用?C# InvalidOperationException.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.InvalidOperationException
的用法示例。
在下文中一共展示了InvalidOperationException.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCreateMatroshika
public void TestCreateMatroshika()
{
var value = new InvalidOperationException( Guid.NewGuid().ToString(), new Exception() );
var result = ExceptionDispatchInfo.CreateMatroshika( value );
Assert.That( result, Is.Not.Null );
Assert.That( result, Is.TypeOf( value.GetType() ) );
Assert.That( result.Message, Is.EqualTo( value.Message ) );
Assert.That( result.InnerException, Is.SameAs( value ) );
}
示例2: 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"));
}
示例3: Invoke_WithExceptionAndInnerException_ThrowsInnerException
public void Invoke_WithExceptionAndInnerException_ThrowsInnerException(
Mock<Common.IServiceLocator> serviceLocator,
Mock<IRepository<Post>> repository,
int postId,
string message,
InvalidOperationException innerException)
{
// Given
var exception = new Exception(message, innerException);
serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
repository.Setup(s => s.Find(It.IsAny<Expression<Func<Post, bool>>>())).Throws(exception);
var sut = new SetPostCommand();
ServiceLocator.SetCurrentInstance(serviceLocator.Object);
// When
sut.Id = postId;
// Then
Assert.Throws(innerException.GetType(), () => sut.Invoke<Post>().Any());
}
示例4: Should_report_failed_specification_end_to_TeamCity_with_exception
public void Should_report_failed_specification_end_to_TeamCity_with_exception()
{
Exception exception = new InvalidOperationException();
using (Mocks.Record())
{
_messageProvider.TestStarted(null);
LastCall.IgnoreArguments();
_messageProvider.TestFailed(null, null, null, null);
LastCall.Constraints(Is.Anything(), Is.Equal(exception.Message), Is.Null(), Is.Equal(exception.GetType().FullName));
_messageProvider.TestFinished(null);
LastCall.IgnoreArguments();
}
_sut.OnContextStart(_contextInfo);
using (Mocks.Playback())
{
_sut.OnSpecificationStart(_specificationInfo);
_sut.OnSpecificationEnd(_specificationInfo, Result.Failure(exception));
}
}
开发者ID:stephen-czetty,项目名称:nant-extensions,代码行数:24,代码来源:When_the_TeamCity_listener_monitors_specification_ends.cs
示例5: Invoke_WithException_ThrowsSameException
public void Invoke_WithException_ThrowsSameException(
Mock<Common.IServiceLocator> serviceLocator,
Mock<IRepository<Post>> repository,
InvalidOperationException exception)
{
// Given
serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
repository.Setup(s => s.Find(It.IsAny<string[]>())).Throws(exception);
var sut = new GetPostCommand();
ServiceLocator.SetCurrentInstance(serviceLocator.Object);
// Then
Assert.Throws(exception.GetType(), () => sut.Invoke<Post>().Any());
}
示例6: TS_Value
// -------------------------------------------------------------------
// Get ValuePattern.Value property
// -------------------------------------------------------------------
private void TS_Value(ValuePattern valuePattern, CheckType checkType)
{
bool isPassword = m_le.Current.IsPassword;
string value = "";
try
{
value = valuePattern.Current.Value;
}
catch (Exception actualException)
{
InvalidOperationException ex = new InvalidOperationException();
if (Library.IsCriticalException(actualException))
throw;
TestException(ex.GetType(), actualException, "TS_Value", checkType);
}
Comment("ValuePattern.Value = " + value);
m_TestStep++;
}
示例7: TestRemoveFromSelectionMethod51701
public void TestRemoveFromSelectionMethod51701(TestCaseAttribute testCase)
{
HeaderComment(testCase);
InvalidOperationException ex = new InvalidOperationException("Unused, just need an instance for GetType() below");
RemoveFromSelectionHelper(ex.GetType());
}
示例8: TestRangeFromChildMethod20302
public void TestRangeFromChildMethod20302(TestCaseAttribute testCase)
{
HeaderComment(testCase);
InvalidOperationException ex = new InvalidOperationException("Unused, just need an instance for GetType() below");
RangeFromChildHelper(SampleText.String1, false, AutoElementType.SameAsPattern, ex.GetType());
}
示例9: GetUdpBytes
/// <summary>
/// expect packet from transport.<para/>
/// the transport must be a TcpServer, UdpClient or UdpServer.
/// </summary>
/// <param name="filter">
/// a Filter delegate that specifies the endpoint to receive data.<para/>
/// if null, receive data from any endpoint.
/// </param>
/// <param name="timeout">
/// a TimeSpan object that indicates the timeout to expect event.
/// </param>
/// <param name="removeEvent">
/// a bool value that indicates whether need to remove the event from buffer.
/// </param>
/// <param name="remoteEndPoint">
/// an object that specifies the remote endpoint expected packet.
/// </param>
/// <param name="localEndPoint">
/// an object that indicates the local endpoint received packet at.
/// </param>
/// <returns>
/// a UdpReceivedBytes object that specifies the received udp packet.<para/>
/// never return null, if no packets, throw exception.
/// </returns>
/// <exception cref="InvalidOperationException">
/// thrown when the received udp packet is invalid
/// </exception>
/// <exception cref="InvalidOperationException">
/// thrown when exception arrived when expect bytes from udp client.
/// </exception>
private UdpReceivedBytes GetUdpBytes(
Filter<UdpReceivedBytes> filter, TimeSpan timeout, bool removeEvent,
out object remoteEndPoint, out object localEndPoint)
{
UdpReceivedBytes bytes = null;
if (filter == null)
{
bytes = this.buffer.Dequeue(timeout);
}
else
{
bytes = this.buffer.Dequeue(timeout, filter);
}
if (bytes == null)
{
throw new InvalidOperationException("the received udp packet is invalid");
}
remoteEndPoint = bytes.RemoteEndPoint;
localEndPoint = bytes.LocalEndPoint;
// exception event arrived
if (bytes.Packet == null)
{
if (!removeEvent)
{
this.buffer.Enqueue(bytes);
}
InvalidOperationException exc =
new InvalidOperationException("exception arrived when expect bytes from udp client.");
// identify this exception.
exc.Data.Add(exc.GetType().Name, true);
throw exc;
}
return bytes;
}
示例10: HandleOperationException
/// <summary>operation with exception</summary>
/// <param name="e">exception object</param>
/// <param name="response">response object</param>
private void HandleOperationException(InvalidOperationException e, IODataResponseMessage response)
{
Debug.Assert(this.entryIndex >= 0 && this.entryIndex < this.ChangedEntries.Count(), string.Format(System.Globalization.CultureInfo.InvariantCulture, "this.entryIndex = '{0}', this.ChangedEntries.Count = '{1}'", this.entryIndex, this.ChangedEntries.Count()));
Descriptor current = this.ChangedEntries[this.entryIndex];
HeaderCollection headers = null;
HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
Version responseVersion = null;
if (null != response)
{
headers = new HeaderCollection(response);
statusCode = (HttpStatusCode)response.StatusCode;
this.HandleOperationResponseHeaders(statusCode, headers);
e = BaseSaveResult.HandleResponse(
this.RequestInfo,
statusCode,
response.GetHeader(XmlConstants.HttpODataVersion),
response.GetStream,
false/*throwOnFailure*/,
out responseVersion);
}
else
{
headers = new HeaderCollection();
headers.SetHeader(XmlConstants.HttpContentType, XmlConstants.MimeTextPlain);
// In V2 we used to merge individual responses from a call to SaveChanges() into a single batch response payload and then process that.
// When we encounter an exception at this point in V2, we used to write the exception to the batch response payload and later on when we
// process through the batch response, we create a DataServiceClientException for each failed operation.
// For backcompat reason, we will always convert the exception type to DataServiceClientException here.
Debug.Assert(e != null, "e != null");
if (e.GetType() != typeof(DataServiceClientException))
{
e = new DataServiceClientException(e.Message, e);
}
}
// For error scenarios, we never invoke the ReadingEntity event.
this.cachedResponses.Add(new CachedResponse(current, headers, statusCode, responseVersion, null, e));
this.perRequest = null;
this.CheckContinueOnError();
}
示例11: write_log_exception
public void write_log_exception()
{
var ex = new InvalidOperationException("Fake Exception");
//Act
Logger.ErrorException(UniqueMessage, ex);
//Assert
var logItem = Db.Fetch<Log>().Single();
VerifyLog(logItem, LogLevel.Error);
logItem.Message.Should().Be(UniqueMessage + ": " + ex.Message);
logItem.ExceptionType.Should().Be(ex.GetType().ToString());
logItem.Exception.Should().Be(ex.ToString());
ExceptionVerification.ExpectedErrors(1);
}
示例12: GetPacket
/// <summary>
/// get packet from packet cache or decode from buffer.
/// </summary>
/// <param name="timeout">
/// a TimeSpan object that specifies the timeout
/// </param>
/// <param name="removeEvent">
/// a bool value that indicates whether need to remove the event from buffer.
/// </param>
/// <param name="remoteEndPoint">
/// an object that specifies the remote endpoint.
/// </param>
/// <returns>
/// a StackPacket object that contains the decoded packet.
/// </returns>
private StackPacket GetPacket(TimeSpan timeout, bool removeEvent, out object remoteEndPoint)
{
// get the packet in packet list.
IPEndPointStackPacket packet = Utility.GetOne<IPEndPointStackPacket>(this.packetCache, null);
if (packet != null)
{
remoteEndPoint = packet.RemoteEndPoint;
return packet.Packet;
}
UdpReceivedBytes bytes = this.buffer.Dequeue(timeout);
remoteEndPoint = bytes.RemoteEndPoint;
// exception event arrived
if (bytes.Packet == null)
{
if (!removeEvent)
{
this.buffer.Enqueue(bytes);
}
InvalidOperationException exc =
new InvalidOperationException("exception arrived when expect packet from udp.");
// identify this exception.
exc.Data.Add(exc.GetType().Name, true);
throw exc;
}
// decode packets using data in buffer.
int consumedLength = 0;
int expectedLength = 0;
StackPacket[] packets = this.decoder(remoteEndPoint, bytes.Packet, out consumedLength, out expectedLength);
// if no packet, drop the recieved data and continue.
if (packets == null || packets.Length == 0)
{
throw new InvalidOperationException("udp client failed to decode udp packet");
}
// if packet arrived, add to packet list, and return the first.
foreach (StackPacket item in packets)
{
this.packetCache.Enqueue(
new IPEndPointStackPacket(item, bytes.RemoteEndPoint, bytes.LocalEndPoint));
}
// set timeout to zero. when packet is decoded, must not wait.
return GetPacket(new TimeSpan(), removeEvent, out remoteEndPoint);
}
示例13: Invoke_WithExceptionAndInnerException_ThrowsInnerException
public void Invoke_WithExceptionAndInnerException_ThrowsInnerException(
Mock<Common.IServiceLocator> serviceLocator,
Mock<IRepository<Post>> repository,
string title,
string message,
InvalidOperationException innerException)
{
// Given
var exception = new Exception(message, innerException);
serviceLocator.Setup(s => s.GetInstance<IRepository<Post>>()).Returns(repository.Object);
repository.Setup(s => s.Save(It.IsAny<Post>())).Throws(exception);
var sut = new NewPostCommand();
ServiceLocator.SetCurrentInstance(serviceLocator.Object);
sut.Title = title;
// Then
Assert.Throws(innerException.GetType(), () => sut.Invoke<Post>().Any());
}
示例14: HandleOperationException
private void HandleOperationException(InvalidOperationException e, HttpWebResponse response)
{
Func<Stream> getResponseStream = null;
Descriptor descriptor = base.ChangedEntries[base.entryIndex];
Dictionary<string, string> headers = null;
HttpStatusCode internalServerError = HttpStatusCode.InternalServerError;
Version parsedResponseVersion = null;
if (response != null)
{
headers = WebUtil.WrapResponseHeaders(response);
base.HandleOperationResponseHeaders(response.StatusCode, headers);
if (getResponseStream == null)
{
getResponseStream = () => WebUtil.GetResponseStream(response, (DataServiceContext) this.Source);
}
e = BaseSaveResult.HandleResponse(base.RequestInfo, response.StatusCode, response.Headers["DataServiceVersion"], getResponseStream, false, out parsedResponseVersion);
internalServerError = response.StatusCode;
}
else
{
headers = new Dictionary<string, string>(StringComparer.Ordinal);
headers.Add("Content-Type", "text/plain");
if (e.GetType() != typeof(DataServiceClientException))
{
e = new DataServiceClientException(e.Message, e);
}
}
this.cachedResponses.Add(new CachedResponse(descriptor, headers, internalServerError, parsedResponseVersion, null, e));
base.perRequest = null;
this.CheckContinueOnError();
}
示例15: BuildThrowsAnyExeptionNotCatched
public void BuildThrowsAnyExeptionNotCatched(
InvalidOperationException exception,
[Frozen] ICommand<BuildParameters> buildCommand,
[Greedy] TfsBuilderController sut,
BuildParameters parameters)
{
parameters.PayLoad = "dummy";
Mock.Get(buildCommand).Setup(x => x.Execute(parameters)).Throws(exception);
Assert.Throws(exception.GetType(), () => sut.Build(parameters));
}