-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ProvideAttribute): use source generation
BREAKING CHANGE: ProvideAttribute now uses source generation and requires a partial class.
- Loading branch information
Showing
19 changed files
with
638 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
186 changes: 186 additions & 0 deletions
186
...nents.Roslyn/UIComponents.Roslyn.Generation.Tests/ProvideAugmentGeneratorSnapshotTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
using UIComponents.Roslyn.Generation.Generators.DependencyInjection; | ||
using UIComponents.Roslyn.Generation.Tests.Utilities; | ||
|
||
namespace UIComponents.Roslyn.Generation.Tests | ||
{ | ||
[UsesVerify] | ||
public class ProvideAugmentGeneratorSnapshotTests | ||
{ | ||
[Fact] | ||
public Task It_Generates_Provide_Calls() | ||
{ | ||
var source = @" | ||
using UIComponents; | ||
public interface IDependency {} | ||
public class Dependency : IDependency {} | ||
public partial class BasicProvideComponent : UIComponent | ||
{ | ||
[Provide] | ||
public IDependency Dependency; | ||
[Provide(CastFrom = typeof(IDependency))] | ||
public Dependency ConcreteDependency; | ||
} | ||
"; | ||
return GeneratorTester.Verify<ProvideAugmentGenerator>(source); | ||
} | ||
|
||
[Fact] | ||
public Task It_Can_Be_Used_On_Non_UIComponent_Class() | ||
{ | ||
var source = @" | ||
using UIComponents; | ||
public interface IDependency {} | ||
public class Dependency : IDependency {} | ||
public partial class MyClass | ||
{ | ||
[Provide] | ||
public IDependency Dependency; | ||
[Provide(CastFrom = typeof(IDependency))] | ||
public Dependency ConcreteDependency; | ||
} | ||
"; | ||
return GeneratorTester.Verify<ProvideAugmentGenerator>(source); | ||
} | ||
|
||
[Fact] | ||
public Task It_Handles_Subclasses() | ||
{ | ||
var source = @" | ||
using UIComponents; | ||
public interface IDependency {} | ||
public interface IAnotherDependency {} | ||
public class Dependency : IDependency {} | ||
public class AnotherDependency : IAnotherDependency {} | ||
public partial class BaseProvideComponent : UIComponent | ||
{ | ||
[Provide] | ||
public IDependency Dependency; | ||
[Provide(CastFrom = typeof(IDependency))] | ||
public Dependency ConcreteDependency; | ||
} | ||
public partial class SubclassProvideComponent : BaseProvideComponent | ||
{ | ||
[Provide] | ||
public IAnotherDependency AnotherDependency; | ||
} | ||
public partial class SecondSubclassProvideComponent : SubclassProvideComponent | ||
{ | ||
[Provide(CastFrom = typeof(IAnotherDependency))] | ||
public AnotherDependency ThirdDependency; | ||
}"; | ||
return GeneratorTester.Verify<ProvideAugmentGenerator>(source); | ||
} | ||
|
||
[Fact] | ||
public Task It_Handles_Namespaces_And_Nested_Types() | ||
{ | ||
var source = @" | ||
using UIComponents; | ||
namespace Dependencies | ||
{ | ||
public interface IDependency {} | ||
public class Dependency : IDependency {} | ||
} | ||
namespace Components | ||
{ | ||
public partial class ParentClass | ||
{ | ||
public interface IOtherDependency {} | ||
private partial class NestedProvideComponent : UIComponent | ||
{ | ||
[Provide] | ||
public Dependencies.IDependency Dependency; | ||
[Provide(CastFrom = typeof(IDependency))] | ||
public Dependencies.Dependency ConcreteDependency; | ||
[Provide] | ||
public IOtherDependency OtherDependency; | ||
} | ||
} | ||
}"; | ||
return GeneratorTester.Verify<ProvideAugmentGenerator>(source); | ||
} | ||
|
||
[Fact] | ||
public Task It_Does_Not_Generate_For_Non_Interface_Or_Class_Fields() | ||
{ | ||
var source = @" | ||
using UIComponents; | ||
public interface IDependency {} | ||
public partial class InvalidProvideComponent : UIComponent | ||
{ | ||
[Provide] | ||
public IDependency Dependency; | ||
[Provide] | ||
public int InvalidIntDependency; | ||
[Provide] | ||
public float InvalidFloatDependency; | ||
} | ||
"; | ||
return GeneratorTester.Verify<ProvideAugmentGenerator>(source); | ||
} | ||
|
||
[Fact] | ||
public Task It_Does_Not_Generate_If_There_Are_No_Provide_Fields() | ||
{ | ||
var source = @" | ||
using UIComponents; | ||
public interface IDependency {} | ||
public partial class NoProvideComponent : UIComponent | ||
{ | ||
public IDependency Dependency; | ||
} | ||
"; | ||
return GeneratorTester.Verify<ProvideAugmentGenerator>(source); | ||
} | ||
|
||
[Fact] | ||
public Task It_Does_Not_Generate_If_ProvideAttribute_Type_Is_Missing() | ||
{ | ||
var source = @" | ||
namespace UIComponents | ||
{ | ||
public class UIComponent {} | ||
public class AssetPathAttribute {} | ||
} | ||
public interface IDependency {} | ||
public partial class MissingProvideComponent : UIComponents.UIComponent | ||
{ | ||
[UIComponents.Provide] | ||
public IDependency Dependency; | ||
} | ||
"; | ||
return GeneratorTester.VerifyWithoutReferences<ProvideAugmentGenerator>(source); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
UIComponents.Roslyn/UIComponents.Roslyn.Generation.Tests/Resources/ProvideAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace UIComponents | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)] | ||
public class ProvideAttribute : Attribute | ||
{ | ||
public Type CastFrom { get; set; } | ||
} | ||
} |
Oops, something went wrong.