/// <summary> /// Creates a <see cref="IFailureHandler"/> instance based on the avaiable testing frameworks. /// </summary> /// <returns>A new <see cref="IFailureHandler"/> instance.</returns> public static IFailureHandler Create() { IEnumerable<Type> types = typeof(FailureHandlerFactory).Assembly.GetTypes() .Where(t => typeof(IFailureHandler).IsAssignableFrom(t) && !t.IsAbstract && t != typeof(FallbackFailureHandler)); foreach (Type type in types) { IFailureHandler handler = Activator.CreateInstance(type) as IFailureHandler; if (handler.IsAvailable()) { return handler; } } return new FallbackFailureHandler(); }
public OutOfProcessQueue( ProcessWatchdog process, ISocketEndPoint endPoint, IFailureHandler failureHandler, FailureSettings failureSettings ) { if (process == null) { throw new ArgumentNullException(nameof(process)); } if (endPoint == null) { throw new ArgumentNullException(nameof(endPoint)); } if (failureHandler == null) { throw new ArgumentNullException(nameof(failureHandler)); } if (failureSettings == null) { throw new ArgumentNullException(nameof(failureSettings)); } _syncRoot = new object(); _process = process; _process.OnFaultDetected += ProcessOnOnFaultDetected; _endPoint = endPoint; _endPoint.OnFailure += EndPointOnOnFailure; _failureHandler = failureHandler; _failureSettings = failureSettings; _actions = new ConcurrentQueue <Operation>(); _thread = new Thread(Do); _thread.Start(); }
/// <summary> /// Initializes a new instance of the ModuleConfiguration class. /// </summary> public HttpAuthenticationConfiguration(IEnumerable <IAuthenticator> inspectors, IFailureHandler failureHandler) { Inspectors = inspectors; FailureHandler = failureHandler; }
/// <summary> /// Initializes a new instance of the <see cref="StringAssertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler.</param> /// <param name="target">The target.</param> public StringAssertion(IFailureHandler failureHandler, string target) : base(failureHandler, target) { }
/// <summary> /// Initializes a new instance of the <see cref="ObjectAssertion{TAssert, TTarget}"/> class. /// </summary> /// <param name="target">The object which is under test.</param> /// <param name="failureHandler">The failure handler of the assertion.</param> public ObjectAssertion(IFailureHandler failureHandler, TTarget target) : base(failureHandler) { Target = target; }
public HttpWebClient(IFailureHandler failureHandler, ILogger <HttpWebClient> logger) { _failureHandler = failureHandler; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="VoidAssertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler of the assertion.</param> /// <param name="action">The action under test.</param> public VoidAssertion(IFailureHandler failureHandler, Action action) : base(failureHandler) { Action = action; }
private static void ExecuteFailureHandler(HttpContextBase context, Dictionary <IAuthenticator, AuthenticationResult> inspectors, IFailureHandler failureHandler) { if (null == failureHandler) { return; } var application = context.ApplicationInstance; if (failureHandler.Configuration.RequireSsl && !context.Request.IsSecureConnection) { log.ErrorFormat(CultureInfo.InvariantCulture, "Inspector configuration requires SSL, but request is not secure"); context.Response.StatusCode = (int)HttpStatusCode.Forbidden; //this is a guard since we can't effectively mock CompleteRequest in tests if (null != application) { application.CompleteRequest(); } return; } //new AuthenticationFailureEvent(this, (null != inspectors[failureInspector] && null != inspectors[failureInspector].Identity ? inspectors[failureInspector].Identity.Name : string.Empty)).Raise(); var failureAction = failureHandler.OnAuthenticationFailure(context, inspectors); context.User = failureAction.User; if (failureAction.ShouldTerminateRequest) { //this is a guard since we can't effectively mock CompleteRequest in tests if (null != application) { application.CompleteRequest(); } } }
/// <summary> /// Initializes a new instance of this silo with the specified options. /// The given host process will only be started once <see cref="Start" /> is called. /// </summary> /// <param name="process"></param> /// <param name="options"></param> /// <param name="codeGenerator">The code generator to create proxy and servant types</param> /// <param name="latencySettings"> /// The settings for latency measurements, if none are specified, then default settings are /// used /// </param> /// <param name="endPointSettings">The settings for the endpoint itself (max. number of concurrent calls, etc...)</param> /// <param name="failureSettings"> /// The settings specifying when a failure is assumed to have occured in the host process - /// if none are specified, then defaults are used /// </param> /// <param name="failureHandler"> /// The object responsible for deciding how failures are dealt with - if none is specified /// then a new <see cref="ZeroFailureToleranceStrategy" /> is used /// </param> /// <param name="endPointName">The name of the endpoint - used in log messages to differentiate between different endpoints</param> /// <exception cref="ArgumentNullException">When <paramref name="process" /> is null</exception> /// <exception cref="ArgumentException">When <paramref name="process" /> is contains only whitespace</exception> public OutOfProcessSilo( string process = ProcessWatchdog.SharpRemoteHost, ProcessOptions options = ProcessOptions.HideConsole, ICodeGenerator codeGenerator = null, LatencySettings latencySettings = null, EndPointSettings endPointSettings = null, FailureSettings failureSettings = null, IFailureHandler failureHandler = null, string endPointName = null ) { if (process == null) { throw new ArgumentNullException(nameof(process)); } if (string.IsNullOrWhiteSpace(process)) { throw new ArgumentException("process"); } if (failureSettings != null) { if (failureSettings.ProcessReadyTimeout <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(failureSettings), "ProcessReadyTimeout should be greater than zero"); } if (failureSettings.EndPointConnectTimeout <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(failureSettings), "EndPointConnectTimeout should be greater than zero"); } } failureSettings = failureSettings ?? new FailureSettings(); failureHandler = failureHandler ?? new ZeroFailureToleranceStrategy(); _endPoint = new SocketEndPoint(EndPointType.Client, endPointName, codeGenerator: codeGenerator, heartbeatSettings: failureSettings.HeartbeatSettings, latencySettings: latencySettings, endPointSettings: endPointSettings, waitUponReadWriteError: true); _subjectHost = _endPoint.CreateProxy <ISubjectHost>(Constants.SubjectHostId); _syncRoot = new object(); _process = new ProcessWatchdog( process, options ); _process.OnHostOutputWritten += EmitHostOutputWritten; _queue = new OutOfProcessQueue( _process, _endPoint, failureHandler, failureSettings ); _queue.OnHostStarted += QueueOnOnHostStarted; }
/// <summary> /// Initializes a new instance of the <see cref="FallbackFailureHandlerTests"/> class. /// </summary> public FallbackFailureHandlerTests() { handler = new FallbackFailureHandler(); }
/// <summary> /// Initializes a new instance of the <see cref="DoubleAssertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler of the assertion.</param> /// <param name="target">The object which is under test.</param> public DoubleAssertion(IFailureHandler failureHandler, double target) : base(failureHandler, target) { }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionAssertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler.</param> /// <param name="exception">The exception.</param> public ExceptionAssertion(IFailureHandler failureHandler, Exception exception) : base(failureHandler, exception) { }
/// <summary> /// Initializes a new instance of the <see cref="EnumerableAssertion{TElement}"/> class. /// </summary> /// <param name="failureHandler">The failure handler of the assertion.</param> /// <param name="target">The object which is under test.</param> public EnumerableAssertion(IFailureHandler failureHandler, IEnumerable <TElement> target) : base(failureHandler, target) { }
/// <summary> /// Initializes a new instance of the ModuleConfiguration class. /// </summary> public HttpAuthenticationConfiguration(IEnumerable<IAuthenticator> inspectors, IFailureHandler failureHandler) { Inspectors = inspectors; FailureHandler = failureHandler; }
/// <summary> /// Initializes a new instance of the <see cref="SingleAssertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler of the assertion.</param> /// <param name="target">The object which is under test.</param> public SingleAssertion(IFailureHandler failureHandler, object target) : base(failureHandler, target) { }
/// <summary> /// Initializes a new instance of the <see cref="BooleanAssertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler of the assertion.</param> /// <param name="target">The object which is under test.</param> public BooleanAssertion(IFailureHandler failureHandler, bool target) : base(failureHandler, target) { }
/// <summary> /// Initializes a new instance of the <see cref="Assertion"/> class. /// </summary> /// <param name="failureHandler">The failure handler of the assertion.</param> public Assertion(IFailureHandler failureHandler) { FailureHandler = failureHandler; }
private static void ExecuteFailureHandler(HttpContextBase context, Dictionary<IAuthenticator, AuthenticationResult> inspectors, IFailureHandler failureHandler) { if (null == failureHandler) return; var application = context.ApplicationInstance; if (failureHandler.Configuration.RequireSsl && !context.Request.IsSecureConnection) { log.ErrorFormat(CultureInfo.InvariantCulture, "Inspector configuration requires SSL, but request is not secure"); context.Response.StatusCode = (int)HttpStatusCode.Forbidden; //this is a guard since we can't effectively mock CompleteRequest in tests if (null != application) { application.CompleteRequest(); } return; } //new AuthenticationFailureEvent(this, (null != inspectors[failureInspector] && null != inspectors[failureInspector].Identity ? inspectors[failureInspector].Identity.Name : string.Empty)).Raise(); var failureAction = failureHandler.OnAuthenticationFailure(context, inspectors); context.User = failureAction.User; if (failureAction.ShouldTerminateRequest) { //this is a guard since we can't effectively mock CompleteRequest in tests if (null != application) { application.CompleteRequest(); } } }