本文整理汇总了C#中TestTraceWriter类的典型用法代码示例。如果您正苦于以下问题:C# TestTraceWriter类的具体用法?C# TestTraceWriter怎么用?C# TestTraceWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestTraceWriter类属于命名空间,在下文中一共展示了TestTraceWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteBindingAsync_Traces_And_Invokes_Inner
public void ExecuteBindingAsync_Traces_And_Invokes_Inner()
{
// Arrange
Mock<HttpParameterDescriptor> mockParamDescriptor = new Mock<HttpParameterDescriptor>() { CallBase = true };
mockParamDescriptor.Setup(d => d.ParameterName).Returns("paramName");
mockParamDescriptor.Setup(d => d.ParameterType).Returns(typeof(string));
Mock<HttpParameterBinding> mockBinding = new Mock<HttpParameterBinding>(mockParamDescriptor.Object) { CallBase = true };
bool innerInvoked = false;
mockBinding.Setup(
b =>
b.ExecuteBindingAsync(It.IsAny<ModelMetadataProvider>(), It.IsAny<HttpActionContext>(),
It.IsAny<CancellationToken>())).Returns(TaskHelpers.Completed()).Callback(() => innerInvoked = true);
TestTraceWriter traceWriter = new TestTraceWriter();
HttpParameterBindingTracer tracer = new HttpParameterBindingTracer(mockBinding.Object, traceWriter);
HttpActionContext actionContext = ContextUtil.CreateActionContext();
ModelMetadataProvider metadataProvider = new EmptyModelMetadataProvider();
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ExecuteBindingAsync" },
new TraceRecord(actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "ExecuteBindingAsync" }
};
// Act
Task task = tracer.ExecuteBindingAsync(metadataProvider, actionContext, CancellationToken.None);
task.Wait();
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.True(innerInvoked);
}
示例2: ExecuteAsync_Faults_And_Traces_When_Inner_Faults
public void ExecuteAsync_Faults_And_Traces_When_Inner_Faults()
{
// Arrange
InvalidOperationException exception = new InvalidOperationException();
TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompletionSource<HttpResponseMessage>();
tcs.TrySetException(exception);
Mock<ApiController> mockController = new Mock<ApiController>() { CallBase = true };
mockController.Setup(b => b.ExecuteAsync(It.IsAny<HttpControllerContext>(), It.IsAny<CancellationToken>())).Returns(tcs.Task);
HttpControllerContext controllerContext = ContextUtil.CreateControllerContext(request: new HttpRequestMessage());
controllerContext.ControllerDescriptor = _controllerDescriptor;
controllerContext.Controller = mockController.Object;
HttpActionContext actionContext = ContextUtil.CreateActionContext(controllerContext, actionDescriptor: _mockActionDescriptor.Object);
TestTraceWriter traceWriter = new TestTraceWriter();
HttpControllerTracer tracer = new HttpControllerTracer(mockController.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(actionContext.Request, TraceCategories.ControllersCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
new TraceRecord(actionContext.Request, TraceCategories.ControllersCategory, TraceLevel.Error) { Kind = TraceKind.End }
};
// Act
Exception thrown = Assert.Throws<InvalidOperationException>(() => ((IHttpController)tracer).ExecuteAsync(controllerContext, CancellationToken.None).Wait());
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
}
示例3: SendAsync_Traces_And_Invokes_Inner
public void SendAsync_Traces_And_Invokes_Inner()
{
// Arrange
HttpResponseMessage response = new HttpResponseMessage();
MockDelegatingHandler mockHandler = new MockDelegatingHandler((rqst, cancellation) =>
TaskHelpers.FromResult<HttpResponseMessage>(response));
TestTraceWriter traceWriter = new TestTraceWriter();
MessageHandlerTracer tracer = new MessageHandlerTracer(mockHandler, traceWriter);
MockHttpMessageHandler mockInnerHandler = new MockHttpMessageHandler((rqst, cancellation) =>
TaskHelpers.FromResult<HttpResponseMessage>(response));
tracer.InnerHandler = mockInnerHandler;
HttpRequestMessage request = new HttpRequestMessage();
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.MessageHandlersCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "SendAsync" },
new TraceRecord(request, TraceCategories.MessageHandlersCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "SendAsync" }
};
MethodInfo method = typeof(DelegatingHandler).GetMethod("SendAsync",
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance);
// Act
Task<HttpResponseMessage> task = method.Invoke(tracer, new object[] { request, CancellationToken.None }) as Task<HttpResponseMessage>;
HttpResponseMessage actualResponse = task.Result;
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(response, actualResponse);
}
示例4: Create_Throws_And_Traces_When_Inner_Throws
public void Create_Throws_And_Traces_When_Inner_Throws()
{
// Arrange
Mock<ApiController> mockController = new Mock<ApiController>();
Mock<IHttpControllerActivator> mockActivator = new Mock<IHttpControllerActivator>() { CallBase = true };
InvalidOperationException exception = new InvalidOperationException("test");
mockActivator.Setup(b => b.Create(It.IsAny<HttpRequestMessage>(), It.IsAny<HttpControllerDescriptor>(), It.IsAny<Type>())).Throws(exception);
HttpRequestMessage request = new HttpRequestMessage();
TestTraceWriter traceWriter = new TestTraceWriter();
HttpControllerActivatorTracer tracer = new HttpControllerActivatorTracer(mockActivator.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.ControllersCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "Create" },
new TraceRecord(request, TraceCategories.ControllersCategory, TraceLevel.Error) { Kind = TraceKind.End, Operation = "Create" }
};
// Act & Assert
Exception thrown = Assert.Throws<InvalidOperationException>(() => ((IHttpControllerActivator)tracer).Create(request, controllerDescriptor: null, controllerType: mockController.Object.GetType()));
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
}
示例5: ExecuteExceptionFilterAsync_Traces
public void ExecuteExceptionFilterAsync_Traces()
{
// Arrange
HttpRequestMessage request = new HttpRequestMessage();
HttpResponseMessage response = new HttpResponseMessage();
Mock<IExceptionFilter> mockFilter = new Mock<IExceptionFilter>() { CallBase = true };
mockFilter.Setup(
f => f.ExecuteExceptionFilterAsync(It.IsAny<HttpActionExecutedContext>(), It.IsAny<CancellationToken>())).
Returns(TaskHelpers.Completed());
HttpActionExecutedContext actionExecutedContext = ContextUtil.GetActionExecutedContext(request, response);
TestTraceWriter traceWriter = new TestTraceWriter();
ExceptionFilterTracer tracer = new ExceptionFilterTracer(mockFilter.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ExecuteExceptionFilterAsync" },
new TraceRecord(request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "ExecuteExceptionFilterAsync" },
};
// Act
Task task = ((IExceptionFilter)tracer).ExecuteExceptionFilterAsync(actionExecutedContext, CancellationToken.None);
task.Wait();
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
}
示例6: ExecuteBindingAsync_Faults_And_Traces_When_Inner_Faults
public void ExecuteBindingAsync_Faults_And_Traces_When_Inner_Faults()
{
// Arrange
InvalidOperationException exception = new InvalidOperationException();
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
tcs.TrySetException(exception);
Mock<HttpActionBinding> mockBinder = new Mock<HttpActionBinding>() { CallBase = true };
mockBinder.Setup(b => b.ExecuteBindingAsync(
It.IsAny<HttpActionContext>(),
It.IsAny<CancellationToken>())).
Returns(tcs.Task);
TestTraceWriter traceWriter = new TestTraceWriter();
HttpActionBindingTracer tracer = new HttpActionBindingTracer(mockBinder.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(_actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
new TraceRecord(_actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Error) { Kind = TraceKind.End }
};
// Act
Task task = tracer.ExecuteBindingAsync(_actionContext, CancellationToken.None);
// Assert
Exception thrown = Assert.Throws<InvalidOperationException>(() => task.Wait());
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
}
示例7: OnReadFromStreamAsync_Traces_And_Faults_When_Inner_Faults
public void OnReadFromStreamAsync_Traces_And_Faults_When_Inner_Faults()
{
// Arrange
InvalidOperationException exception = new InvalidOperationException("test");
Mock<MediaTypeFormatter> mockFormatter = new Mock<MediaTypeFormatter>() { CallBase = true };
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
tcs.TrySetException(exception);
mockFormatter.Setup(
f => f.ReadFromStreamAsync(It.IsAny<Type>(), It.IsAny<Stream>(), It.IsAny<HttpContentHeaders>(), It.IsAny<IFormatterLogger>())).
Returns(tcs.Task);
TestTraceWriter traceWriter = new TestTraceWriter();
HttpRequestMessage request = new HttpRequestMessage();
request.Content = new StringContent("");
MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ReadFromStreamAsync" },
new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Error) { Kind = TraceKind.End, Operation = "ReadFromStreamAsync" }
};
// Act
Task<object> task = tracer.ReadFromStreamAsync(typeof(string), new MemoryStream(), request.Content.Headers, null);
// Assert
Exception thrown = Assert.Throws<InvalidOperationException>(() => task.Wait());
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
}
示例8: ReadFromStream_Traces_And_Throws_When_Inner_Throws
public void ReadFromStream_Traces_And_Throws_When_Inner_Throws()
{
// Arrange
InvalidOperationException exception = new InvalidOperationException("test");
Mock<BufferedMediaTypeFormatter> mockFormatter = new Mock<BufferedMediaTypeFormatter>() { CallBase = true };
mockFormatter.Setup(
f => f.ReadFromStream(It.IsAny<Type>(), It.IsAny<Stream>(), It.IsAny<HttpContent>(), It.IsAny<IFormatterLogger>())).Throws(exception);
TestTraceWriter traceWriter = new TestTraceWriter();
HttpRequestMessage request = new HttpRequestMessage();
request.Content = new StringContent("");
BufferedMediaTypeFormatterTracer tracer = new BufferedMediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ReadFromStream" },
new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Error) { Kind = TraceKind.End, Operation = "ReadFromStream" }
};
// Act
Exception thrown = Assert.Throws<InvalidOperationException>(() => tracer.ReadFromStream(typeof(string), new MemoryStream(), request.Content, null));
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
}
示例9: OnReadFromStreamAsync_Traces
public void OnReadFromStreamAsync_Traces()
{
// Arrange
Mock<MediaTypeFormatter> mockFormatter = new Mock<MediaTypeFormatter>() { CallBase = true };
mockFormatter.Setup(
f => f.ReadFromStreamAsync(It.IsAny<Type>(), It.IsAny<Stream>(), It.IsAny<HttpContentHeaders>(), It.IsAny<IFormatterLogger>())).
Returns(TaskHelpers.FromResult<object>("sampleValue"));
TestTraceWriter traceWriter = new TestTraceWriter();
HttpRequestMessage request = new HttpRequestMessage();
request.Content = new StringContent("");
MediaTypeFormatterTracer tracer = new MediaTypeFormatterTracer(mockFormatter.Object, traceWriter, request);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ReadFromStreamAsync" },
new TraceRecord(request, TraceCategories.FormattingCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "ReadFromStreamAsync" }
};
// Act
Task<object> task = tracer.ReadFromStreamAsync(typeof(string), new MemoryStream(), request.Content.Headers, null);
string result = task.Result as string;
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Equal("sampleValue", result);
}
示例10: BindValuesAsync_Invokes_Inner_And_Traces
public void BindValuesAsync_Invokes_Inner_And_Traces()
{
// Arrange
bool wasInvoked = false;
Mock<HttpActionBinding> mockBinder = new Mock<HttpActionBinding>() { CallBase = true };
mockBinder.Setup(b => b.ExecuteBindingAsync(
It.IsAny<HttpActionContext>(),
It.IsAny<CancellationToken>())).
Callback(() => wasInvoked = true).Returns(TaskHelpers.Completed());
TestTraceWriter traceWriter = new TestTraceWriter();
HttpActionBindingTracer tracer = new HttpActionBindingTracer(mockBinder.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(_actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
new TraceRecord(_actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Info) { Kind = TraceKind.End }
};
// Act
tracer.ExecuteBindingAsync(_actionContext, CancellationToken.None).Wait();
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.True(wasInvoked);
}
示例11: ExecuteExceptionFilterAsync_Traces
public void ExecuteExceptionFilterAsync_Traces()
{
// Arrange
HttpRequestMessage request = new HttpRequestMessage();
HttpResponseMessage response = new HttpResponseMessage();
Mock<ExceptionFilterAttribute> mockAttr = new Mock<ExceptionFilterAttribute>() { CallBase = true };
Mock<HttpActionDescriptor> mockActionDescriptor = new Mock<HttpActionDescriptor>() { CallBase = true };
mockActionDescriptor.Setup(a => a.ActionName).Returns("test");
mockActionDescriptor.Setup(a => a.GetParameters()).Returns(new Collection<HttpParameterDescriptor>(new HttpParameterDescriptor[0]));
HttpActionExecutedContext actionExecutedContext = ContextUtil.GetActionExecutedContext(request, response);
TestTraceWriter traceWriter = new TestTraceWriter();
ExceptionFilterAttributeTracer tracer = new ExceptionFilterAttributeTracer(mockAttr.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "OnException" },
new TraceRecord(request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "OnException" },
};
// Act
Task task = ((IExceptionFilter)tracer).ExecuteExceptionFilterAsync(actionExecutedContext, CancellationToken.None);
task.Wait();
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
}
示例12: ExecuteExceptionFilterAsync_Throws_And_Traces_When_Inner_OnException_Throws
public void ExecuteExceptionFilterAsync_Throws_And_Traces_When_Inner_OnException_Throws()
{
// Arrange
HttpRequestMessage request = new HttpRequestMessage();
HttpResponseMessage response = new HttpResponseMessage();
Mock<ExceptionFilterAttribute> mockAttr = new Mock<ExceptionFilterAttribute>() { CallBase = true };
InvalidOperationException exception = new InvalidOperationException("test");
mockAttr.Setup(a => a.OnException(It.IsAny<HttpActionExecutedContext>())).Throws(exception);
Mock<HttpActionDescriptor> mockActionDescriptor = new Mock<HttpActionDescriptor>() { CallBase = true };
mockActionDescriptor.Setup(a => a.ActionName).Returns("test");
mockActionDescriptor.Setup(a => a.GetParameters()).Returns(new Collection<HttpParameterDescriptor>(new HttpParameterDescriptor[0]));
HttpActionExecutedContext actionExecutedContext = ContextUtil.GetActionExecutedContext(request, response);
TestTraceWriter traceWriter = new TestTraceWriter();
ExceptionFilterAttributeTracer tracer = new ExceptionFilterAttributeTracer(mockAttr.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "OnException" },
new TraceRecord(request, TraceCategories.FiltersCategory, TraceLevel.Error) { Kind = TraceKind.End, Operation = "OnException" }
};
// Act
Exception thrown =
Assert.Throws<InvalidOperationException>(
() => ((IExceptionFilter) tracer).ExecuteExceptionFilterAsync(actionExecutedContext, CancellationToken.None));
// Assert
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
}
示例13: SendAsync_Traces_And_Faults_When_Inner_Faults
public void SendAsync_Traces_And_Faults_When_Inner_Faults()
{
// Arrange
InvalidOperationException exception = new InvalidOperationException("test");
TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompletionSource<HttpResponseMessage>();
tcs.TrySetException(exception);
TestTraceWriter traceWriter = new TestTraceWriter();
RequestMessageHandlerTracer tracer = new RequestMessageHandlerTracer(traceWriter);
// DelegatingHandlers require an InnerHandler to run. We create a mock one to simulate what
// would happen when a DelegatingHandler executing after the tracer returns a Task that throws.
MockHttpMessageHandler mockInnerHandler = new MockHttpMessageHandler((rqst, cancellation) => { return tcs.Task; });
tracer.InnerHandler = mockInnerHandler;
HttpRequestMessage request = new HttpRequestMessage();
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(request, TraceCategories.RequestCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
new TraceRecord(request, TraceCategories.RequestCategory, TraceLevel.Error) { Kind = TraceKind.End }
};
MethodInfo method = typeof(DelegatingHandler).GetMethod("SendAsync",
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance);
// Act
Task<HttpResponseMessage> task =
method.Invoke(tracer, new object[] { request, CancellationToken.None }) as Task<HttpResponseMessage>;
// Assert
Exception thrown = Assert.Throws<InvalidOperationException>(() => task.Wait());
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(exception, thrown);
Assert.Same(exception, traceWriter.Traces[1].Exception);
}
示例14: ExecuteAsync_Invokes_Inner_And_Traces
public void ExecuteAsync_Invokes_Inner_And_Traces()
{
// Arrange
HttpResponseMessage response = new HttpResponseMessage();
Mock<ApiController> mockController = new Mock<ApiController>() { CallBase = true };
mockController.Setup(b => b.ExecuteAsync(It.IsAny<HttpControllerContext>(), It.IsAny<CancellationToken>())).Returns(TaskHelpers.FromResult<HttpResponseMessage>(response));
HttpControllerContext controllerContext = ContextUtil.CreateControllerContext(request: new HttpRequestMessage());
controllerContext.ControllerDescriptor = _controllerDescriptor;
controllerContext.Controller = mockController.Object;
HttpActionContext actionContext = ContextUtil.CreateActionContext(controllerContext, actionDescriptor: _mockActionDescriptor.Object);
TestTraceWriter traceWriter = new TestTraceWriter();
HttpControllerTracer tracer = new HttpControllerTracer(mockController.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(actionContext.Request, TraceCategories.ControllersCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
new TraceRecord(actionContext.Request, TraceCategories.ControllersCategory, TraceLevel.Info) { Kind = TraceKind.End }
};
// Act
HttpResponseMessage actualResponse = ((IHttpController)tracer).ExecuteAsync(controllerContext, CancellationToken.None).Result;
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
Assert.Same(response, actualResponse);
}
示例15: ExecuteAuthorizationFilterAsync_Traces
public void ExecuteAuthorizationFilterAsync_Traces()
{
// Arrange
HttpResponseMessage response = new HttpResponseMessage();
Mock<IAuthorizationFilter> mockFilter = new Mock<IAuthorizationFilter>() { CallBase = true };
mockFilter.Setup(f => f.ExecuteAuthorizationFilterAsync(It.IsAny<HttpActionContext>(), It.IsAny<CancellationToken>(), It.IsAny<Func<Task<HttpResponseMessage>>>())).Returns(TaskHelpers.FromResult(response));
Mock<HttpActionDescriptor> mockActionDescriptor = new Mock<HttpActionDescriptor>() { CallBase = true };
mockActionDescriptor.Setup(a => a.ActionName).Returns("test");
mockActionDescriptor.Setup(a => a.GetParameters()).Returns(new Collection<HttpParameterDescriptor>(new HttpParameterDescriptor[0]));
HttpActionContext actionContext = ContextUtil.CreateActionContext(actionDescriptor: mockActionDescriptor.Object);
Func<Task<HttpResponseMessage>> continuation = () => TaskHelpers.FromResult<HttpResponseMessage>(new HttpResponseMessage());
TestTraceWriter traceWriter = new TestTraceWriter();
AuthorizationFilterTracer tracer = new AuthorizationFilterTracer(mockFilter.Object, traceWriter);
TraceRecord[] expectedTraces = new TraceRecord[]
{
new TraceRecord(actionContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.Begin, Operation = "ExecuteAuthorizationFilterAsync" },
new TraceRecord(actionContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info) { Kind = TraceKind.End, Operation = "ExecuteAuthorizationFilterAsync" },
};
// Act
Task task = ((IAuthorizationFilter)tracer).ExecuteAuthorizationFilterAsync(actionContext, CancellationToken.None, continuation);
task.Wait();
// Assert
Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
}