a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package languages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
"github.com/zzet/gortex/internal/parser"
|
|
)
|
|
|
|
func TestDetectDotNetSurfaces_DIRegistrations(t *testing.T) {
|
|
result := &parser.ExtractionResult{
|
|
Nodes: []*graph.Node{{ID: "Startup.cs", Kind: graph.KindFile, FilePath: "Startup.cs"}},
|
|
}
|
|
src := []byte(`public void ConfigureServices(IServiceCollection services) {
|
|
services.AddScoped<IUserRepo, UserRepo>();
|
|
services.AddSingleton<ILogger>();
|
|
builder.Services.AddTransient<IFoo, Foo>();
|
|
}`)
|
|
detectDotNetSurfaces(src, result)
|
|
|
|
regs, _ := result.Nodes[0].Meta["di_registrations"].([]string)
|
|
require.Len(t, regs, 3)
|
|
require.Contains(t, regs, "scoped IUserRepo -> UserRepo")
|
|
require.Contains(t, regs, "singleton ILogger")
|
|
require.Contains(t, regs, "transient IFoo -> Foo")
|
|
}
|
|
|
|
func TestDetectDotNetSurfaces_COMInterop(t *testing.T) {
|
|
result := &parser.ExtractionResult{
|
|
Nodes: []*graph.Node{{ID: "Com.cs", Kind: graph.KindFile, FilePath: "Com.cs"}},
|
|
}
|
|
src := []byte(`[ComImport]
|
|
[Guid("00000000-0000-0000-0000-000000000000")]
|
|
interface IShellLink {}`)
|
|
detectDotNetSurfaces(src, result)
|
|
require.Equal(t, true, result.Nodes[0].Meta["com_interop"])
|
|
}
|
|
|
|
func TestDetectDotNetSurfaces_PlainFile(t *testing.T) {
|
|
result := &parser.ExtractionResult{
|
|
Nodes: []*graph.Node{{ID: "Plain.cs", Kind: graph.KindFile, FilePath: "Plain.cs"}},
|
|
}
|
|
detectDotNetSurfaces([]byte(`public class Plain { void M() {} }`), result)
|
|
require.Nil(t, result.Nodes[0].Meta) // nothing to stamp
|
|
}
|