Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
layomia committed Apr 7, 2023
1 parent d68947f commit e517bb8
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public void It_resolves_offbydefaultgenerator_correctly(GeneratorSpec generator,
if (isEnabled != null)
{
var ns = project.Root.Name.Namespace;
// Delete when we have a new targeting pack that contains Microsoft.Extensions.Configuration.Binder.SourceGeneration.
if (generator == GeneratorSpec.ConfigurationBinding)
{
project.Root.Add(new XElement(ns + "ItemGroup", new XElement("Analyzer", new XAttribute("Include", "does_not_yet_exist\Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll"))));
}
project.Root.Add(new XElement(ns + "PropertyGroup", new XElement(generator.EnablingPropertyName, isEnabled)));
}
});
Expand All @@ -43,20 +48,24 @@ public void It_resolves_offbydefaultgenerator_correctly(GeneratorSpec generator,
}

[Theory]
[InlineData("Microsoft.AspNetCore.Http.RequestDelegateGenerator.dll")]
[InlineData("Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll")]
public void It_enables_offbydefaultgenerator_for_PublishAot()
[MemberData(nameof(OffByDefaultGenerators))]
public void It_enables_offbydefaultgenerator_for_PublishAot(GeneratorSpec generator)
{
var asset = _testAssetsManager
.CopyTestAsset("WebApp")
.WithSource()
.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
// Delete when we have a new targeting pack that contains Microsoft.Extensions.Configuration.Binder.SourceGeneration.
if (generator == GeneratorSpec.ConfigurationBinding)
{
project.Root.Add(new XElement(ns + "ItemGroup", new XElement("Analyzer", new XAttribute("Include", "does_not_yet_exist\Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll"))));
}
project.Root.Add(new XElement(ns + "PropertyGroup", new XElement("PublishAot", "true")));
});

VerifyOffByDefaultGeneratorIsUsed(asset, expectEnabled: true);
VerifyOffByDefaultGeneratorIsUsed(asset, generator.DllFileName, expectEnabled: true);
}

private void VerifyOffByDefaultGeneratorIsUsed(TestAsset asset, string dllFileName, bool? expectEnabled)
Expand All @@ -78,21 +87,28 @@ private void VerifyOffByDefaultGeneratorIsUsed(TestAsset asset, string dllFileNa
Assert.Equal(expectEnabled ?? false, analyzers.Any(analyzer => analyzer.Contains(dllFileName)));
}

private record GeneratorSpec(string EnablingPropertyName, string DllFileName)
public record GeneratorSpec(string EnablingPropertyName, string DllFileName)
{
public static GeneratorSpec RequestDelegate { get; } = new GeneratorSpec("EnableRequestDelegateGenerator", "Microsoft.AspNetCore.Http.RequestDelegateGenerator.dll");
public static GeneratorSpec ConfigurationBinding { get; } = new GeneratorSpec("EnableConfigurationBindingGenerator", "Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll");
}

public IEnumerator<object[]> OffByDefaultGenerators()
{
yield return new object[] { GeneratorSpec.RequestDelegate };
yield return new object[] { GeneratorSpec.ConfigurationBinding };
}

public IEnumerator<object[]> OffByDefaultGeneratorTestData()
{
// Test asset name, generator to test, whether generator is enabled.
yield return new object[] { GeneratorSpec.RequestDelegate, false };
yield return new object[] { GeneratorSpec.RequestDelegate, true };
yield return new object[] { GeneratorSpec.RequestDelegate, null };
yield return new object[] { GeneratorSpec.ConfigurationBinding, false };
yield return new object[] { GeneratorSpec.ConfigurationBinding, true };
yield return new object[] { GeneratorSpec.ConfigurationBinding, null };
foreach (object[] generator in OffByDefaultGenerators())
{
// Test asset name, generator to test, whether generator is enabled.
var spec = (GeneratorSpec)generator[0];
yield return new object[] { spec, false };
yield return new object[] { spec, true };
yield return new object[] { spec, null };
}
}

[Theory]
Expand Down

0 comments on commit e517bb8

Please sign in to comment.