Skip to content

Commit 1d8bda6

Browse files
dmytroettDmytro Ett
andauthored
Make the .AddAttributedDI explicitly opt in + e2e tests (#21)
* WIP e2e tests * Adding readme * Compiles and tests pass * Verified that transitive dependencies also work as expected. * this works * fixed small issue that I had noticed * reworking * WIP * Fixing some issues * let's see whether this is unecessary * try it out * This works * Start over * Fixed path and other issues * Prepare references for e2e tests * Move to nested directory * updating nuget packages * Refactoring MEDI dep * adding missing assets to solution * Make sure that test projects do not affect how analyzer works * correct nuget path * Some progress with e2e tests * Looks like we had caught a bug * Turn off e2e for now. * Small refactoring * WIP * refactored * Fixing compilation issues and refactoring tests * WIP * WIP * codex refactoring. Reivewing and getting fixed. * WIP * Refactoring tests to my liking * Updating global usings * Fixing tests * I configured IDE to automatically format on save instead of having codex to do that. * Fixing compilation issue * Including refernce in the unit test output * Cover the case when there are no registered services but flag is present * removing outdated opt in things and adding e2e to sln * WIP * E2E tests finally ready * Small refactoring * Clean up xml formatting rules --------- Co-authored-by: Dmytro Ett <dmytro.ett@outlook.com>
1 parent d4d915f commit 1d8bda6

File tree

73 files changed

+1024
-904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1024
-904
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ end_of_line = lf
77
insert_final_newline = false
88
indent_style = space
99

10-
[*.csproj]
10+
[*.{csproj,props}]
1111
indent_size = 2
1212

1313
# C# files

.github/copilot-instructions.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/instructions/source-generators.instructions.md

Lines changed: 0 additions & 147 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,4 @@ MigrationBackup/
363363
FodyWeavers.xsd
364364

365365
# JetBrains
366-
.idea
366+
.idea

AGENTS.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@ This project is about building a library to simplify dependency registration in
1818
- Do not overuse comments; place them only where they add real value.
1919
- Minimize public surface area: Use `private` or `internal` access modifiers by default unless the API is intentionally designed to be public. A smaller public API is easier to maintain and reduces breaking change concerns in future versions.
2020

21-
## Code Style & Formatting
22-
23-
When done with code generation or modification, you must:
24-
25-
1. Run `dotnet format --include <list-of-changed-files>`
26-
2. Ensure no formatting issues remain
27-
28-
Example:
29-
```
30-
dotnet format --include src/AttributedDI/MyClass.cs
31-
```
32-
33-
For multiple files:
34-
```
35-
dotnet format --include src/AttributedDI/File1.cs src/AttributedDI/File2.cs
36-
```
37-
3821
## Public API Documentation
3922

4023
This is a library. **All** public methods, properties, classes, and interfaces in library code **must** have XML documentation (///).

AttributedDI.slnx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,27 @@
1717
<Project Path="src/AttributedDI/AttributedDI.csproj" />
1818
</Folder>
1919
<Folder Name="/test/">
20-
<Project Path="test/AttributedDI.IntegrationTests/AttributedDI.IntegrationTests.csproj" />
21-
<Project Path="test/AttributedDI.GenerateExtensionsOptIn.IntegrationTests/AttributedDI.GenerateExtensionsOptIn.IntegrationTests.csproj" />
22-
<Project Path="test/AttributedDI.GenerateExtensionsOptOut.IntegrationTests/AttributedDI.GenerateExtensionsOptOut.IntegrationTests.csproj" />
23-
<Project Path="test/AttributedDI.SourceGenerator.UnitTests/AttributedDI.SourceGenerator.UnitTests.csproj" />
20+
<Project
21+
Path="test/AttributedDI.SourceGenerator.UnitTests/AttributedDI.SourceGenerator.UnitTests.csproj" />
2422
</Folder>
25-
<Folder Name="/test/assets/">
26-
<Project Path="test/assets/AllModulesRegistration.App/AllModulesRegistration.App.csproj" />
27-
<Project Path="test/assets/AllModulesRegistration.Core/AllModulesRegistration.Core.csproj" />
28-
<Project Path="test/assets/Company.TeamName.Project.API/Company.TeamName.Project.API.csproj" />
29-
<Project Path="test/assets/CustomModuleName/CustomModuleName.csproj" />
30-
<Project Path="test/assets/GeneratedInterfacesSut/GeneratedInterfacesSut.csproj" />
31-
<Project Path="test/assets/GenerateExtensions.OptIn/GenerateExtensions.OptIn.csproj" />
32-
<Project Path="test/assets/GenerateExtensions.OptOut/GenerateExtensions.OptOut.csproj" />
33-
<File Path="test/assets/.editorconfig" />
34-
<File Path="test/assets/Directory.Build.props" />
23+
<Folder Name="/test/integration/">
24+
<Project
25+
Path="test/integration/AttributedDI.IntegrationTests/AttributedDI.IntegrationTests.csproj" />
26+
<File Path="test/integration/nuget.config" />
27+
</Folder>
28+
<Folder Name="/test/integration/assets/">
29+
<Project
30+
Path="test/integration/assets/AllModulesRegistration.App/AllModulesRegistration.App.csproj" />
31+
<Project
32+
Path="test/integration/assets/AllModulesRegistration.Core/AllModulesRegistration.Core.csproj" />
33+
<Project
34+
Path="test/integration/assets/Company.TeamName.Project.API/Company.TeamName.Project.API.csproj" />
35+
<Project Path="test/integration/assets/CustomModuleName/CustomModuleName.csproj" />
36+
<Project Path="test/integration/assets/GeneratedInterfacesSut/GeneratedInterfacesSut.csproj" />
37+
<File Path="test/integration/assets/.editorconfig" />
38+
<File Path="test/integration/assets/Directory.Build.props" />
39+
</Folder>
40+
<Folder Name="/test/e2e/">
41+
<File Path="test/e2e/run-e2e-tests" />
3542
</Folder>
3643
</Solution>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.Text;
3+
using System;
4+
using System.Text;
5+
6+
namespace AttributedDI.SourceGenerator;
7+
8+
internal static class GeneratedAttributesInitializer
9+
{
10+
private const string GeneratedModuleAttributeSource = """
11+
// <auto-generated/>
12+
#nullable enable
13+
14+
namespace AttributedDI.Generated.Internal
15+
{
16+
/// <summary>
17+
/// Marks a generated service module to enable discovery by AttributedDI's source generator.
18+
/// </summary>
19+
[global::Microsoft.CodeAnalysis.Embedded]
20+
[global::System.AttributeUsage(global::System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
21+
internal sealed class GeneratedModuleAttribute : global::System.Attribute
22+
{
23+
}
24+
}
25+
""";
26+
27+
public static void EmbedGeneratedAttributes(IncrementalGeneratorInitializationContext context)
28+
{
29+
context.RegisterPostInitializationOutput(static postInitializationContext =>
30+
{
31+
postInitializationContext.AddEmbeddedAttributeDefinition();
32+
postInitializationContext.AddSource(
33+
"AttributedDI.Generated.Internal.GeneratedModuleAttribute.g.cs",
34+
SourceText.From(GeneratedModuleAttributeSource, Encoding.UTF8));
35+
});
36+
}
37+
}

0 commit comments

Comments
 (0)