RuntimeCreationTests.cs 1.2 KB

1234567891011121314151617181920212223242526272829
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using System.Text;
  4. using Microsoft.AspNetCore.Http.Features;
  5. using Microsoft.AspNetCore.Routing;
  6. using Microsoft.CodeAnalysis;
  7. using Microsoft.Extensions.DependencyInjection;
  8. using Microsoft.Extensions.Logging;
  9. namespace Microsoft.AspNetCore.Http.Generators.Tests;
  10. public partial class RuntimeCreationTests : RequestDelegateCreationTests
  11. {
  12. protected override bool IsGeneratorEnabled { get; } = false;
  13. [Theory]
  14. [InlineData("BindAsyncWrongType")]
  15. [InlineData("BindAsyncFromStaticAbstractInterfaceWrongType")]
  16. [InlineData("InheritBindAsyncWrongType")]
  17. public async Task MapAction_BindAsync_WithWrongType_IsNotUsed(string bindAsyncType)
  18. {
  19. var source = $$"""
  20. app.MapGet("/", ({{bindAsyncType}} myNotBindAsyncParam) => { });
  21. """;
  22. var (result, compilation) = await RunGeneratorAsync(source);
  23. var ex = Assert.Throws<InvalidOperationException>(() => GetEndpointFromCompilation(compilation));
  24. Assert.StartsWith($"BindAsync method found on {bindAsyncType} with incorrect format.", ex.Message);
  25. }
  26. }