public void SetterAllowsInPlaceModificationOfParameters() { var context = new RouteHandlerInvocationContext <string, int, bool, Todo>(new DefaultHttpContext(), "This is a test", 42, false, new Todo()); context[0] = "Foo"; Assert.Equal("Foo", context.GetArgument <string>(0)); }
public virtual async ValueTask <object?> InvokeAsync(RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next) { Logger.LogInformation("{MethodName} Before next", _methodName); var result = await next(context); Logger.LogInformation("{MethodName} After next", _methodName); return(result); }
public void ProhibitsActionsThatModifyListSize() { var context = new RouteHandlerInvocationContext <string, int, bool>(new DefaultHttpContext(), "This is a test", 42, false); Assert.Throws <NotSupportedException>(() => context.Add("string")); Assert.Throws <NotSupportedException>(() => context.Insert(0, "string")); Assert.Throws <NotSupportedException>(() => context.RemoveAt(0)); Assert.Throws <NotSupportedException>(() => context.Remove("string")); Assert.Throws <NotSupportedException>(() => context.Clear()); }
public void HandlesMismatchedNullabilityOnTypeParams() { var context = new RouteHandlerInvocationContext <string?, int?, bool?, Todo?>(new DefaultHttpContext(), null, null, null, null); // Mismatched reference types will resolve as null Assert.Null(context.GetArgument <string>(0)); Assert.Null(context.GetArgument <Todo>(3)); // Mismatched value types will throw Assert.Throws <NullReferenceException>(() => context.GetArgument <int>(1)); Assert.Throws <NullReferenceException>(() => context.GetArgument <bool>(2)); }
public void ThrowsExceptionForInvalidCastOnGetArgument() { var context = new RouteHandlerInvocationContext <string, int, bool, Todo>(new DefaultHttpContext(), "This is a test", 42, false, new Todo()); Assert.Throws <InvalidCastException>(() => context.GetArgument <string>(1)); Assert.Throws <InvalidCastException>(() => context.GetArgument <int>(0)); Assert.Throws <InvalidCastException>(() => context.GetArgument <string>(3)); var todo = context.GetArgument <ITodo>(3); Assert.IsType <Todo>(todo); }
public void AllowsEnumerationOfParameters() { var context = new RouteHandlerInvocationContext <string, int, bool, Todo>(new DefaultHttpContext(), "This is a test", 42, false, new Todo()); var enumeratedCount = 0; foreach (var parameter in context) { Assert.NotNull(parameter); enumeratedCount++; } Assert.Equal(4, enumeratedCount); }
public async ValueTask <object?> InvokeAsync(RouteHandlerInvocationContext rhiContext, RouteHandlerFilterDelegate next) { var todo = rhiContext.GetArgument <Todo>(0); var validationError = Utilities.IsValid(todo !); if (!string.IsNullOrEmpty(validationError)) { _logger.LogWarning(validationError); return(Results.Problem(validationError)); } return(await next(rhiContext)); }
public void SetterDoesNotAllowModificationOfParameterType() { var context = new RouteHandlerInvocationContext <string, int, bool, Todo>(new DefaultHttpContext(), "This is a test", 42, false, new Todo()); Assert.Throws <InvalidCastException>(() => context[0] = 4); }