public void SetterAllowsInPlaceModificationOfParameters()
    {
        var context = new EndpointFilterInvocationContext <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 void ProhibitsActionsThatModifyListSize()
    {
        var context = new EndpointFilterInvocationContext <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 EndpointFilterInvocationContext <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 EndpointFilterInvocationContext <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 EndpointFilterInvocationContext <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 void SetterDoesNotAllowModificationOfParameterType()
    {
        var context = new EndpointFilterInvocationContext <string, int, bool, Todo>(new DefaultHttpContext(), "This is a test", 42, false, new Todo());

        Assert.Throws <InvalidCastException>(() => context[0] = 4);
    }