public async Task Should_Not_Parse_Null_InstanceId() { _httpContext.Request.RouteValues.Add("instanceIdFromRoute", null); await _sut.InvokeAsync(_httpContext, context => Task.CompletedTask); A.CallTo(() => _instanceIdContextProvider.SetInstanceId(A <string> ._)).MustNotHaveHappened(); }
public void OnActionExecuting(ActionExecutingContext context) { if (!context.HttpContext.Request.RouteValues.TryGetValue("instanceIdFromRoute", out object instance)) { return; } // Convert the object value to a string and see if it is empty string instanceId = instance as string; if (string.IsNullOrEmpty(instanceId)) { return; } //check that the character's are allowed Match match = Regex.Match(instanceId, Pattern); if (!match.Success) { return; } // If we're still here, set the context value _instanceIdContextProvider.SetInstanceId(instanceId); }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { if (context.Request.RouteValues.TryGetValue("instanceIdFromRoute", out object instance)) { // Convert the object value to a string and see if it is empty var instanceId = instance as string; if (!string.IsNullOrEmpty(instanceId)) { //check that the character's are allowed Match match = Regex.Match(instanceId, Pattern); if (match.Success) { // If we're still here, set the context value _instanceIdContextProvider.SetInstanceId(instanceId); } } } await next(context); }