using System;
using Amazon.Runtime;
using Amazon.Runtime.Internal;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AWSSDK.UnitTests
{
///
/// Helper class for testing plumbing. Works by throwing
/// an exception to halt pipeline execution, but preserving a reference to the final
/// so Tests can against it.
///
///
///
///
/// Wraps the real , but tweaks said client to make it more test friendly
/// by adding a handler to 1) prevent an actual outbound http request as well as
/// 2) capturing the final request's so Tests can assert against it.
///
/// private class AmazonBearerTokenAuthTestClientTestFixture : AmazonBearerTokenAuthTestClient
/// {
/// private readonly TerminatePipeline _terminatePipeline = new TerminatePipeline();
///
/// public IExecutionContext CapturedContext => _terminatePipeline.CapturedContext;
///
/// public AmazonBearerTokenAuthTestClientTestFixture(AmazonBearerTokenAuthTestConfig config) : base(config)
/// {
/// RuntimePipeline.AddHandlerBefore>(_terminatePipeline);
/// }
/// }
/// ]]>
///
///
public class TerminatePipeline : PipelineHandler
{
public IExecutionContext CapturedContext { get; set; }
public override void InvokeSync(IExecutionContext executionContext)
{
CapturedContext = executionContext;
throw new Exception("Terminating Pipeline");
}
#if AWS_ASYNC_API
public override System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext)
{
CapturedContext = executionContext;
throw new Exception("Terminating Pipeline");
}
#endif
}
}