diff --git a/src/.editorconfig b/.editorconfig
similarity index 97%
rename from src/.editorconfig
rename to .editorconfig
index 863bb0b3e..f90fd8498 100644
--- a/src/.editorconfig
+++ b/.editorconfig
@@ -29,7 +29,7 @@ trim_trailing_whitespace = true
indent_style = tab
# Visual Studio XML Project Files
-[*.{csproj,vcxproj.filters,proj,projitems,shproj}]
+[*.{csproj,vcxproj.filters,proj,projitems,shproj,slnx}]
indent_size = 2
# XML Configuration Files
@@ -75,6 +75,8 @@ indent_style = tab
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions
##########################################
+[*.{cs,csx,cake}]
+
# Default Severity for .NET Code Style
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/configuration-options#scope
dotnet_analyzer_diagnostic.severity = error
@@ -86,7 +88,6 @@ dotnet_separate_import_directive_groups = false
# .NET Code Style Settings
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#net-code-style-settings
-[*.{cs,csx,cake}]
# "this." and "Me." qualifiers
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#this-and-me
@@ -157,6 +158,8 @@ csharp_style_var_elsewhere = true
# Namespace declaration preferences
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0160-ide0161?view=vs-2022
csharp_style_namespace_declarations = file_scoped # IDE0160 and IDE0161
+# Keep explicit Program classes; top-level statements conflict with insert_final_newline = false.
+csharp_style_prefer_top_level_statements = false # IDE0210 and IDE0211
# Expression-bodied members
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-bodied-members
@@ -509,7 +512,7 @@ dotnet_diagnostic.IDE0005.severity = warning # https://github.com/atc-net
dotnet_diagnostic.IDE0010.severity = suggestion # Populate switch
dotnet_diagnostic.IDE0028.severity = suggestion # Collection initialization can be simplified
dotnet_diagnostic.IDE0021.severity = suggestion # Use expression body for constructor
-dotnet_diagnostic.IDE0055.severity = none # Fix formatting
+dotnet_diagnostic.IDE0055.severity = warning # Fix formatting
dotnet_diagnostic.IDE0058.severity = none # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/IDE0058.md
dotnet_diagnostic.IDE0061.severity = suggestion # Use expression body for local function
dotnet_diagnostic.IDE0130.severity = suggestion # Namespace does not match folder structure
@@ -571,3 +574,20 @@ dotnet_diagnostic.SA1518.severity = none # Newline at the end of the file
[PatchedSqlServerDatabaseModelFactory.cs]
generated_code = true
+
+# Generated by the matching T4 templates in microsoft/DACExtensions.
+# https://github.com/microsoft/DACExtensions/tree/master/DacFxStronglyTypedModel
+[src/Core/DacFxStrongTypedCore.161/{Interfaces,VersionSpecificImplementations}.cs]
+generated_code = true
+
+
+# Preserve checked-in scaffolding output, including models generated from T4 templates.
+[test/ScaffoldingTester/**/Models/**.cs]
+generated_code = true
+
+# Custom partial classes are maintained by hand and should follow the shared rules.
+[test/ScaffoldingTester/**/Models/*.{custom,Custom}.cs]
+generated_code = false
+
+[test/ScaffoldingTester/ScaffoldingTester5/Models/StringSplitResult.cs]
+generated_code = false
\ No newline at end of file
diff --git a/.github/workflows/vsix.yml b/.github/workflows/vsix.yml
index 634222a4e..2b503ac99 100644
--- a/.github/workflows/vsix.yml
+++ b/.github/workflows/vsix.yml
@@ -6,8 +6,9 @@ on:
paths-ignore:
- '**/*'
- '!.github/workflows/vsix.yml'
- - '!src/GUI/**/*'
- - '!src/Core/**/*'
+ - '!.editorconfig'
+ - '!src/**/*'
+ - '!test/ScaffoldingTester/**/*'
branches:
- 'master'
pull_request:
@@ -36,6 +37,31 @@ jobs:
with:
dotnet-version: '10.0.x'
+ - name: Setup MSBuild.exe
+ uses: microsoft/setup-msbuild@v3
+
+ # Verify checked-in source before Update Version modifies it.
+ - name: Verify formatting
+ shell: pwsh
+ env:
+ DOTNET_CLI_UI_LANGUAGE: en-US
+ run: |
+ $solutions = @('src/EFCorePowerTools.slnx', 'test/ScaffoldingTester/ScaffoldingTester.slnx')
+ foreach ($solution in $solutions) {
+ Write-Host "Restoring: $solution"
+ msbuild $solution /t:Restore /p:Configuration=Debug /v:minimal /nologo
+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
+
+ Write-Host "Verifying formatting: $solution"
+ $formatOutput = dotnet format $solution --verify-no-changes --no-restore --verbosity diagnostic 2>&1
+ $formatExitCode = $LASTEXITCODE
+ $formatOutput | Write-Output
+ if ($formatExitCode -ne 0) { exit $formatExitCode }
+ if ($formatOutput -match 'Required references did not load for ') {
+ throw "Formatting verification is incomplete for $solution because project references could not be loaded."
+ }
+ }
+
- name: Update Version
run: |
((Get-Content -Path GUI/EFCorePowerTools/Properties/AssemblyInfo.cs -Raw) -Replace "2.6.0.1", "${{ env.VERSION }}") | Set-Content -Path GUI/EFCorePowerTools/Properties/AssemblyInfo.cs
@@ -44,10 +70,6 @@ jobs:
working-directory: src
shell: pwsh
- - name: Restore
- run: dotnet restore EFCorePowerTools.slnx
- working-directory: src
-
- name: Build reveng tools
shell: cmd
run: |
@@ -80,9 +102,6 @@ jobs:
dir /a:-d /s /b "efreveng100" | find /c ":\" > filecount.txt
findstr "149" filecount.txt
- - name: Setup MSBuild.exe
- uses: microsoft/setup-msbuild@v3
-
- name: Build
run: msbuild EFCorePowerTools.slnx /property:Configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
working-directory: src
diff --git a/README.md b/README.md
index ae2b12373..1d33de0e8 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,22 @@ You can smoke test changes to reverse engineering. Launch one of the `efreveng`
In the `ScaffoldingTester` solution there are scripts to populate Northwind and Chinook databases with the required objects.
+### Code formatting
+
+CI build runs a **Verify formatting** step in the **VSIX** workflow to check both solutions against [`.editorconfig`](.editorconfig). If it fails and reports formatting violations, apply fixes from the repository root:
+
+```sh
+dotnet format src/EFCorePowerTools.slnx
+dotnet format test/ScaffoldingTester/ScaffoldingTester.slnx
+```
+
+Some violations may need manual fixes. Rerun the commands with `--verify-no-changes` to see those locally:
+
+```sh
+dotnet format src/EFCorePowerTools.slnx --verify-no-changes
+dotnet format test/ScaffoldingTester/ScaffoldingTester.slnx --verify-no-changes
+```
+
## Support and sponsors
The tool and GitHub based support are free. A [rating or review](https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools&ssr=false#review-details) and [sponsorships](https://github.com/sponsors/ErikEJ) are greatly appreciated.
diff --git a/src/Core/DacFxStrongTypedCore.161/ISqlModelElement.cs b/src/Core/DacFxStrongTypedCore.161/ISqlModelElement.cs
index 2bc5855a9..e8fa8490c 100644
--- a/src/Core/DacFxStrongTypedCore.161/ISqlModelElement.cs
+++ b/src/Core/DacFxStrongTypedCore.161/ISqlModelElement.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
//
// The MIT License (MIT)
@@ -24,47 +24,49 @@
// SOFTWARE.
//
//------------------------------------------------------------------------------
-namespace Microsoft.SqlServer.Dac.Extensions.Prototype
+using System.Collections.Generic;
+using Microsoft.SqlServer.Dac.Model;
+using Microsoft.SqlServer.TransactSql.ScriptDom;
+
+namespace Microsoft.SqlServer.Dac.Extensions.Prototype;
+
+#pragma warning disable CA1716 // Preserve upstream public parameter names for callers using named arguments.
+public interface ISqlModelElement
{
- using System.Collections.Generic;
- using Microsoft.SqlServer.Dac.Model;
- using Microsoft.SqlServer.TransactSql.ScriptDom;
- public interface ISqlModelElement
- {
- ObjectIdentifier Name { get; }
- TSqlObject Element { get; }
- TSqlScript GetAst();
- IEnumerable GetChildren();
- IEnumerable GetChildren(DacQueryScopes queryScopes);
- object GetMetadata(ModelMetadataClass metadata);
- T GetMetadata(ModelMetadataClass metadata);
- TSqlObject GetParent();
- TSqlObject GetParent(DacQueryScopes queryScopes);
- object GetProperty(ModelPropertyClass property);
- T GetProperty(ModelPropertyClass property);
- IEnumerable GetReferenced();
- IEnumerable GetReferenced(DacQueryScopes queryScopes);
- IEnumerable GetReferenced(ModelRelationshipClass relationshipType);
- IEnumerable GetReferenced(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
- IEnumerable GetReferencedRelationshipInstances();
- IEnumerable GetReferencedRelationshipInstances(DacExternalQueryScopes queryScopes);
- IEnumerable GetReferencedRelationshipInstances(DacQueryScopes queryScopes);
- IEnumerable GetReferencedRelationshipInstances(ModelRelationshipClass relationshipType);
- IEnumerable GetReferencedRelationshipInstances(ModelRelationshipClass relationshipType, DacExternalQueryScopes queryScopes);
- IEnumerable GetReferencedRelationshipInstances(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
- IEnumerable GetReferencing();
- IEnumerable GetReferencing(DacQueryScopes queryScopes);
- IEnumerable GetReferencing(ModelRelationshipClass relationshipType);
- IEnumerable GetReferencing(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
- IEnumerable GetReferencingRelationshipInstances();
- IEnumerable GetReferencingRelationshipInstances(DacQueryScopes queryScopes);
- IEnumerable GetReferencingRelationshipInstances(ModelRelationshipClass relationshipType);
- IEnumerable GetReferencingRelationshipInstances(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
- string GetScript();
- SourceInformation GetSourceInformation();
- ModelTypeClass ObjectType { get; }
- object this[ModelPropertyClass property] { get; }
- bool TryGetAst(out TSqlScript objectAst);
- bool TryGetScript(out string objectScript);
- }
+ public ObjectIdentifier Name { get; }
+ public TSqlObject Element { get; }
+ public TSqlScript GetAst();
+ public IEnumerable GetChildren();
+ public IEnumerable GetChildren(DacQueryScopes queryScopes);
+ public object GetMetadata(ModelMetadataClass metadata);
+ public T GetMetadata(ModelMetadataClass metadata);
+ public TSqlObject GetParent();
+ public TSqlObject GetParent(DacQueryScopes queryScopes);
+ public object GetProperty(ModelPropertyClass property);
+ public T GetProperty(ModelPropertyClass property);
+ public IEnumerable GetReferenced();
+ public IEnumerable GetReferenced(DacQueryScopes queryScopes);
+ public IEnumerable GetReferenced(ModelRelationshipClass relationshipType);
+ public IEnumerable GetReferenced(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
+ public IEnumerable GetReferencedRelationshipInstances();
+ public IEnumerable GetReferencedRelationshipInstances(DacExternalQueryScopes queryScopes);
+ public IEnumerable GetReferencedRelationshipInstances(DacQueryScopes queryScopes);
+ public IEnumerable GetReferencedRelationshipInstances(ModelRelationshipClass relationshipType);
+ public IEnumerable GetReferencedRelationshipInstances(ModelRelationshipClass relationshipType, DacExternalQueryScopes queryScopes);
+ public IEnumerable GetReferencedRelationshipInstances(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
+ public IEnumerable GetReferencing();
+ public IEnumerable GetReferencing(DacQueryScopes queryScopes);
+ public IEnumerable GetReferencing(ModelRelationshipClass relationshipType);
+ public IEnumerable GetReferencing(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
+ public IEnumerable GetReferencingRelationshipInstances();
+ public IEnumerable GetReferencingRelationshipInstances(DacQueryScopes queryScopes);
+ public IEnumerable GetReferencingRelationshipInstances(ModelRelationshipClass relationshipType);
+ public IEnumerable GetReferencingRelationshipInstances(ModelRelationshipClass relationshipType, DacQueryScopes queryScopes);
+ public string GetScript();
+ public SourceInformation GetSourceInformation();
+ public ModelTypeClass ObjectType { get; }
+ public object this[ModelPropertyClass property] { get; }
+ public bool TryGetAst(out TSqlScript objectAst);
+ public bool TryGetScript(out string objectScript);
}
+#pragma warning restore CA1716
\ No newline at end of file
diff --git a/src/Core/DacFxStrongTypedCore.161/ISqlModelElementReference.cs b/src/Core/DacFxStrongTypedCore.161/ISqlModelElementReference.cs
index d7d263c7b..7bb39f736 100644
--- a/src/Core/DacFxStrongTypedCore.161/ISqlModelElementReference.cs
+++ b/src/Core/DacFxStrongTypedCore.161/ISqlModelElementReference.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
//
// The MIT License (MIT)
@@ -25,11 +25,12 @@
//
//------------------------------------------------------------------------------
using Microsoft.SqlServer.Dac.Model;
-namespace Microsoft.SqlServer.Dac.Extensions.Prototype
-{
- public interface ISqlModelElementReference : ISqlModelElement
- {
- T GetMetadataProperty(ModelPropertyClass property);
- }
+namespace Microsoft.SqlServer.Dac.Extensions.Prototype;
+
+#pragma warning disable CA1716 // Preserve upstream public parameter names for callers using named arguments.
+public interface ISqlModelElementReference : ISqlModelElement
+{
+ public T GetMetadataProperty(ModelPropertyClass property);
}
+#pragma warning restore CA1716
\ No newline at end of file
diff --git a/src/Core/DacFxStrongTypedCore.161/Interfaces.cs b/src/Core/DacFxStrongTypedCore.161/Interfaces.cs
index 3e2afa35f..ee41a8837 100644
--- a/src/Core/DacFxStrongTypedCore.161/Interfaces.cs
+++ b/src/Core/DacFxStrongTypedCore.161/Interfaces.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
//
// The MIT License (MIT)
@@ -22116,4 +22116,4 @@ String Expression
get;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/DacFxStrongTypedCore.161/ModelExtensions.cs b/src/Core/DacFxStrongTypedCore.161/ModelExtensions.cs
index 3e8551c7e..82464452c 100644
--- a/src/Core/DacFxStrongTypedCore.161/ModelExtensions.cs
+++ b/src/Core/DacFxStrongTypedCore.161/ModelExtensions.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
//
// The MIT License (MIT)
@@ -30,228 +30,227 @@
using Microsoft.SqlServer.Dac.Model;
using Index = Microsoft.SqlServer.Dac.Model.Index;
-namespace Microsoft.SqlServer.Dac.Extensions.Prototype
+namespace Microsoft.SqlServer.Dac.Extensions.Prototype;
+
+public partial class TSqlTable
{
- public partial class TSqlTable
+ public IEnumerable Indexes
{
- public IEnumerable Indexes
+ get
{
- get
+ foreach (var element in Element.GetReferencing(Index.IndexedObject))
{
- foreach (var element in Element.GetReferencing(Index.IndexedObject))
- {
- yield return (ISqlIndex)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (ISqlIndex)AdaptInstance(element);
}
}
+ }
- public IEnumerable ForeignKeyConstraints
+ public IEnumerable ForeignKeyConstraints
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(ForeignKeyConstraint.Host))
{
- foreach (var element in Element.GetReferencing(ForeignKeyConstraint.Host))
- {
- yield return (TSqlForeignKeyConstraint)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlForeignKeyConstraint)AdaptInstance(element);
}
}
+ }
- public IEnumerable PrimaryKeyConstraints
+ public IEnumerable PrimaryKeyConstraints
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(PrimaryKeyConstraint.Host))
{
- foreach (var element in Element.GetReferencing(PrimaryKeyConstraint.Host))
- {
- yield return (TSqlPrimaryKeyConstraint)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlPrimaryKeyConstraint)AdaptInstance(element);
}
}
+ }
- public IEnumerable DefaultConstraints
+ public IEnumerable DefaultConstraints
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(DefaultConstraint.Host))
{
- foreach (var element in Element.GetReferencing(DefaultConstraint.Host))
- {
- yield return (TSqlDefaultConstraint)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlDefaultConstraint)AdaptInstance(element);
}
}
+ }
- public IEnumerable CheckConstraints
+ public IEnumerable CheckConstraints
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(CheckConstraint.Host))
{
- foreach (var element in Element.GetReferencing(CheckConstraint.Host))
- {
- yield return (TSqlCheckConstraint)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlCheckConstraint)AdaptInstance(element);
}
}
+ }
- public IEnumerable UniqueConstraints
+ public IEnumerable UniqueConstraints
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(UniqueConstraint.Host))
{
- foreach (var element in Element.GetReferencing(UniqueConstraint.Host))
- {
- yield return (TSqlUniqueConstraint)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlUniqueConstraint)AdaptInstance(element);
}
}
+ }
- ///
- /// Returns all constraints for the table
- ///
- public IEnumerable AllConstraints
+ ///
+ /// Returns all constraints for the table
+ ///
+ public IEnumerable AllConstraints
+ {
+ get
{
- get
+ foreach (var constraint in ForeignKeyConstraints)
+ {
+ yield return constraint;
+ }
+ foreach (var constraint in PrimaryKeyConstraints)
+ {
+ yield return constraint;
+ }
+ foreach (var constraint in UniqueConstraints)
+ {
+ yield return constraint;
+ }
+ foreach (var constraint in CheckConstraints)
{
- foreach (var constraint in ForeignKeyConstraints)
- {
- yield return constraint;
- }
- foreach (var constraint in PrimaryKeyConstraints)
- {
- yield return constraint;
- }
- foreach (var constraint in UniqueConstraints)
- {
- yield return constraint;
- }
- foreach (var constraint in CheckConstraints)
- {
- yield return constraint;
- }
- foreach (var constraint in DefaultConstraints)
- {
- yield return constraint;
- }
+ yield return constraint;
+ }
+ foreach (var constraint in DefaultConstraints)
+ {
+ yield return constraint;
}
}
- public IEnumerable Triggers
+ }
+ public IEnumerable Triggers
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(DmlTrigger.TriggerObject))
{
- foreach (var element in Element.GetReferencing(DmlTrigger.TriggerObject))
- {
- yield return (TSqlDmlTrigger)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlDmlTrigger)AdaptInstance(element);
}
}
-
}
- public partial class TSqlFileTable
+
+}
+public partial class TSqlFileTable
+{
+ public IEnumerable Indexes
{
- public IEnumerable Indexes
+ get
{
- get
+ foreach (var element in Element.GetReferencing(Index.IndexedObject))
{
- foreach (var element in Element.GetReferencing(Index.IndexedObject))
- {
- yield return (ISqlIndex)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (ISqlIndex)AdaptInstance(element);
}
}
+ }
- public IEnumerable Triggers
+ public IEnumerable Triggers
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(DmlTrigger.TriggerObject))
{
- foreach (var element in Element.GetReferencing(DmlTrigger.TriggerObject))
- {
- yield return (TSqlDmlTrigger)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlDmlTrigger)AdaptInstance(element);
}
-
}
+
}
+}
- public partial class TSqlTableValuedFunction
+public partial class TSqlTableValuedFunction
+{
+ public IEnumerable Indexes
{
- public IEnumerable Indexes
+ get
{
- get
+ foreach (var element in Element.GetReferencing(Index.IndexedObject))
{
- foreach (var element in Element.GetReferencing(Index.IndexedObject))
- {
- yield return (ISqlIndex)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (ISqlIndex)AdaptInstance(element);
}
}
}
+}
- public partial class TSqlView
+public partial class TSqlView
+{
+ public IEnumerable Indexes
{
- public IEnumerable Indexes
+ get
{
- get
+ foreach (var element in Element.GetReferencing(Index.IndexedObject))
{
- foreach (var element in Element.GetReferencing(Index.IndexedObject))
- {
- yield return (ISqlIndex)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (ISqlIndex)AdaptInstance(element);
}
}
+ }
- public IEnumerable Triggers
+ public IEnumerable Triggers
+ {
+ get
{
- get
+ foreach (var element in Element.GetReferencing(DmlTrigger.TriggerObject))
{
- foreach (var element in Element.GetReferencing(DmlTrigger.TriggerObject))
- {
- yield return (TSqlDmlTrigger)TSqlModelElement.AdaptInstance(element);
- }
+ yield return (TSqlDmlTrigger)AdaptInstance(element);
}
-
}
+
}
+}
- public partial class TSqlTableType
+public partial class TSqlTableType
+{
+ public IEnumerable PrimaryKeyConstraints
{
- public IEnumerable PrimaryKeyConstraints
+ get
{
- get
- {
- foreach (var element in Constraints.OfType())
- {
- yield return element;
- }
+ foreach (var element in Constraints.OfType())
+ {
+ yield return element;
}
}
+ }
- public IEnumerable DefaultConstraints
+ public IEnumerable DefaultConstraints
+ {
+ get
{
- get
+ foreach (var element in Constraints.OfType())
{
- foreach (var element in Constraints.OfType())
- {
- yield return element;
- }
+ yield return element;
}
}
+ }
- public IEnumerable CheckConstraints
+ public IEnumerable CheckConstraints
+ {
+ get
{
- get
+ foreach (var element in Constraints.OfType())
{
- foreach (var element in Constraints.OfType())
- {
- yield return element;
- }
+ yield return element;
}
}
+ }
- public IEnumerable UniqueConstraints
+ public IEnumerable UniqueConstraints
+ {
+ get
{
- get
+ foreach (var element in Constraints.OfType())
{
- foreach (var element in this.Constraints.OfType())
- {
- yield return element;
- }
+ yield return element;
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/DacFxStrongTypedCore.161/TSqlTypedModel.cs b/src/Core/DacFxStrongTypedCore.161/TSqlTypedModel.cs
index 6c52ee94b..450845bff 100644
--- a/src/Core/DacFxStrongTypedCore.161/TSqlTypedModel.cs
+++ b/src/Core/DacFxStrongTypedCore.161/TSqlTypedModel.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
//
// The MIT License (MIT)
@@ -30,297 +30,266 @@
using Microsoft.SqlServer.Dac.Model;
using Microsoft.SqlServer.TransactSql.ScriptDom;
-namespace Microsoft.SqlServer.Dac.Extensions.Prototype
+namespace Microsoft.SqlServer.Dac.Extensions.Prototype;
+
+public sealed class TSqlTypedModel : IDisposable
{
- public sealed class TSqlTypedModel : IDisposable
- {
- TSqlModel model;
+ private TSqlModel model;
- public TSqlTypedModel(TSqlModel model)
- {
- this.model = model;
- }
+ public TSqlTypedModel(TSqlModel model)
+ {
+ this.model = model;
+ }
- public TSqlTypedModel(string filename)
- {
- model = new TSqlModel(filename);
- }
+ public TSqlTypedModel(string filename)
+ {
+ model = new TSqlModel(filename);
+ }
- public TSqlTypedModel(SqlServerVersion modelTargetVersion, TSqlModelOptions modelCreationOptions)
- {
- model = new TSqlModel(modelTargetVersion, modelCreationOptions);
- }
+ public TSqlTypedModel(SqlServerVersion modelTargetVersion, TSqlModelOptions modelCreationOptions)
+ {
+ model = new TSqlModel(modelTargetVersion, modelCreationOptions);
+ }
- public TSqlTypedModel(string filename, DacSchemaModelStorageType modelStorageType)
- {
- model = new TSqlModel(filename, modelStorageType);
- }
+ public TSqlTypedModel(string filename, DacSchemaModelStorageType modelStorageType)
+ {
+ model = new TSqlModel(filename, modelStorageType);
+ }
- public IEnumerable GetObjects(DacQueryScopes queryScope) where T : ISqlModelElement
+ public IEnumerable GetObjects(DacQueryScopes queryScope) where T : ISqlModelElement
+ {
+ // Map the System.Type to a set of ModelType classes that extend the type or implement the interface
+ foreach (var modelType in UtilityMethods.GetModelElementTypes(typeof(T)))
{
- // Map the System.Type to a set of ModelType classes that extend the type or implement the interface
- foreach (ModelTypeClass modelType in UtilityMethods.GetModelElementTypes(typeof(T)))
+ foreach (var element in model.GetObjects(queryScope, modelType))
{
- foreach (var element in model.GetObjects(queryScope, modelType))
- {
- // Adapt instance with strongly-typed wrapper.
- yield return (T)TSqlModelElement.AdaptInstance(element);
- }
+ // Adapt instance with strongly-typed wrapper.
+ yield return (T)TSqlModelElement.AdaptInstance(element);
}
}
+ }
- public IEnumerable GetObjects(ObjectIdentifier id, DacQueryScopes queryScope) where T : ISqlModelElement
+ public IEnumerable GetObjects(ObjectIdentifier id, DacQueryScopes queryScope) where T : ISqlModelElement
+ {
+ // Map the System.Type to a set of ModelType classes that extend the type or implement the interface
+ foreach (var modelType in UtilityMethods.GetModelElementTypes(typeof(T)))
{
- // Map the System.Type to a set of ModelType classes that extend the type or implement the interface
- foreach (ModelTypeClass modelType in UtilityMethods.GetModelElementTypes(typeof(T)))
+ foreach (var element in model.GetObjects(modelType, id, queryScope))
{
- foreach (var element in model.GetObjects(modelType, id, queryScope))
- {
- // Adapt instance with strongly-typed wrapper.
- yield return (T)TSqlModelElement.AdaptInstance(element);
- }
+ // Adapt instance with strongly-typed wrapper.
+ yield return (T)TSqlModelElement.AdaptInstance(element);
}
}
+ }
- public T GetObject(ObjectIdentifier id, DacQueryScopes queryScope) where T : ISqlModelElement
- {
- return GetObjects(id, queryScope).FirstOrDefault();
- }
+ public T GetObject(ObjectIdentifier id, DacQueryScopes queryScope) where T : ISqlModelElement => GetObjects(id, queryScope).FirstOrDefault();
- // Summary:
- // Adds objects to the model based on the contents of a TSql Script string.
- // The script should consist of valid TSql DDL statements. Objects added using
- // this method cannot be updated or deleted at a later point as update/delete
- // requires a script name to be specified when adding the objects. If this is
- // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(System.String,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
- // method instead.
- //
- // Parameters:
- // inputScript:
- // Script containing TSql DDL statements
- //
- // Exceptions:
- // System.ArgumentNullException:
- // If the supplied inputScript is null.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void AddObjects(string inputScript)
- {
- model.AddObjects(inputScript);
- }
- //
- // Summary:
- // Adds objects to the model based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
- // object. The script should be valid TSql with no parse errors. Objects added
- // using this method cannot be updated or deleted at a later point as update/delete
- // requires a script name to be specified when adding the objects. If this is
- // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
- // method instead.
- //
- // Parameters:
- // inputScript:
- // The Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript to add
- //
- // Exceptions:
- // System.ArgumentNullException:
- // If the supplied inputScript is null.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void AddObjects(TSqlScript inputScript)
- {
- model.AddObjects(inputScript);
- }
- //
- // Summary:
- // Add Objects to the model based on the contents of a TSql Script string, plus
- // additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
- // object The script should consist of valid TSql DDL statements. Objects added
- // using this method cannot be updated or deleted at a later point as update/delete
- // requires a script name to be specified when adding the objects. If this is
- // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(System.String,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
- // method instead.
- //
- // Parameters:
- // inputScript:
- // Script containing TSql DDL statements
- //
- // options:
- // Options defining how to interpret the script
- //
- // Exceptions:
- // System.ArgumentNullException:
- // If the supplied inputScript is null.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void AddObjects(string inputScript, TSqlObjectOptions options)
- {
- model.AddObjects(inputScript, options);
- }
+ // Summary:
+ // Adds objects to the model based on the contents of a TSql Script string.
+ // The script should consist of valid TSql DDL statements. Objects added using
+ // this method cannot be updated or deleted at a later point as update/delete
+ // requires a script name to be specified when adding the objects. If this is
+ // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(System.String,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
+ // method instead.
+ //
+ // Parameters:
+ // inputScript:
+ // Script containing TSql DDL statements
+ //
+ // Exceptions:
+ // System.ArgumentNullException:
+ // If the supplied inputScript is null.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void AddObjects(string inputScript) => model.AddObjects(inputScript);
+ //
+ // Summary:
+ // Adds objects to the model based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
+ // object. The script should be valid TSql with no parse errors. Objects added
+ // using this method cannot be updated or deleted at a later point as update/delete
+ // requires a script name to be specified when adding the objects. If this is
+ // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
+ // method instead.
+ //
+ // Parameters:
+ // inputScript:
+ // The Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript to add
+ //
+ // Exceptions:
+ // System.ArgumentNullException:
+ // If the supplied inputScript is null.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void AddObjects(TSqlScript inputScript) => model.AddObjects(inputScript);
+ //
+ // Summary:
+ // Add Objects to the model based on the contents of a TSql Script string, plus
+ // additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
+ // object The script should consist of valid TSql DDL statements. Objects added
+ // using this method cannot be updated or deleted at a later point as update/delete
+ // requires a script name to be specified when adding the objects. If this is
+ // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(System.String,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
+ // method instead.
+ //
+ // Parameters:
+ // inputScript:
+ // Script containing TSql DDL statements
+ //
+ // options:
+ // Options defining how to interpret the script
+ //
+ // Exceptions:
+ // System.ArgumentNullException:
+ // If the supplied inputScript is null.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void AddObjects(string inputScript, TSqlObjectOptions options) => model.AddObjects(inputScript, options);
- //
- // Summary:
- // Add Objects to the model based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
- // object, plus additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
- // object The script should be valid TSql with no parse errors. Objects added
- // using this method cannot be updated or deleted at a later point as update/delete
- // requires a script name to be specified when adding the objects. If this is
- // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
- // method instead.
- //
- // Parameters:
- // inputScript:
- // The Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript to add
- //
- // options:
- // Options defining how to interpret the script
- //
- // Exceptions:
- // System.ArgumentNullException:
- // If the supplied inputScript is null.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void AddObjects(TSqlScript inputScript, TSqlObjectOptions options)
- {
- model.AddObjects(inputScript, options);
- }
+ //
+ // Summary:
+ // Add Objects to the model based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
+ // object, plus additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
+ // object The script should be valid TSql with no parse errors. Objects added
+ // using this method cannot be updated or deleted at a later point as update/delete
+ // requires a script name to be specified when adding the objects. If this is
+ // a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
+ // method instead.
+ //
+ // Parameters:
+ // inputScript:
+ // The Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript to add
+ //
+ // options:
+ // Options defining how to interpret the script
+ //
+ // Exceptions:
+ // System.ArgumentNullException:
+ // If the supplied inputScript is null.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void AddObjects(TSqlScript inputScript, TSqlObjectOptions options) => model.AddObjects(inputScript, options);
- //
- // Summary:
- // Adds or updates the objects defined for a specified sourceName with the objects
- // defined in the inputScript. If any objects were previously added with the
- // same sourceName these will be completely replaced The object definitions
- // are based on the contents of a TSql Script string plus additional metadata
- // defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions object The script
- // should consist of valid TSql DDL statements.
- //
- // Parameters:
- // inputScript:
- // Script containing TSql DDL statements
- //
- // sourceName:
- // A name to identify the inputScript, for example a fileName such as "MyTable.sql"
- // or simply an alias like "dbo.Table". Scripts are cached and TSqlObjects are
- // linked to the source name. Any future Update/Delete operations will remove
- // all existing objects with the same script name and replace them with the
- // new objects.
- //
- // options:
- // Options defining how to interpret the script
- //
- // Exceptions:
- // System.ArgumentNullException:
- // If the supplied inputScript is null.
- //
- // System.ArgumentException:
- // If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
- // Note: source names ending in ".xsd" are currently not supported. These relate
- // to Xml Schema Collections and adding of these is currently not supported
- // in the public API.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void AddOrUpdateObjects(string inputScript, string sourceName, TSqlObjectOptions options)
- {
- model.AddOrUpdateObjects(inputScript, sourceName, options);
- }
+ //
+ // Summary:
+ // Adds or updates the objects defined for a specified sourceName with the objects
+ // defined in the inputScript. If any objects were previously added with the
+ // same sourceName these will be completely replaced The object definitions
+ // are based on the contents of a TSql Script string plus additional metadata
+ // defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions object The script
+ // should consist of valid TSql DDL statements.
+ //
+ // Parameters:
+ // inputScript:
+ // Script containing TSql DDL statements
+ //
+ // sourceName:
+ // A name to identify the inputScript, for example a fileName such as "MyTable.sql"
+ // or simply an alias like "dbo.Table". Scripts are cached and TSqlObjects are
+ // linked to the source name. Any future Update/Delete operations will remove
+ // all existing objects with the same script name and replace them with the
+ // new objects.
+ //
+ // options:
+ // Options defining how to interpret the script
+ //
+ // Exceptions:
+ // System.ArgumentNullException:
+ // If the supplied inputScript is null.
+ //
+ // System.ArgumentException:
+ // If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
+ // Note: source names ending in ".xsd" are currently not supported. These relate
+ // to Xml Schema Collections and adding of these is currently not supported
+ // in the public API.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void AddOrUpdateObjects(string inputScript, string sourceName, TSqlObjectOptions options) => model.AddOrUpdateObjects(inputScript, sourceName, options);
- //
- // Summary:
- // Adds or updates the objects defined for a specified sourceName with the objects
- // defined in the inputScript. If any objects were previously added with the
- // same sourceName these will be completely replaced The object definitions
- // are based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
- // object plus additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
- // object The script should consist of valid TSql DDL statements.
- //
- // Parameters:
- // inputScript:
- // Script containing TSql DDL statements
- //
- // sourceName:
- // A name to identify the inputScript, for example a fileName such as "MyTable.sql"
- // or simply an alias like "dbo.Table". Scripts are cached and TSqlObjects are
- // linked to the source name. Any future Update/Delete operations will remove
- // all existing objects with the same script name and replace them with the
- // new objects.
- //
- // options:
- // Options defining how to interpret the script
- //
- // Exceptions:
- // System.ArgumentNullException:
- // If the supplied inputScript is null.
- //
- // System.ArgumentException:
- // If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
- // Note: source names ending in ".xsd" are currently not supported. These relate
- // to Xml Schema Collections and adding of these is currently not supported
- // in the public API.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void AddOrUpdateObjects(TSqlScript inputScript, string sourceName, TSqlObjectOptions options)
- {
- model.AddOrUpdateObjects(inputScript, sourceName, options);
- }
+ //
+ // Summary:
+ // Adds or updates the objects defined for a specified sourceName with the objects
+ // defined in the inputScript. If any objects were previously added with the
+ // same sourceName these will be completely replaced The object definitions
+ // are based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
+ // object plus additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
+ // object The script should consist of valid TSql DDL statements.
+ //
+ // Parameters:
+ // inputScript:
+ // Script containing TSql DDL statements
+ //
+ // sourceName:
+ // A name to identify the inputScript, for example a fileName such as "MyTable.sql"
+ // or simply an alias like "dbo.Table". Scripts are cached and TSqlObjects are
+ // linked to the source name. Any future Update/Delete operations will remove
+ // all existing objects with the same script name and replace them with the
+ // new objects.
+ //
+ // options:
+ // Options defining how to interpret the script
+ //
+ // Exceptions:
+ // System.ArgumentNullException:
+ // If the supplied inputScript is null.
+ //
+ // System.ArgumentException:
+ // If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
+ // Note: source names ending in ".xsd" are currently not supported. These relate
+ // to Xml Schema Collections and adding of these is currently not supported
+ // in the public API.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void AddOrUpdateObjects(TSqlScript inputScript, string sourceName, TSqlObjectOptions options) => model.AddOrUpdateObjects(inputScript, sourceName, options);
- //
- // Summary:
- // Copies the Microsoft.SqlServer.Dac.Model.DatabaseOptions for the model to
- // a Microsoft.SqlServer.Dac.Model.TSqlModelOptions object. This is useful
- // if you wish to duplicate the options for a model when creating a new model.
- //
- // Returns:
- // Microsoft.SqlServer.Dac.Model.TSqlModelOptions with settings matching the
- // database options of the model
- public TSqlModelOptions CopyModelOptions()
- {
- return model.CopyModelOptions();
- }
+ //
+ // Summary:
+ // Copies the Microsoft.SqlServer.Dac.Model.DatabaseOptions for the model to
+ // a Microsoft.SqlServer.Dac.Model.TSqlModelOptions object. This is useful
+ // if you wish to duplicate the options for a model when creating a new model.
+ //
+ // Returns:
+ // Microsoft.SqlServer.Dac.Model.TSqlModelOptions with settings matching the
+ // database options of the model
+ public TSqlModelOptions CopyModelOptions() => model.CopyModelOptions();
- //
- // Summary:
- // Deletes any objects that were added to the model with the specified sourceName.
- //
- // Parameters:
- // sourceName:
- // A name to identify the source to be deleted, for example a fileName such
- // as "MyTable.sql" or simply an alias like "dbo.Table". Scripts are cached
- // and TSqlObjects are linked to the source name.
- //
- // Exceptions:
- // System.ArgumentException:
- // If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
- // Note: source names ending in ".xsd" are currently not supported. These relate
- // to Xml Schema Collections and adding of these is currently not supported
- // in the public API.
- //
- // System.Runtime.Remoting.RemotingException:
- // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
- // fails.
- public void DeleteObjects(string sourceName)
- {
- model.DeleteObjects(sourceName);
- }
+ //
+ // Summary:
+ // Deletes any objects that were added to the model with the specified sourceName.
+ //
+ // Parameters:
+ // sourceName:
+ // A name to identify the source to be deleted, for example a fileName such
+ // as "MyTable.sql" or simply an alias like "dbo.Table". Scripts are cached
+ // and TSqlObjects are linked to the source name.
+ //
+ // Exceptions:
+ // System.ArgumentException:
+ // If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
+ // Note: source names ending in ".xsd" are currently not supported. These relate
+ // to Xml Schema Collections and adding of these is currently not supported
+ // in the public API.
+ //
+ // System.Runtime.Remoting.RemotingException:
+ // If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
+ // fails.
+ public void DeleteObjects(string sourceName) => model.DeleteObjects(sourceName);
- public void Dispose()
- {
- if (this.model != null)
- {
- model.Dispose();
- model = null;
- }
- }
+ public void Dispose()
+ {
+ model?.Dispose();
+ model = null;
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/DacFxStrongTypedCore.161/Utils.cs b/src/Core/DacFxStrongTypedCore.161/Utils.cs
index 5f282702b..e69de29bb 100644
--- a/src/Core/DacFxStrongTypedCore.161/Utils.cs
+++ b/src/Core/DacFxStrongTypedCore.161/Utils.cs
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/src/Core/DacFxStrongTypedCore.161/VersionSpecificImplementations.cs b/src/Core/DacFxStrongTypedCore.161/VersionSpecificImplementations.cs
index 9c83e3394..beb4f5823 100644
--- a/src/Core/DacFxStrongTypedCore.161/VersionSpecificImplementations.cs
+++ b/src/Core/DacFxStrongTypedCore.161/VersionSpecificImplementations.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
//
// The MIT License (MIT)
@@ -25196,4 +25196,4 @@ String ISqlAzureV12TSqlXmlSchemaCollection.Expression
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/ClassicHumanizerPluralizerTest.cs b/src/Core/NUnitTestCore/ClassicHumanizerPluralizerTest.cs
index 9a1911974..d342799e3 100644
--- a/src/Core/NUnitTestCore/ClassicHumanizerPluralizerTest.cs
+++ b/src/Core/NUnitTestCore/ClassicHumanizerPluralizerTest.cs
@@ -1,26 +1,25 @@
-using Xunit;
using RevEng.Core;
+using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class ClassicHumanizerPluralizerTest
{
- public class ClassicHumanizerPluralizerTest
+ [Fact]
+ public void SingularizeUserData()
{
- [Fact]
- public void SingularizeUserData()
- {
- var sut = new HumanizerPluralizer();
- var result = sut.Singularize("UserData");
+ var sut = new HumanizerPluralizer();
+ var result = sut.Singularize("UserData");
- Assert.Equal("UserDatum", result);
- }
+ Assert.Equal("UserDatum", result);
+ }
- [Fact]
- public void PluralizeUserStatus()
- {
- var sut = new HumanizerPluralizer();
- var result = sut.Pluralize("UserStatus");
+ [Fact]
+ public void PluralizeUserStatus()
+ {
+ var sut = new HumanizerPluralizer();
+ var result = sut.Pluralize("UserStatus");
- Assert.Equal("UserStatuses", result);
- }
+ Assert.Equal("UserStatuses", result);
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/CliExitCodeTests.cs b/src/Core/NUnitTestCore/CliExitCodeTests.cs
index c33ca7c07..b602ccbac 100644
--- a/src/Core/NUnitTestCore/CliExitCodeTests.cs
+++ b/src/Core/NUnitTestCore/CliExitCodeTests.cs
@@ -4,107 +4,107 @@
using ErikEJ.EFCorePowerTools;
using Xunit;
-namespace NUnitTestCore
+namespace NUnitTestCore;
+
+// Program.MainAsync uses the process-wide Environment.ExitCode, so these tests must not run in parallel.
+[Collection(nameof(CliExitCodeTests))]
+public sealed class CliExitCodeTests : IDisposable
{
- // Program.MainAsync uses the process-wide Environment.ExitCode, so these tests must not run in parallel.
- [Collection(nameof(CliExitCodeTests))]
- public sealed class CliExitCodeTests : IDisposable
- {
- private static readonly TimeSpan RunTimeout = TimeSpan.FromSeconds(60);
+ private static readonly TimeSpan RunTimeout = TimeSpan.FromSeconds(60);
- private readonly string workDirectory;
- private readonly string dacpacPath;
- private readonly string configPath;
+ private readonly string workDirectory;
+ private readonly string dacpacPath;
+ private readonly string configPath;
- public CliExitCodeTests()
- {
- workDirectory = Path.Combine(Path.GetTempPath(), "EFCorePowerTools.Tests", Guid.NewGuid().ToString("N"));
- Directory.CreateDirectory(workDirectory);
+ public CliExitCodeTests()
+ {
+ workDirectory = Path.Combine(Path.GetTempPath(), "EFCorePowerTools.Tests", Guid.NewGuid().ToString("N"));
+ Directory.CreateDirectory(workDirectory);
- dacpacPath = Path.Combine(workDirectory, "abc.dacpac");
- File.Copy(Path.Combine(AppContext.BaseDirectory, "Dacpac", "abc.dacpac"), dacpacPath);
+ dacpacPath = Path.Combine(workDirectory, "abc.dacpac");
+ File.Copy(Path.Combine(AppContext.BaseDirectory, "Dacpac", "abc.dacpac"), dacpacPath);
- configPath = Path.Combine(workDirectory, "efcpt-config.json");
- File.WriteAllText(
- configPath,
- @"{
+ configPath = Path.Combine(workDirectory, "efcpt-config.json");
+ File.WriteAllText(
+ configPath,
+ /*lang=json,strict*/
+ @"{
""code-generation"": { ""use-t4"": true, ""refresh-object-lists"": true },
""names"": { ""dbcontext-name"": ""TestContext"", ""root-namespace"": ""TestNamespace"" }
}");
- Environment.ExitCode = 0;
- }
-
- public void Dispose()
- {
- Environment.ExitCode = 0;
+ Environment.ExitCode = 0;
+ }
- if (Directory.Exists(workDirectory))
- {
- Directory.Delete(workDirectory, true);
- }
- }
+ public void Dispose()
+ {
+ Environment.ExitCode = 0;
- [Fact]
- public async Task MainAsyncReturnsZeroForValidDacpac()
+ if (Directory.Exists(workDirectory))
{
- var exitCode = await RunEfcptAsync(dacpacPath, configPath);
-
- Assert.Equal(0, exitCode);
+ Directory.Delete(workDirectory, true);
}
+ }
- [Fact]
- public async Task MainAsyncReturnsOneWhenGenerationFails()
- {
- Assert.Equal(0, await RunEfcptAsync(dacpacPath, configPath));
-
- await File.WriteAllTextAsync(
- Path.Combine(workDirectory, "CodeTemplates", "EFCore", "DbContext.t4"),
- "<#@ template hostSpecific=\"true\" #>\n<# this is not valid C#; #>\n",
- TestContext.Current.CancellationToken);
-
- var exitCode = await RunEfcptAsync(dacpacPath, configPath);
+ [Fact]
+ public async Task MainAsyncReturnsZeroForValidDacpac()
+ {
+ var exitCode = await RunEfcptAsync(dacpacPath, configPath);
- Assert.Equal(1, exitCode);
- }
+ Assert.Equal(0, exitCode);
+ }
- [Fact]
- public async Task MainAsyncReturnsOneWhenDacpacIsInvalid()
- {
- var invalidDacpacPath = Path.Combine(workDirectory, "Invalid.dacpac");
- await File.WriteAllTextAsync(invalidDacpacPath, "not a dacpac", TestContext.Current.CancellationToken);
+ [Fact]
+ public async Task MainAsyncReturnsOneWhenGenerationFails()
+ {
+ Assert.Equal(0, await RunEfcptAsync(dacpacPath, configPath));
- var exitCode = await RunEfcptAsync(invalidDacpacPath, configPath);
+ await File.WriteAllTextAsync(
+ Path.Combine(workDirectory, "CodeTemplates", "EFCore", "DbContext.t4"),
+ "<#@ template hostSpecific=\"true\" #>\n<# this is not valid C#; #>\n",
+ TestContext.Current.CancellationToken);
- Assert.Equal(1, exitCode);
- }
+ var exitCode = await RunEfcptAsync(dacpacPath, configPath);
- [Fact]
- public async Task MainAsyncReturnsOneWhenConfigFileIsInvalid()
- {
- var invalidConfigPath = Path.Combine(workDirectory, "invalid-config.json");
- await File.WriteAllTextAsync(invalidConfigPath, "{ not json", TestContext.Current.CancellationToken);
+ Assert.Equal(1, exitCode);
+ }
- var exitCode = await RunEfcptAsync(dacpacPath, invalidConfigPath);
+ [Fact]
+ public async Task MainAsyncReturnsOneWhenDacpacIsInvalid()
+ {
+ var invalidDacpacPath = Path.Combine(workDirectory, "Invalid.dacpac");
+ await File.WriteAllTextAsync(invalidDacpacPath, "not a dacpac", TestContext.Current.CancellationToken);
- Assert.Equal(1, exitCode);
- }
+ var exitCode = await RunEfcptAsync(invalidDacpacPath, configPath);
- private async Task RunEfcptAsync(string dacpac, string config)
- {
- Environment.ExitCode = 0;
+ Assert.Equal(1, exitCode);
+ }
- var run = Program.MainAsync(new[] { dacpac, "mssql", "-i", config, "-o", workDirectory });
- var completed = await Task.WhenAny(run, Task.Delay(RunTimeout, TestContext.Current.CancellationToken));
+ [Fact]
+ public async Task MainAsyncReturnsOneWhenConfigFileIsInvalid()
+ {
+ var invalidConfigPath = Path.Combine(workDirectory, "invalid-config.json");
+ await File.WriteAllTextAsync(invalidConfigPath, "{ not json", TestContext.Current.CancellationToken);
- Assert.True(completed == run, $"efcpt did not exit within {RunTimeout.TotalSeconds} seconds.");
+ var exitCode = await RunEfcptAsync(dacpacPath, invalidConfigPath);
- return await run;
- }
+ Assert.Equal(1, exitCode);
}
- [CollectionDefinition(nameof(CliExitCodeTests), DisableParallelization = true)]
- public sealed class CliExitCodeTestsDefinition
+ private async Task RunEfcptAsync(string dacpac, string config)
{
+ Environment.ExitCode = 0;
+
+ var run = Program.MainAsync([dacpac, "mssql", "-i", config, "-o", workDirectory]);
+ var completed = await Task.WhenAny(run, Task.Delay(RunTimeout, TestContext.Current.CancellationToken));
+
+ Assert.True(completed == run, $"efcpt did not exit within {RunTimeout.TotalSeconds} seconds.");
+
+ return await run;
}
}
+
+[CollectionDefinition(nameof(CliExitCodeTests), DisableParallelization = true)]
+public sealed class CliExitCodeTestsDefinition
+{
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/CliObjectListTest.cs b/src/Core/NUnitTestCore/CliObjectListTest.cs
index 386c3128a..e039be026 100644
--- a/src/Core/NUnitTestCore/CliObjectListTest.cs
+++ b/src/Core/NUnitTestCore/CliObjectListTest.cs
@@ -4,438 +4,423 @@
using System.Linq;
using System.Text;
using System.Text.Json;
-using Xunit;
using RevEng.Common;
using RevEng.Common.Cli;
using RevEng.Common.Cli.Configuration;
+using Xunit;
+
+namespace UnitTests;
-namespace UnitTests
+public class CliObjectListTest
{
- public class CliObjectListTest
- {
- private readonly string cliTestDirectory = Path.Combine(AppContext.BaseDirectory, "CliObjectListTests");
+ private readonly string cliTestDirectory = Path.Combine(AppContext.BaseDirectory, "CliObjectListTests");
- public CliObjectListTest()
+ public CliObjectListTest()
+ {
+ if (!Directory.Exists(cliTestDirectory))
{
- if (!Directory.Exists(cliTestDirectory))
- {
- Directory.CreateDirectory(cliTestDirectory);
- }
+ Directory.CreateDirectory(cliTestDirectory);
}
+ }
- [Fact]
- public void CanGetConfig()
- {
- var config = GetConfig();
-
- var result = CliConfigMapper.BuildObjectList(config);
+ [Fact]
+ public void CanGetConfig()
+ {
+ var config = GetConfig();
- Assert.NotNull(result);
- Assert.Equal(7, result.Count);
- Assert.Contains(result, x => x.Name == "[dbo].[Users]");
- Assert.Contains(result, x => x.Name == "[other].[Accounts]");
- Assert.Contains(result, x => x.Name == "[dbo].[Extras]");
- Assert.Contains(result, x => x.Name == "[dbo].[Actors]");
- Assert.Contains(result, x => x.Name == "[dbo].[Directors]");
- Assert.Contains(result, x => x.Name == "[dbo].[UsersView]");
- Assert.Contains(result, x => x.Name == "TestProcedure");
+ var result = CliConfigMapper.BuildObjectList(config);
- var testProcedure = result.Single(x => x.Name == "TestProcedure");
+ Assert.NotNull(result);
+ Assert.Equal(7, result.Count);
+ Assert.Contains(result, x => x.Name == "[dbo].[Users]");
+ Assert.Contains(result, x => x.Name == "[other].[Accounts]");
+ Assert.Contains(result, x => x.Name == "[dbo].[Extras]");
+ Assert.Contains(result, x => x.Name == "[dbo].[Actors]");
+ Assert.Contains(result, x => x.Name == "[dbo].[Directors]");
+ Assert.Contains(result, x => x.Name == "[dbo].[UsersView]");
+ Assert.Contains(result, x => x.Name == "TestProcedure");
- Assert.True(testProcedure.UseLegacyResultSetDiscovery);
- Assert.Equal("MyNamespace.MyType", testProcedure.MappedType);
- Assert.True(testProcedure.GenerateEmptyResultType);
- }
+ var testProcedure = result.Single(x => x.Name == "TestProcedure");
- [Fact]
- public void ToCommandOptionsMapsGenerateEmptyResultTypeForStoredProcedure()
- {
- var config = GetConfig();
- var configPath = TestPath("test.efcpt-config.json");
+ Assert.True(testProcedure.UseLegacyResultSetDiscovery);
+ Assert.Equal("MyNamespace.MyType", testProcedure.MappedType);
+ Assert.True(testProcedure.GenerateEmptyResultType);
+ }
- var commandOptions = config.ToCommandOptions(
- "Server=.;Database=TestDb;Trusted_Connection=True;",
- DatabaseType.SQLServer,
- cliTestDirectory,
- isDacpac: false,
- configPath,
- "efpt.renaming.json");
+ [Fact]
+ public void ToCommandOptionsMapsGenerateEmptyResultTypeForStoredProcedure()
+ {
+ var config = GetConfig();
+ var configPath = TestPath("test.efcpt-config.json");
+
+ var commandOptions = config.ToCommandOptions(
+ "Server=.;Database=TestDb;Trusted_Connection=True;",
+ DatabaseType.SQLServer,
+ cliTestDirectory,
+ isDacpac: false,
+ configPath,
+ "efpt.renaming.json");
+
+ var testProcedure = commandOptions.Tables.Single(x => x.ObjectType == ObjectType.Procedure && x.Name == "TestProcedure");
+ Assert.True(testProcedure.GenerateEmptyResultType);
+ }
- var testProcedure = commandOptions.Tables.Single(x => x.ObjectType == ObjectType.Procedure && x.Name == "TestProcedure");
- Assert.True(testProcedure.GenerateEmptyResultType);
- }
+ [Fact]
+ public void CanUseGobalFilter()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanUseGobalFilter()
- {
- var config = GetConfig();
+ config.Views.Add(new View { ExclusionWildcard = "*" });
+ config.Tables.Add(new Table { ExclusionWildcard = "*" });
- config.Views.Add(new View { ExclusionWildcard = "*" });
- config.Tables.Add(new Table { ExclusionWildcard = "*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(2, result.Count);
+ Assert.StartsWith("Dummy", result[0].Name);
+ }
- Assert.NotNull(result);
- Assert.Equal(2, result.Count);
- Assert.StartsWith("Dummy", result[0].Name);
- }
+ [Fact]
+ public void CanAddStartsWithFilter()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddStartsWithFilter()
- {
- var config = GetConfig();
+ config.Tables.Add(new Table { ExclusionWildcard = "[dbo]*" });
- config.Tables.Add(new Table { ExclusionWildcard = "[dbo]*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(3, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(3, result.Count);
- }
+ [Fact]
+ public void CanAddStartsWithFilter2()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddStartsWithFilter2()
- {
- var config = GetConfig();
+ config.Tables.Add(new Table { ExclusionWildcard = "[other]*" });
- config.Tables.Add(new Table { ExclusionWildcard = "[other]*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(6, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(6, result.Count);
- }
+ [Fact]
+ public void CanAddStartsWithFilterAndExplicitInclude()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddStartsWithFilterAndExplicitInclude()
- {
- var config = GetConfig();
+ config.Tables.First().Exclude = false;
- config.Tables.First().Exclude = false;
+ config.Tables.Add(new Table { ExclusionWildcard = "[dbo]*" });
- config.Tables.Add(new Table { ExclusionWildcard = "[dbo]*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(4, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(4, result.Count);
- }
+ [Fact]
+ public void MultipleExclusionWildcardExcludes()
+ {
+ var config = GetConfig();
- [Fact]
- public void MultipleExclusionWildcardExcludes()
- {
- var config = GetConfig();
+ config.Tables.Add(new Table { ExclusionWildcard = "*Users*" });
+ config.Tables.Add(new Table { ExclusionWildcard = "*Accounts*" });
+ config.Views.Add(new View { ExclusionWildcard = "*Users*" });
- config.Tables.Add(new Table { ExclusionWildcard = "*Users*" });
- config.Tables.Add(new Table { ExclusionWildcard = "*Accounts*" });
- config.Views.Add(new View { ExclusionWildcard = "*Users*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(4, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(4, result.Count);
- }
+ [Fact]
+ public void CanAddEndsWithFilter()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddEndsWithFilter()
- {
- var config = GetConfig();
+ config.Tables.Add(new Table { ExclusionWildcard = "*ors]" });
- config.Tables.Add(new Table { ExclusionWildcard = "*ors]" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(5, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(5, result.Count);
- }
+ [Fact]
+ public void CanAddEndsWithFilterAndExplicitInclude()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddEndsWithFilterAndExplicitInclude()
- {
- var config = GetConfig();
+ config.Tables.First().Exclude = false;
- config.Tables.First().Exclude = false;
+ config.Tables.Add(new Table { ExclusionWildcard = "*ors]" });
- config.Tables.Add(new Table { ExclusionWildcard = "*ors]" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(5, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(5, result.Count);
- }
+ [Fact]
+ public void CanAddContainsFilter()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddContainsFilter()
- {
- var config = GetConfig();
+ config.Tables.Add(new Table { ExclusionWildcard = "*].[Ac*" });
- config.Tables.Add(new Table { ExclusionWildcard = "*].[Ac*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(5, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(5, result.Count);
- }
+ [Fact]
+ public void CanAddContainsFilterAndExplicitInclude()
+ {
+ var config = GetConfig();
- [Fact]
- public void CanAddContainsFilterAndExplicitInclude()
- {
- var config = GetConfig();
+ config.Tables[1].Exclude = false;
- config.Tables[1].Exclude = false;
+ config.Tables.Add(new Table { ExclusionWildcard = "*].[Ac*" });
- config.Tables.Add(new Table { ExclusionWildcard = "*].[Ac*" });
+ var result = CliConfigMapper.BuildObjectList(config);
- var result = CliConfigMapper.BuildObjectList(config);
+ Assert.NotNull(result);
+ Assert.Equal(6, result.Count);
+ }
- Assert.NotNull(result);
- Assert.Equal(6, result.Count);
- }
+ [Fact]
+ public void TryGetCliConfigWithExistingFileReturnsExpectedConfig()
+ {
+ var config = GetConfig();
+ config.CodeGeneration.UseStoredProcedureResultSetFallback = false;
+ config.CodeGeneration.FileLineEndings = "crlf";
+ config.CodeGeneration.FileCharset = "utf-8";
- [Fact]
- public void TryGetCliConfigWithExistingFileReturnsExpectedConfig()
+ var testPath = TestPath("test.efpcli.json");
+ try
{
- var config = GetConfig();
- config.CodeGeneration.UseStoredProcedureResultSetFallback = false;
- config.CodeGeneration.FileLineEndings = "crlf";
- config.CodeGeneration.FileCharset = "utf-8";
+ WriteConfigFile(config, testPath);
- var testPath = TestPath("test.efpcli.json");
- try
- {
- WriteConfigFile(config, testPath);
-
- var fetchedConfigSuccess = CliConfigMapper.TryGetCliConfig(testPath, "fakeConnectionString",
- DatabaseType.SQLServer,
- GetDefaultTables(DatabaseType.SQLServer), CodeGenerationMode.EFCore8,
- out CliConfig resultConfig,
- out List warnings);
-
- Assert.True(fetchedConfigSuccess);
- Assert.NotNull(resultConfig);
- Assert.Equal(config.Tables.Count, resultConfig.Tables.Count);
- Assert.False(resultConfig.CodeGeneration.UseStoredProcedureResultSetFallback);
- Assert.Equal("crlf", resultConfig.CodeGeneration.FileLineEndings);
- Assert.Equal("utf-8", resultConfig.CodeGeneration.FileCharset);
-
- for (var i = 0; i < config.Tables.Count; i++)
- {
- Assert.Equal(config.Tables[i].Name, resultConfig.Tables[i].Name);
- Assert.Equal(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
- Assert.Equal(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
- }
- }
- finally
+ var fetchedConfigSuccess = CliConfigMapper.TryGetCliConfig(testPath, "fakeConnectionString",
+ DatabaseType.SQLServer,
+ GetDefaultTables(DatabaseType.SQLServer), CodeGenerationMode.EFCore8,
+ out var resultConfig,
+ out var warnings);
+
+ Assert.True(fetchedConfigSuccess);
+ Assert.NotNull(resultConfig);
+ Assert.Equal(config.Tables.Count, resultConfig.Tables.Count);
+ Assert.False(resultConfig.CodeGeneration.UseStoredProcedureResultSetFallback);
+ Assert.Equal("crlf", resultConfig.CodeGeneration.FileLineEndings);
+ Assert.Equal("utf-8", resultConfig.CodeGeneration.FileCharset);
+
+ for (var i = 0; i < config.Tables.Count; i++)
{
- RemoveConfigFile(testPath);
+ Assert.Equal(config.Tables[i].Name, resultConfig.Tables[i].Name);
+ Assert.Equal(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
+ Assert.Equal(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
}
}
-
- [Fact]
- public void ToCommandOptionsMapsFileLineEndings()
+ finally
{
- var config = GetConfig();
- config.CodeGeneration.FileLineEndings = "lf";
- config.Names.DbContextName = "TestContext";
-
- var commandOptions = config.ToCommandOptions(
- "Server=(localdb)\\mssqllocaldb;Database=Northwind;Trusted_Connection=True;",
- DatabaseType.SQLServer,
- cliTestDirectory,
- false,
- TestPath("test.efpcli.json"),
- TestPath("efpt.renaming.json"));
-
- Assert.Equal("lf", commandOptions.FileLineEndingStyle);
+ RemoveConfigFile(testPath);
}
+ }
- [Fact]
- public void ToCommandOptionsMapsFileCharset()
- {
- var config = GetConfig();
- config.CodeGeneration.FileCharset = "utf-8";
- config.Names.DbContextName = "TestContext";
-
- var commandOptions = config.ToCommandOptions(
- "Server=(localdb)\\mssqllocaldb;Database=Northwind;Trusted_Connection=True;",
- DatabaseType.SQLServer,
- cliTestDirectory,
- false,
- TestPath("test.efpcli.json"),
- TestPath("efpt.renaming.json"));
+ [Fact]
+ public void ToCommandOptionsMapsFileLineEndings()
+ {
+ var config = GetConfig();
+ config.CodeGeneration.FileLineEndings = "lf";
+ config.Names.DbContextName = "TestContext";
+
+ var commandOptions = config.ToCommandOptions(
+ "Server=(localdb)\\mssqllocaldb;Database=Northwind;Trusted_Connection=True;",
+ DatabaseType.SQLServer,
+ cliTestDirectory,
+ false,
+ TestPath("test.efpcli.json"),
+ TestPath("efpt.renaming.json"));
+
+ Assert.Equal("lf", commandOptions.FileLineEndingStyle);
+ }
- Assert.Equal("utf-8", commandOptions.FileCharset);
- }
+ [Fact]
+ public void ToCommandOptionsMapsFileCharset()
+ {
+ var config = GetConfig();
+ config.CodeGeneration.FileCharset = "utf-8";
+ config.Names.DbContextName = "TestContext";
+
+ var commandOptions = config.ToCommandOptions(
+ "Server=(localdb)\\mssqllocaldb;Database=Northwind;Trusted_Connection=True;",
+ DatabaseType.SQLServer,
+ cliTestDirectory,
+ false,
+ TestPath("test.efpcli.json"),
+ TestPath("efpt.renaming.json"));
+
+ Assert.Equal("utf-8", commandOptions.FileCharset);
+ }
- [Fact]
- public void FileCharsetDefaultsToUtf8Bom()
- {
- Assert.Equal("utf-8-bom", new CodeGeneration().FileCharset);
- Assert.Equal("utf-8-bom", new ReverseEngineerCommandOptions().FileCharset);
- }
+ [Fact]
+ public void FileCharsetDefaultsToUtf8Bom()
+ {
+ Assert.Equal("utf-8-bom", new CodeGeneration().FileCharset);
+ Assert.Equal("utf-8-bom", new ReverseEngineerCommandOptions().FileCharset);
+ }
- [Fact]
- public void TryGetCliConfigWithExcludedColumnsReturns()
- {
- var config = GetConfig();
- var userTable = config.Tables.Single(x => x.Name == "[dbo].[Users]");
- userTable.ExcludedColumns = new List { "UserId", "AccountId", "Name" };
+ [Fact]
+ public void TryGetCliConfigWithExcludedColumnsReturns()
+ {
+ var config = GetConfig();
+ var userTable = config.Tables.Single(x => x.Name == "[dbo].[Users]");
+ userTable.ExcludedColumns = new List { "UserId", "AccountId", "Name" };
- var userView = config.Views.Single(x => x.Name == "[dbo].[UsersView]");
- userView.ExcludedColumns = new List { "UserId", "AccountId", "Name" };
+ var userView = config.Views.Single(x => x.Name == "[dbo].[UsersView]");
+ userView.ExcludedColumns = new List { "UserId", "AccountId", "Name" };
- config.Functions = new List()
- {
- new()
- {
- Name = "TestFunction",
- ExcludedColumns = new List { "ColumnA", "ColumnB"}
- }
- };
-
- config.StoredProcedures = new List()
+ config.Functions = new List()
+ {
+ new()
{
- new()
- {
- Name = "TestProcedure",
- ExcludedColumns = new List { "ColumnA", "ColumnB"}
- }
- };
+ Name = "TestFunction",
+ ExcludedColumns = new List { "ColumnA", "ColumnB"}
+ }
+ };
- var testPath = TestPath("test.efpcli.json");
- try
+ config.StoredProcedures = new List()
+ {
+ new()
{
- WriteConfigFile(config, testPath);
+ Name = "TestProcedure",
+ ExcludedColumns = new List { "ColumnA", "ColumnB"}
+ }
+ };
- var fetchedConfigSuccess = CliConfigMapper.TryGetCliConfig(testPath, "fakeConnectionString",
- DatabaseType.SQLServer,
- GetDefaultTables(DatabaseType.SQLServer), CodeGenerationMode.EFCore8,
- out CliConfig resultConfig,
- out List warnings);
+ var testPath = TestPath("test.efpcli.json");
+ try
+ {
+ WriteConfigFile(config, testPath);
- Assert.True(fetchedConfigSuccess);
- Assert.NotNull(resultConfig);
- Assert.Equal(config.Tables.Count, resultConfig.Tables.Count);
+ var fetchedConfigSuccess = CliConfigMapper.TryGetCliConfig(testPath, "fakeConnectionString",
+ DatabaseType.SQLServer,
+ GetDefaultTables(DatabaseType.SQLServer), CodeGenerationMode.EFCore8,
+ out var resultConfig,
+ out var warnings);
- for (var i = 0; i < config.Tables.Count; i++)
- {
- Assert.Equal(config.Tables[i].Name, resultConfig.Tables[i].Name);
- Assert.Equal(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
- Assert.Equal(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
- }
+ Assert.True(fetchedConfigSuccess);
+ Assert.NotNull(resultConfig);
+ Assert.Equal(config.Tables.Count, resultConfig.Tables.Count);
- Assert.Equal(4, warnings.Count);
- Assert.Equal(3, resultConfig.Tables[0].ExcludedColumns.Count);
- Assert.Equal("UserId", resultConfig.Tables[0].ExcludedColumns[0]);
- Assert.Equal(3, resultConfig.Views[0].ExcludedColumns.Count);
- Assert.Equal("UserId", resultConfig.Views[0].ExcludedColumns[0]);
- Assert.Null(resultConfig.Functions[0].ExcludedColumns);
- Assert.Null(resultConfig.StoredProcedures[0].ExcludedColumns);
- }
- finally
+ for (var i = 0; i < config.Tables.Count; i++)
{
- RemoveConfigFile(testPath);
+ Assert.Equal(config.Tables[i].Name, resultConfig.Tables[i].Name);
+ Assert.Equal(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
+ Assert.Equal(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
}
- }
- private static List GetDefaultTables(DatabaseType databaseType)
- {
- return new List()
- {
- new TableModel("Users", "dbo", databaseType, ObjectType.Table, new List()
- {
- new ColumnModel("UserId", "", true, false),
- new ColumnModel("AccountId", "", false, true),
- new ColumnModel("Name", "", false, false),
- new ColumnModel("Email", "", false, false),
-
- }),
- new TableModel("Accounts", "other", databaseType, ObjectType.Table, new List()),
- new TableModel("Extras", "dbo", databaseType, ObjectType.Table, new List()),
- new TableModel("Actors", "dbo", databaseType, ObjectType.Table, new List()),
- new TableModel("Directors", "dbo", databaseType, ObjectType.Table, new List()),
- new TableModel("TestFunction", "dbo", databaseType, ObjectType.ScalarFunction, new List()
- {
- new ColumnModel("ColumnA", "", false, false),
- new ColumnModel("ColumnB", "", false, false)
- }),
- new TableModel("TestProcedure", "dbo", databaseType, ObjectType.Procedure, new List()
- {
- new ColumnModel("ColumnA", "", false, false),
- new ColumnModel("ColumnB", "", false, false)
- }),
- new TableModel("UsersView", "dbo", databaseType, ObjectType.View, new List()
- {
- new ColumnModel("UserId", "", true, false),
- new ColumnModel("AccountId", "", false, true),
- new ColumnModel("Name", "", false, false)
- })
- };
+ Assert.Equal(4, warnings.Count);
+ Assert.Equal(3, resultConfig.Tables[0].ExcludedColumns.Count);
+ Assert.Equal("UserId", resultConfig.Tables[0].ExcludedColumns[0]);
+ Assert.Equal(3, resultConfig.Views[0].ExcludedColumns.Count);
+ Assert.Equal("UserId", resultConfig.Views[0].ExcludedColumns[0]);
+ Assert.Null(resultConfig.Functions[0].ExcludedColumns);
+ Assert.Null(resultConfig.StoredProcedures[0].ExcludedColumns);
}
-
- private void WriteConfigFile(CliConfig configToWrite, string fullPath)
+ finally
{
- var options = new JsonSerializerOptions { WriteIndented = true };
- File.WriteAllText(fullPath, JsonSerializer.Serialize(configToWrite, options), Encoding.UTF8);
+ RemoveConfigFile(testPath);
}
+ }
- private void RemoveConfigFile(string fullPath)
+ private static List GetDefaultTables(DatabaseType databaseType) => new()
{
- File.Delete(fullPath);
- }
+ new("Users", "dbo", databaseType, ObjectType.Table, new List()
+ {
+ new("UserId", "", true, false),
+ new("AccountId", "", false, true),
+ new("Name", "", false, false),
+ new("Email", "", false, false),
+
+ }),
+ new("Accounts", "other", databaseType, ObjectType.Table, new List()),
+ new("Extras", "dbo", databaseType, ObjectType.Table, new List()),
+ new("Actors", "dbo", databaseType, ObjectType.Table, new List()),
+ new("Directors", "dbo", databaseType, ObjectType.Table, new List()),
+ new("TestFunction", "dbo", databaseType, ObjectType.ScalarFunction, new List()
+ {
+ new("ColumnA", "", false, false),
+ new("ColumnB", "", false, false)
+ }),
+ new("TestProcedure", "dbo", databaseType, ObjectType.Procedure, new List()
+ {
+ new("ColumnA", "", false, false),
+ new("ColumnB", "", false, false)
+ }),
+ new("UsersView", "dbo", databaseType, ObjectType.View, new List()
+ {
+ new("UserId", "", true, false),
+ new("AccountId", "", false, true),
+ new("Name", "", false, false)
+ })
+ };
- private string TestPath(string file)
- {
- return System.IO.Path.Combine(cliTestDirectory, file);
- }
+ private void WriteConfigFile(CliConfig configToWrite, string fullPath)
+ {
+ var options = new JsonSerializerOptions { WriteIndented = true };
+ File.WriteAllText(fullPath, JsonSerializer.Serialize(configToWrite, options), Encoding.UTF8);
+ }
+
+ private void RemoveConfigFile(string fullPath) => File.Delete(fullPath);
- private CliConfig GetConfig()
+ private string TestPath(string file) => Path.Combine(cliTestDirectory, file);
+
+ private CliConfig GetConfig()
+ {
+ var config = new CliConfig
{
- var config = new CliConfig
+ Tables = new List
{
- Tables = new System.Collections.Generic.List
- {
- new Table
- {
- Name = "[dbo].[Users]",
- },
- new Table
- {
- Name = "[other].[Accounts]",
- },
- new Table
- {
- Name = "[dbo].[Extras]",
- },
- new Table
- {
- Name = "[dbo].[Actors]",
- },
- new Table
- {
- Name = "[dbo].[Directors]",
- },
+ new() {
+ Name = "[dbo].[Users]",
},
- Views = new List()
- {
- new View()
- {
- Name = "[dbo].[UsersView]"
- }
+ new() {
+ Name = "[other].[Accounts]",
},
- StoredProcedures = new List()
+ new() {
+ Name = "[dbo].[Extras]",
+ },
+ new() {
+ Name = "[dbo].[Actors]",
+ },
+ new() {
+ Name = "[dbo].[Directors]",
+ },
+ },
+ Views = new List()
+ {
+ new()
+ {
+ Name = "[dbo].[UsersView]"
+ }
+ },
+ StoredProcedures = new List()
+ {
+ new()
{
- new StoredProcedure()
- {
- Name = "TestProcedure",
- UseLegacyResultsetDiscovery = true,
- MappedType = "MyNamespace.MyType",
- GenerateEmptyResultType = true,
- }
+ Name = "TestProcedure",
+ UseLegacyResultsetDiscovery = true,
+ MappedType = "MyNamespace.MyType",
+ GenerateEmptyResultType = true,
}
- };
+ }
+ };
- return config;
- }
+ return config;
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/CustomHumanizerPluralizerTest.cs b/src/Core/NUnitTestCore/CustomHumanizerPluralizerTest.cs
index 10a5f6218..c20f860ee 100644
--- a/src/Core/NUnitTestCore/CustomHumanizerPluralizerTest.cs
+++ b/src/Core/NUnitTestCore/CustomHumanizerPluralizerTest.cs
@@ -2,87 +2,80 @@
using RevEng.Core;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class CustomHumanizerPluralizerTest
{
- public class CustomHumanizerPluralizerTest
+ [Theory]
+ [InlineData("AuditStatus")]
+ [InlineData("TelemetryData")]
+ [InlineData("Delta")]
+ public void DoesNotPluralizeCustomUncountableWords(string word) => Pluralize(word);
+
+ [Theory]
+ [InlineData("AuditStatus")]
+ [InlineData("TelemetryData")]
+ [InlineData("Delta")]
+ public void DoesNotSingularizeCustomUncountableWords(string word) => Singularize(word);
+
+ private static void Pluralize(string word)
+ {
+ Vocabularies.Default.AddUncountable(word);
+ var sut = new HumanizerPluralizer();
+ var result = sut.Pluralize(word);
+
+ Assert.Equal(word, result);
+ }
+
+ private static void Singularize(string word)
{
- [Theory]
- [InlineData("AuditStatus")]
- [InlineData("TelemetryData")]
- [InlineData("Delta")]
- public void DoesNotPluralizeCustomUncountableWords(string word)
- {
- Pluralize(word);
- }
-
- [Theory]
- [InlineData("AuditStatus")]
- [InlineData("TelemetryData")]
- [InlineData("Delta")]
- public void DoesNotSingularizeCustomUncountableWords(string word)
- {
- Singularize(word);
- }
-
- private static void Pluralize(string word)
- {
- Vocabularies.Default.AddUncountable(word);
- var sut = new HumanizerPluralizer();
- var result = sut.Pluralize(word);
-
- Assert.Equal(word, result);
- }
-
- private static void Singularize(string word)
- {
- Vocabularies.Default.AddUncountable(word);
- var sut = new HumanizerPluralizer();
- var result = sut.Singularize(word);
-
- Assert.Equal(word, result);
- }
-
- [Theory]
- [InlineData("Locus", "Loci")]
- [InlineData("Krone", "Kroner")]
- public void PluralizesAndSingularizesIrregularly(string singular, string plural)
- {
- // Verify inflection fails by default. If this assertion fails, then Humanizer's default logic has been enhanced and a better test case is needed.
- var sut = new HumanizerPluralizer();
- Assert.NotEqual(plural, sut.Pluralize(singular));
- Assert.NotEqual(singular, sut.Singularize(plural));
-
- Vocabularies.Default.AddIrregular(singular, plural);
-
- Assert.Equal(plural, sut.Pluralize(singular));
- Assert.Equal(singular, sut.Singularize(plural));
- }
-
- [Theory]
- [InlineData("(.*)mas$", "$1mases", "Christmas", "Christmases")]
- public void DoesPluralizeWithRule(string rule, string replacement, string singular, string plural)
- {
- // Verify inflection fails by default. If this assertion fails, then Humanizer's default logic has been enhanced and a better test case is needed.
- var sut = new HumanizerPluralizer();
- Assert.NotEqual(plural, sut.Pluralize(singular));
-
- Vocabularies.Default.AddPlural(rule, replacement);
-
- Assert.Equal(plural, sut.Pluralize(singular));
- }
-
- [Theory]
- [InlineData("(.*)mases$", "$1mas", "Christmas", "Christmases")]
- public void DoesSingularizeWithRule(string rule, string replacement, string singular, string plural)
- {
- // Verify inflection fails by default. If this assertion fails, then Humanizer's default logic has been enhanced and a better test case is needed.
- var sut = new HumanizerPluralizer();
- Assert.NotEqual(singular, sut.Singularize(plural));
-
- Vocabularies.Default.AddSingular(rule, replacement);
-
- Assert.Equal(singular, sut.Singularize(plural));
- }
+ Vocabularies.Default.AddUncountable(word);
+ var sut = new HumanizerPluralizer();
+ var result = sut.Singularize(word);
+ Assert.Equal(word, result);
}
-}
+
+ [Theory]
+ [InlineData("Locus", "Loci")]
+ [InlineData("Krone", "Kroner")]
+ public void PluralizesAndSingularizesIrregularly(string singular, string plural)
+ {
+ // Verify inflection fails by default. If this assertion fails, then Humanizer's default logic has been enhanced and a better test case is needed.
+ var sut = new HumanizerPluralizer();
+ Assert.NotEqual(plural, sut.Pluralize(singular));
+ Assert.NotEqual(singular, sut.Singularize(plural));
+
+ Vocabularies.Default.AddIrregular(singular, plural);
+
+ Assert.Equal(plural, sut.Pluralize(singular));
+ Assert.Equal(singular, sut.Singularize(plural));
+ }
+
+ [Theory]
+ [InlineData("(.*)mas$", "$1mases", "Christmas", "Christmases")]
+ public void DoesPluralizeWithRule(string rule, string replacement, string singular, string plural)
+ {
+ // Verify inflection fails by default. If this assertion fails, then Humanizer's default logic has been enhanced and a better test case is needed.
+ var sut = new HumanizerPluralizer();
+ Assert.NotEqual(plural, sut.Pluralize(singular));
+
+ Vocabularies.Default.AddPlural(rule, replacement);
+
+ Assert.Equal(plural, sut.Pluralize(singular));
+ }
+
+ [Theory]
+ [InlineData("(.*)mases$", "$1mas", "Christmas", "Christmases")]
+ public void DoesSingularizeWithRule(string rule, string replacement, string singular, string plural)
+ {
+ // Verify inflection fails by default. If this assertion fails, then Humanizer's default logic has been enhanced and a better test case is needed.
+ var sut = new HumanizerPluralizer();
+ Assert.NotEqual(singular, sut.Singularize(plural));
+
+ Vocabularies.Default.AddSingular(rule, replacement);
+
+ Assert.Equal(singular, sut.Singularize(plural));
+ }
+
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/DabBuilderTest.cs b/src/Core/NUnitTestCore/DabBuilderTest.cs
index 32b244072..31f7115ac 100644
--- a/src/Core/NUnitTestCore/DabBuilderTest.cs
+++ b/src/Core/NUnitTestCore/DabBuilderTest.cs
@@ -5,196 +5,195 @@
using RevEng.Core;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test method names")]
+public class DabBuilderTest
{
- [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test method names")]
- public class DabBuilderTest
+ [Theory]
+ [InlineData("User", "User")]
+ [InlineData("Users", "User")]
+ [InlineData("UserStatus", "UserStatus")]
+ [InlineData("UserData", "UserDatum")]
+ [InlineData("user_accounts", "UserAccount")]
+ [InlineData("order_details", "OrderDetail")]
+ [InlineData("product_categories", "ProductCategory")]
+ [InlineData("my_table_name", "MyTableName")]
+ [InlineData("TABLE_NAME", "TableName")]
+ [InlineData("tableName", "TableName")]
+ [InlineData("TableName", "TableName")]
+ [InlineData("table123", "Table123")]
+ [InlineData("123table", "123table")]
+ [InlineData("table_with_multiple_underscores", "TableWithMultipleUnderscore")]
+ public void GenerateEntityName_ShouldConvertToSingularPascalCase(string input, string expected)
{
- [Theory]
- [InlineData("User", "User")]
- [InlineData("Users", "User")]
- [InlineData("UserStatus", "UserStatus")]
- [InlineData("UserData", "UserDatum")]
- [InlineData("user_accounts", "UserAccount")]
- [InlineData("order_details", "OrderDetail")]
- [InlineData("product_categories", "ProductCategory")]
- [InlineData("my_table_name", "MyTableName")]
- [InlineData("TABLE_NAME", "TableName")]
- [InlineData("tableName", "TableName")]
- [InlineData("TableName", "TableName")]
- [InlineData("table123", "Table123")]
- [InlineData("123table", "123table")]
- [InlineData("table_with_multiple_underscores", "TableWithMultipleUnderscore")]
- public void GenerateEntityName_ShouldConvertToSingularPascalCase(string input, string expected)
- {
- // Act
- var result = InvokePrivateStaticMethod("GenerateEntityName", input);
+ // Act
+ var result = InvokePrivateStaticMethod("GenerateEntityName", input);
- // Assert
- Assert.Equal(expected, result);
- }
+ // Assert
+ Assert.Equal(expected, result);
+ }
- [Theory]
- [InlineData("", "")]
- [InlineData(null, "")]
- [InlineData("simple text", "simple text")]
- [InlineData("text with ^ caret", "text with ^^ caret")]
- [InlineData("text with & ampersand", "text with ^& ampersand")]
- [InlineData("text with | pipe", "text with ^| pipe")]
- [InlineData("text with < less", "text with ^< less")]
- [InlineData("text with > greater", "text with ^> greater")]
- [InlineData("text with ! exclamation", "text with ^! exclamation")]
- [InlineData("text with % percent", "text with %% percent")]
- [InlineData("text with \"quote\"", "text with \\\"quote\\\"")]
- [InlineData("complex ^&|<>!%\" test", "complex ^^^&^|^<^>^!%%\\\" test")]
- public void EscapeDescription_ShouldEscapeSpecialCharacters(string input, string expected)
- {
- // Act
- var result = InvokePrivateStaticMethod("EscapeDescription", input);
+ [Theory]
+ [InlineData("", "")]
+ [InlineData(null, "")]
+ [InlineData("simple text", "simple text")]
+ [InlineData("text with ^ caret", "text with ^^ caret")]
+ [InlineData("text with & ampersand", "text with ^& ampersand")]
+ [InlineData("text with | pipe", "text with ^| pipe")]
+ [InlineData("text with < less", "text with ^< less")]
+ [InlineData("text with > greater", "text with ^> greater")]
+ [InlineData("text with ! exclamation", "text with ^! exclamation")]
+ [InlineData("text with % percent", "text with %% percent")]
+ [InlineData("text with \"quote\"", "text with \\\"quote\\\"")]
+ [InlineData("complex ^&|<>!%\" test", "complex ^^^&^|^<^>^!%%\\\" test")]
+ public void EscapeDescription_ShouldEscapeSpecialCharacters(string input, string expected)
+ {
+ // Act
+ var result = InvokePrivateStaticMethod("EscapeDescription", input);
- // Assert
- Assert.Equal(expected, result);
- }
+ // Assert
+ Assert.Equal(expected, result);
+ }
- [Theory]
- [InlineData(null, "")]
- [InlineData("", "")]
- [InlineData(" ", "")]
- [InlineData("My table description", "--description \"My table description\"")]
- [InlineData("Description with ^ special", "--description \"Description with ^^ special\"")]
- public void GetDescriptionParameter_ShouldFormatDescriptionCorrectly(string input, string expected)
- {
- // Act
- var result = InvokePrivateStaticMethod("GetDescriptionParameter", input);
+ [Theory]
+ [InlineData(null, "")]
+ [InlineData("", "")]
+ [InlineData(" ", "")]
+ [InlineData("My table description", "--description \"My table description\"")]
+ [InlineData("Description with ^ special", "--description \"Description with ^^ special\"")]
+ public void GetDescriptionParameter_ShouldFormatDescriptionCorrectly(string input, string expected)
+ {
+ // Act
+ var result = InvokePrivateStaticMethod("GetDescriptionParameter", input);
- // Assert
- Assert.Equal(expected, result);
- }
+ // Assert
+ Assert.Equal(expected, result);
+ }
- [Fact]
- public void BreaksOn_ShouldReturnTrue_WhenTableHasNoColumns()
- {
- // Arrange
- var table = CreateDatabaseTable(columns: new List());
+ [Fact]
+ public void BreaksOn_ShouldReturnTrue_WhenTableHasNoColumns()
+ {
+ // Arrange
+ var table = CreateDatabaseTable(columns: new List());
- // Act
- var result = InvokePrivateStaticMethod("BreaksOn", table);
+ // Act
+ var result = InvokePrivateStaticMethod("BreaksOn", table);
- // Assert
- Assert.True(result);
- }
+ // Assert
+ Assert.True(result);
+ }
- [Theory]
- [InlineData("hierarchyid")]
- [InlineData("geometry")]
- [InlineData("geography")]
- public void BreaksOn_ShouldReturnTrue_WhenTableHasUnsupportedColumnTypes(string storeType)
+ [Theory]
+ [InlineData("hierarchyid")]
+ [InlineData("geometry")]
+ [InlineData("geography")]
+ public void BreaksOn_ShouldReturnTrue_WhenTableHasUnsupportedColumnTypes(string storeType)
+ {
+ // Arrange
+ var columns = new List
{
- // Arrange
- var columns = new List
- {
- new DatabaseColumn { Name = "Id", StoreType = "int" },
- new DatabaseColumn { Name = "Location", StoreType = storeType }
- };
- var table = CreateDatabaseTable(columns: columns);
+ new() { Name = "Id", StoreType = "int" },
+ new() { Name = "Location", StoreType = storeType }
+ };
+ var table = CreateDatabaseTable(columns: columns);
- // Act
- var result = InvokePrivateStaticMethod("BreaksOn", table);
+ // Act
+ var result = InvokePrivateStaticMethod("BreaksOn", table);
- // Assert
- Assert.True(result);
- }
+ // Assert
+ Assert.True(result);
+ }
- [Fact]
- public void BreaksOn_ShouldReturnFalse_WhenTableHasSupportedColumns()
+ [Fact]
+ public void BreaksOn_ShouldReturnFalse_WhenTableHasSupportedColumns()
+ {
+ // Arrange
+ var columns = new List
{
- // Arrange
- var columns = new List
- {
- new DatabaseColumn { Name = "Id", StoreType = "int" },
- new DatabaseColumn { Name = "Name", StoreType = "nvarchar" },
- new DatabaseColumn { Name = "CreatedDate", StoreType = "datetime" }
- };
- var table = CreateDatabaseTable(columns: columns);
+ new() { Name = "Id", StoreType = "int" },
+ new() { Name = "Name", StoreType = "nvarchar" },
+ new() { Name = "CreatedDate", StoreType = "datetime" }
+ };
+ var table = CreateDatabaseTable(columns: columns);
- // Act
- var result = InvokePrivateStaticMethod("BreaksOn", table);
+ // Act
+ var result = InvokePrivateStaticMethod("BreaksOn", table);
- // Assert
- Assert.False(result);
- }
+ // Assert
+ Assert.False(result);
+ }
- [Fact]
- public void GenerateEntityName_ShouldHandleEdgeCases()
- {
- // Test empty string
- var emptyResult = InvokePrivateStaticMethod("GenerateEntityName", "");
- Assert.Equal(string.Empty, emptyResult);
+ [Fact]
+ public void GenerateEntityName_ShouldHandleEdgeCases()
+ {
+ // Test empty string
+ var emptyResult = InvokePrivateStaticMethod("GenerateEntityName", "");
+ Assert.Equal(string.Empty, emptyResult);
- // Test single character
- var singleChar = InvokePrivateStaticMethod("GenerateEntityName", "a");
- Assert.Equal("A", singleChar);
+ // Test single character
+ var singleChar = InvokePrivateStaticMethod("GenerateEntityName", "a");
+ Assert.Equal("A", singleChar);
- // Test all underscores
- var underscores = InvokePrivateStaticMethod("GenerateEntityName", "___");
- Assert.Equal(string.Empty, underscores);
+ // Test all underscores
+ var underscores = InvokePrivateStaticMethod("GenerateEntityName", "___");
+ Assert.Equal(string.Empty, underscores);
- // Test mixed case with underscores
- var mixed = InvokePrivateStaticMethod("GenerateEntityName", "My_Table_NAME");
- Assert.Equal("MyTableName", mixed);
- }
+ // Test mixed case with underscores
+ var mixed = InvokePrivateStaticMethod("GenerateEntityName", "My_Table_NAME");
+ Assert.Equal("MyTableName", mixed);
+ }
- [Fact]
- public void EscapeDescription_ShouldHandleMultipleSpecialCharacters()
- {
- // Arrange
- var input = "Test ^^ && || << >> !! %% \"\"";
- var expected = "Test ^^^^ ^&^& ^|^| ^<^< ^>^> ^!^! %%%% \\\"\\\"";
+ [Fact]
+ public void EscapeDescription_ShouldHandleMultipleSpecialCharacters()
+ {
+ // Arrange
+ var input = "Test ^^ && || << >> !! %% \"\"";
+ var expected = "Test ^^^^ ^&^& ^|^| ^<^< ^>^> ^!^! %%%% \\\"\\\"";
- // Act
- var result = InvokePrivateStaticMethod("EscapeDescription", input);
+ // Act
+ var result = InvokePrivateStaticMethod("EscapeDescription", input);
- // Assert
- Assert.Equal(expected, result);
- }
+ // Assert
+ Assert.Equal(expected, result);
+ }
- // Helper methods
- private static DatabaseTable CreateDatabaseTable(
- string name = "TestTable",
- string schema = "dbo",
- List columns = null,
- DatabasePrimaryKey primaryKey = null,
- string comment = null)
+ // Helper methods
+ private static DatabaseTable CreateDatabaseTable(
+ string name = "TestTable",
+ string schema = "dbo",
+ List columns = null,
+ DatabasePrimaryKey primaryKey = null,
+ string comment = null)
+ {
+ var table = new DatabaseTable
{
- var table = new DatabaseTable
- {
- Name = name,
- Schema = schema,
- PrimaryKey = primaryKey,
- Comment = comment
- };
+ Name = name,
+ Schema = schema,
+ PrimaryKey = primaryKey,
+ Comment = comment
+ };
- if (columns != null)
+ if (columns != null)
+ {
+ foreach (var column in columns)
{
- foreach (var column in columns)
- {
- table.Columns.Add(column);
- }
+ table.Columns.Add(column);
}
-
- return table;
}
- private static string InvokePrivateStaticMethod(string methodName, string parameter)
- {
- var method = typeof(DabBuilder).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);
- return method != null ? (string)method.Invoke(null, new object[] { parameter }) : string.Empty;
- }
+ return table;
+ }
- private static TResult InvokePrivateStaticMethod(string methodName, TParam parameter)
- {
- var method = typeof(DabBuilder).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);
- return method != null ? (TResult)method.Invoke(null, new object[] { parameter }) : default;
- }
+ private static string InvokePrivateStaticMethod(string methodName, string parameter)
+ {
+ var method = typeof(DabBuilder).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);
+ return method != null ? (string)method.Invoke(null, [parameter]) : string.Empty;
+ }
+
+ private static TResult InvokePrivateStaticMethod(string methodName, TParam parameter)
+ {
+ var method = typeof(DabBuilder).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static);
+ return method != null ? (TResult)method.Invoke(null, [parameter]) : default;
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/Dacpac/DacpacConsolidatorTest.cs b/src/Core/NUnitTestCore/Dacpac/DacpacConsolidatorTest.cs
index 11b0182d9..54dec6b86 100644
--- a/src/Core/NUnitTestCore/Dacpac/DacpacConsolidatorTest.cs
+++ b/src/Core/NUnitTestCore/Dacpac/DacpacConsolidatorTest.cs
@@ -2,26 +2,22 @@
using GOEddie.Dacpac.References;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class DacpacConsolidatorTest
{
- public class DacpacConsolidatorTest
+ [Fact]
+ public void CanConsolidateWithoutReferencesIssue274()
{
- [Fact]
- public void CanConsolidateWithoutReferencesIssue274()
- {
- // Arrange
- var dacPath = TestPath("Chinook.dacpac");
-
- // Act
- var result = DacpacConsolidator.Consolidate(dacPath);
+ // Arrange
+ var dacPath = TestPath("Chinook.dacpac");
- // Assert
- Assert.Equal(dacPath, result);
- }
+ // Act
+ var result = DacpacConsolidator.Consolidate(dacPath);
- private string TestPath(string file)
- {
- return System.IO.Path.Combine(AppContext.BaseDirectory, "Dacpac", file);
- }
+ // Assert
+ Assert.Equal(dacPath, result);
}
-}
+
+ private string TestPath(string file) => System.IO.Path.Combine(AppContext.BaseDirectory, "Dacpac", file);
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/Dacpac/DacpacTest.cs b/src/Core/NUnitTestCore/Dacpac/DacpacTest.cs
index 3820a9104..3a316df81 100644
--- a/src/Core/NUnitTestCore/Dacpac/DacpacTest.cs
+++ b/src/Core/NUnitTestCore/Dacpac/DacpacTest.cs
@@ -6,35 +6,35 @@
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.SqlServer.Dac;
using Microsoft.SqlServer.Dac.Model;
-using Xunit;
using RevEng.Core.Abstractions;
+using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class DacpacTest
{
- public class DacpacTest
+ private const string SqlServerSparseAnnotation = "SqlServer:Sparse";
+ private const string SqlServerIsTemporalAnnotation = "SqlServer:IsTemporal";
+ private readonly string dacpac;
+ private readonly string dacpacDescending;
+ private readonly string dacpacSparse;
+ private readonly string dacpacViews;
+ private readonly string dacpacQuirk;
+
+ public DacpacTest()
{
- private const string SqlServerSparseAnnotation = "SqlServer:Sparse";
- private const string SqlServerIsTemporalAnnotation = "SqlServer:IsTemporal";
- private string dacpac;
- private string dacpacDescending;
- private string dacpacSparse;
- private string dacpacViews;
- private string dacpacQuirk;
-
- public DacpacTest()
- {
- dacpacQuirk = TestPath("TestDb.dacpac");
- dacpac = TestPath("Chinook.dacpac");
- dacpacDescending = TestPath("DescendingIndex.dacpac");
- dacpacSparse = TestPath("SparseColumn.dacpac");
- dacpacViews = TestPath("ViewColumnTypesSqlProj.dacpac");
- #region Here Is the SQL used to create ViewColumnTypesSqlProj.dacpac
- /*
- CREATE VIEW [dbo].[AllTypes]
+ dacpacQuirk = TestPath("TestDb.dacpac");
+ dacpac = TestPath("Chinook.dacpac");
+ dacpacDescending = TestPath("DescendingIndex.dacpac");
+ dacpacSparse = TestPath("SparseColumn.dacpac");
+ dacpacViews = TestPath("ViewColumnTypesSqlProj.dacpac");
+ #region Here Is the SQL used to create ViewColumnTypesSqlProj.dacpac
+ /*
+ CREATE VIEW [dbo].[AllTypes]
AS
SELECT
- CAST( 0x1 AS bit ) col_bit
+CAST( 0x1 AS bit ) col_bit
,CAST( 0x2 AS tinyint ) col_tinyint
,CAST( 0x3 AS smallint ) col_smallint
,CAST( 0x4 AS int ) col_int
@@ -96,599 +96,591 @@ [col_varbinary] [varbinary](1) NULL,
[col_xml] [xml] NULL
)
GO
- */
- #endregion
- }
+ */
+ #endregion
+ }
- [Fact]
- public void CanEnumerateTables()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(new List(), new List());
+ [Fact]
+ public void CanEnumerateTables()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(new List(), new List());
- // Act
- var dbModel = factory.Create(dacpac, options);
+ // Act
+ var dbModel = factory.Create(dacpac, options);
- // Assert
- Assert.Equal(11, dbModel.Tables.Count());
- }
+ // Assert
+ Assert.Equal(11, dbModel.Tables.Count);
+ }
- [Fact]
- public void CanEnumerateViewColumns()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(new List(), new List());
+ [Fact]
+ public void CanEnumerateViewColumns()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(new List(), new List());
- // Act
- var dbModel = factory.Create(dacpacViews, options);
+ // Act
+ var dbModel = factory.Create(dacpacViews, options);
- // Assert
- Assert.Equal(28, dbModel.Tables[0].Columns.Count());
- }
+ // Assert
+ Assert.Equal(28, dbModel.Tables[0].Columns.Count);
+ }
- [Fact]
- public void ViewDescriptionsAreCaptured()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
- var dacpacPath = BuildDacpac(
- """
- CREATE TABLE [dbo].[Base]
- (
- [Id] int NOT NULL CONSTRAINT [PK_Base] PRIMARY KEY,
- [Name] nvarchar(100)
- )
- """,
- """
- CREATE VIEW [dbo].[ViewWithDescription]
- AS
- SELECT [Id], [Name]
- FROM [dbo].[Base]
- """,
- """
- EXEC sp_addextendedproperty
- @name = N'MS_Description',
- @value = N'View description',
- @level0type = N'SCHEMA',
- @level0name = N'dbo',
- @level1type = N'VIEW',
- @level1name = N'ViewWithDescription'
- """,
- """
- EXEC sp_addextendedproperty
- @name = N'MS_Description',
- @value = N'Column description',
- @level0type = N'SCHEMA',
- @level0name = N'dbo',
- @level1type = N'VIEW',
- @level1name = N'ViewWithDescription',
- @level2type = N'COLUMN',
- @level2name = N'Name'
- """);
-
- try
- {
- var dbModel = factory.Create(dacpacPath, options);
- var view = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "ViewWithDescription");
-
- Assert.Equal("View description", view.Comment);
-
- var nameColumn = view.Columns.Single(c => c.Name == "Name");
- Assert.Equal("Column description", nameColumn.Comment);
- }
- finally
- {
- File.Delete(dacpacPath);
- }
+ [Fact]
+ public void ViewDescriptionsAreCaptured()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
+ var dacpacPath = BuildDacpac(
+ """
+ CREATE TABLE [dbo].[Base]
+ (
+ [Id] int NOT NULL CONSTRAINT [PK_Base] PRIMARY KEY,
+ [Name] nvarchar(100)
+ )
+ """,
+ """
+ CREATE VIEW [dbo].[ViewWithDescription]
+ AS
+ SELECT [Id], [Name]
+ FROM [dbo].[Base]
+ """,
+ """
+ EXEC sp_addextendedproperty
+ @name = N'MS_Description',
+ @value = N'View description',
+ @level0type = N'SCHEMA',
+ @level0name = N'dbo',
+ @level1type = N'VIEW',
+ @level1name = N'ViewWithDescription'
+ """,
+ """
+ EXEC sp_addextendedproperty
+ @name = N'MS_Description',
+ @value = N'Column description',
+ @level0type = N'SCHEMA',
+ @level0name = N'dbo',
+ @level1type = N'VIEW',
+ @level1name = N'ViewWithDescription',
+ @level2type = N'COLUMN',
+ @level2name = N'Name'
+ """);
+
+ try
+ {
+ var dbModel = factory.Create(dacpacPath, options);
+ var view = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "ViewWithDescription");
+
+ Assert.Equal("View description", view.Comment);
+
+ var nameColumn = view.Columns.Single(c => c.Name == "Name");
+ Assert.Equal("Column description", nameColumn.Comment);
+ }
+ finally
+ {
+ File.Delete(dacpacPath);
}
+ }
- [Fact]
- public void CanEnumerateSelectedTables()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[Album]", "[dbo].[Artist]", "[dbo].[InvoiceLine]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
-
- // Act
- var dbModel = factory.Create(dacpac, options);
-
- // Assert
- Assert.Equal(3, dbModel.Tables.Count());
- Assert.Equal("Album", dbModel.Tables[0].Name);
- Assert.Single(dbModel.Tables[0].ForeignKeys);
- Assert.Equal(3, dbModel.Tables[0].Columns.Count);
- }
+ [Fact]
+ public void CanEnumerateSelectedTables()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[Album]", "[dbo].[Artist]", "[dbo].[InvoiceLine]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
+
+ // Act
+ var dbModel = factory.Create(dacpac, options);
+
+ // Assert
+ Assert.Equal(3, dbModel.Tables.Count);
+ Assert.Equal("Album", dbModel.Tables[0].Name);
+ Assert.Single(dbModel.Tables[0].ForeignKeys);
+ Assert.Equal(3, dbModel.Tables[0].Columns.Count);
+ }
- [Fact]
- public void CanEnumerateSelectedQuirkObjects()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[FilteredIndexTable]", "[dbo].[DefaultComputedValues]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
-
- // Act
- var dbModel = factory.Create(dacpacQuirk, options);
-
- // Assert
- Assert.Equal(2, dbModel.Tables.Count());
- Assert.Equal("FilteredIndexTable", dbModel.Tables[1].Name);
- Assert.Empty(dbModel.Tables[1].ForeignKeys);
- Assert.Equal(2, dbModel.Tables[1].Columns.Count);
- Assert.Equal("DefaultComputedValues", dbModel.Tables[0].Name);
- Assert.Equal(6, dbModel.Tables[0].Columns.Count);
- }
+ [Fact]
+ public void CanEnumerateSelectedQuirkObjects()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[FilteredIndexTable]", "[dbo].[DefaultComputedValues]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
+
+ // Act
+ var dbModel = factory.Create(dacpacQuirk, options);
+
+ // Assert
+ Assert.Equal(2, dbModel.Tables.Count);
+ Assert.Equal("FilteredIndexTable", dbModel.Tables[1].Name);
+ Assert.Empty(dbModel.Tables[1].ForeignKeys);
+ Assert.Equal(2, dbModel.Tables[1].Columns.Count);
+ Assert.Equal("DefaultComputedValues", dbModel.Tables[0].Name);
+ Assert.Equal(6, dbModel.Tables[0].Columns.Count);
+ }
- [Fact]
- public void CanEnumerateSelectedComputed()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[DefaultComputedValues]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
-
- // Act
- var dbModel = factory.Create(dacpacQuirk, options);
-
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.Equal("DefaultComputedValues", dbModel.Tables[0].Name);
- Assert.Equal(6, dbModel.Tables[0].Columns.Count);
- }
+ [Fact]
+ public void CanEnumerateSelectedComputed()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[DefaultComputedValues]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
+
+ // Act
+ var dbModel = factory.Create(dacpacQuirk, options);
+
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.Equal("DefaultComputedValues", dbModel.Tables[0].Name);
+ Assert.Equal(6, dbModel.Tables[0].Columns.Count);
+ }
- [Fact]
- public void CanEnumerateTypeAlias()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[TypeAlias]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
-
- // Act
- var dbModel = factory.Create(dacpacQuirk, options);
-
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.Equal("TypeAlias", dbModel.Tables[0].Name);
- Assert.Equal(2, dbModel.Tables[0].Columns.Count);
- Assert.Equal("nvarchar(max)", dbModel.Tables[0].Columns[1].StoreType);
- }
+ [Fact]
+ public void CanEnumerateTypeAlias()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[TypeAlias]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
+
+ // Act
+ var dbModel = factory.Create(dacpacQuirk, options);
+
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.Equal("TypeAlias", dbModel.Tables[0].Name);
+ Assert.Equal(2, dbModel.Tables[0].Columns.Count);
+ Assert.Equal("nvarchar(max)", dbModel.Tables[0].Columns[1].StoreType);
+ }
- [Fact]
- public void PreservesDefaultValueSql()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[DefaultValues]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
-
- // Act
- var dbModel = factory.Create(dacpacQuirk, options);
-
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.Equal(
- new[]
- {
- "OrderDate",
- "Freight1",
- "Freight2",
- "Freight3",
- "Freight4",
- "Freight5",
- "Freight6",
- "Freight7",
- "Freight8",
- },
- dbModel.Tables.Single().Columns
- .Where(c => c.DefaultValueSql != null)
- .Select(c => c.Name));
- }
+ [Fact]
+ public void PreservesDefaultValueSql()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[DefaultValues]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
+
+ // Act
+ var dbModel = factory.Create(dacpacQuirk, options);
+
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.Equal(
+ [
+ "OrderDate",
+ "Freight1",
+ "Freight2",
+ "Freight3",
+ "Freight4",
+ "Freight5",
+ "Freight6",
+ "Freight7",
+ "Freight8",
+ ],
+ dbModel.Tables.Single().Columns
+ .Where(c => c.DefaultValueSql != null)
+ .Select(c => c.Name));
+ }
- [Fact]
- public void PreservesNumericClrDefaultConstraintSql()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[DefaultValues]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
-
- var dbModel = factory.Create(dacpacQuirk, options);
- var table = dbModel.Tables.Single(t => t.Name == "DefaultValues");
-
- var freight2 = table.Columns.Single(c => c.Name == "Freight2");
- var freight3 = table.Columns.Single(c => c.Name == "Freight3");
- var freight4 = table.Columns.Single(c => c.Name == "Freight4");
- var freight5 = table.Columns.Single(c => c.Name == "Freight5");
- var freight6 = table.Columns.Single(c => c.Name == "Freight6");
-
- Assert.Equal("0", freight2.DefaultValueSql);
- Assert.Equal("0.0", freight3.DefaultValueSql);
- Assert.Equal("0.0", freight4.DefaultValueSql);
- Assert.Equal("0.0", freight5.DefaultValueSql);
- Assert.Equal("0.0", freight6.DefaultValueSql);
- }
+ [Fact]
+ public void PreservesNumericClrDefaultConstraintSql()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[DefaultValues]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
+
+ var dbModel = factory.Create(dacpacQuirk, options);
+ var table = dbModel.Tables.Single(t => t.Name == "DefaultValues");
+
+ var freight2 = table.Columns.Single(c => c.Name == "Freight2");
+ var freight3 = table.Columns.Single(c => c.Name == "Freight3");
+ var freight4 = table.Columns.Single(c => c.Name == "Freight4");
+ var freight5 = table.Columns.Single(c => c.Name == "Freight5");
+ var freight6 = table.Columns.Single(c => c.Name == "Freight6");
+
+ Assert.Equal("0", freight2.DefaultValueSql);
+ Assert.Equal("0.0", freight3.DefaultValueSql);
+ Assert.Equal("0.0", freight4.DefaultValueSql);
+ Assert.Equal("0.0", freight5.DefaultValueSql);
+ Assert.Equal("0.0", freight6.DefaultValueSql);
+ }
- [Fact]
- public void CanCaptureSparseColumnAnnotation()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var tables = new List { "[dbo].[Department]" };
- var options = new DatabaseModelFactoryOptions(tables, new List());
+ [Fact]
+ public void CanCaptureSparseColumnAnnotation()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var tables = new List { "[dbo].[Department]" };
+ var options = new DatabaseModelFactoryOptions(tables, new List());
- var dbModel = factory.Create(dacpacSparse, options);
- var importToken = dbModel.Tables.Single().Columns.Single(c => c.Name == "ImportToken");
+ var dbModel = factory.Create(dacpacSparse, options);
+ var importToken = dbModel.Tables.Single().Columns.Single(c => c.Name == "ImportToken");
- Assert.Single(dbModel.Tables);
- Assert.NotNull(importToken.FindAnnotation(SqlServerSparseAnnotation));
- }
+ Assert.Single(dbModel.Tables);
+ Assert.NotNull(importToken.FindAnnotation(SqlServerSparseAnnotation));
+ }
- [Fact]
- public void CanBuildAW2014()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Fact]
+ public void CanBuildAW2014()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- // Act
- var dbModel = factory.Create(TestPath("AdventureWorks2014.dacpac"), options);
+ // Act
+ var dbModel = factory.Create(TestPath("AdventureWorks2014.dacpac"), options);
- // Assert
- Assert.Equal(91, dbModel.Tables.Count());
- }
+ // Assert
+ Assert.Equal(91, dbModel.Tables.Count);
+ }
- [Fact]
- public void Issue208ComputedConstraint()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Fact]
+ public void Issue208ComputedConstraint()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- // Act
- var dbModel = factory.Create(TestPath("Issue208.dacpac"), options);
+ // Act
+ var dbModel = factory.Create(TestPath("Issue208.dacpac"), options);
- // Assert
- Assert.Single(dbModel.Tables);
- }
+ // Assert
+ Assert.Single(dbModel.Tables);
+ }
- [Fact]
- public void Issue210ComputedConstraintIsFK()
- {
- // Arrange
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Fact]
+ public void Issue210ComputedConstraintIsFK()
+ {
+ // Arrange
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- // Act
- var dbModel = factory.Create(TestPath("Issue210.dacpac"), options);
+ // Act
+ var dbModel = factory.Create(TestPath("Issue210.dacpac"), options);
- // Assert
- Assert.Equal(2, dbModel.Tables.Count());
- }
+ // Assert
+ Assert.Equal(2, dbModel.Tables.Count);
+ }
- [Fact]
- public void Issue1262ConsiderSchemaArgument()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List() { "mat" });
+ [Fact]
+ public void Issue1262ConsiderSchemaArgument()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List() { "mat" });
- // Act
- var dbModel = factory.Create(TestPath("Issue1262.dacpac"), options);
+ // Act
+ var dbModel = factory.Create(TestPath("Issue1262.dacpac"), options);
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.Equal("mat", dbModel.Tables.Single().Schema);
- }
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.Equal("mat", dbModel.Tables.Single().Schema);
+ }
- [Fact]
- public void Issue1262BehaviourWithoutSchemaArgument()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Fact]
+ public void Issue1262BehaviourWithoutSchemaArgument()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- // Act
- var dbModel = factory.Create(TestPath("Issue1262.dacpac"), options);
+ // Act
+ var dbModel = factory.Create(TestPath("Issue1262.dacpac"), options);
- // Assert
- Assert.Equal(2, dbModel.Tables.Count());
- Assert.Equal(1, dbModel.Tables.Count(x => x.Schema == "mat"));
- Assert.Equal(1, dbModel.Tables.Count(x => x.Schema == "mat2"));
- }
+ // Assert
+ Assert.Equal(2, dbModel.Tables.Count);
+ Assert.Equal(1, dbModel.Tables.Count(x => x.Schema == "mat"));
+ Assert.Equal(1, dbModel.Tables.Count(x => x.Schema == "mat2"));
+ }
- [Fact]
- public void Issue3341PersistedComputedForeignKeys()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Fact]
+ public void Issue3341PersistedComputedForeignKeys()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- var dbModel = factory.Create(TestPath("Issue3341.dacpac"), options);
+ var dbModel = factory.Create(TestPath("Issue3341.dacpac"), options);
- Assert.Equal(3, dbModel.Tables.Count());
+ Assert.Equal(3, dbModel.Tables.Count);
- var bin = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "Bin");
- var inventoryNodeTypeCode = bin.Columns.Single(c => c.Name == "InventoryNodeTypeCode");
+ var bin = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "Bin");
+ var inventoryNodeTypeCode = bin.Columns.Single(c => c.Name == "InventoryNodeTypeCode");
- Assert.Equal("tinyint", inventoryNodeTypeCode.StoreType);
- Assert.Contains("CONVERT", inventoryNodeTypeCode.ComputedColumnSql);
- Assert.Contains("8", inventoryNodeTypeCode.ComputedColumnSql);
- Assert.True(inventoryNodeTypeCode.IsStored);
- Assert.False(inventoryNodeTypeCode.IsNullable);
- Assert.Equal(2, bin.ForeignKeys.Count);
- Assert.Contains(bin.ForeignKeys, fk => fk.Columns.Any(c => c.Name == "InventoryNodeTypeCode"));
- Assert.Contains(bin.ForeignKeys, fk => fk.Columns.Count == 2);
- }
+ Assert.Equal("tinyint", inventoryNodeTypeCode.StoreType);
+ Assert.Contains("CONVERT", inventoryNodeTypeCode.ComputedColumnSql);
+ Assert.Contains("8", inventoryNodeTypeCode.ComputedColumnSql);
+ Assert.True(inventoryNodeTypeCode.IsStored);
+ Assert.False(inventoryNodeTypeCode.IsNullable);
+ Assert.Equal(2, bin.ForeignKeys.Count);
+ Assert.Contains(bin.ForeignKeys, fk => fk.Columns.Any(c => c.Name == "InventoryNodeTypeCode"));
+ Assert.Contains(bin.ForeignKeys, fk => fk.Columns.Count == 2);
+ }
+
+ [Theory]
+ [InlineData("ISNULL(CONVERT(bit, CASE [processing_status_id] WHEN 0 THEN 1 END), 0)", false)]
+ [InlineData("COALESCE(CONVERT(bit, CASE [processing_status_id] WHEN 0 THEN 1 END), 0)", false)]
+ [InlineData("COALESCE(CONVERT(bit, CASE [processing_status_id] WHEN 0 THEN 1 END), NULL)", true)]
+ public void Issue3451ComputedColumnNullabilityCanBeInferredFromExpression(string expression, bool expectedNullable)
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
+ var dacpacPath = BuildDacpac(
+ $"""
+ CREATE TABLE [dbo].[processing_status]
+ (
+ [processing_status_id] int NOT NULL
+ CONSTRAINT [pk_processing_status] PRIMARY KEY,
+ [is_status_created] AS {expression}
+ );
+ """);
- [Theory]
- [InlineData("ISNULL(CONVERT(bit, CASE [processing_status_id] WHEN 0 THEN 1 END), 0)", false)]
- [InlineData("COALESCE(CONVERT(bit, CASE [processing_status_id] WHEN 0 THEN 1 END), 0)", false)]
- [InlineData("COALESCE(CONVERT(bit, CASE [processing_status_id] WHEN 0 THEN 1 END), NULL)", true)]
- public void Issue3451ComputedColumnNullabilityCanBeInferredFromExpression(string expression, bool expectedNullable)
+ try
{
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
- var dacpacPath = BuildDacpac(
- $"""
- CREATE TABLE [dbo].[processing_status]
- (
- [processing_status_id] int NOT NULL
- CONSTRAINT [pk_processing_status] PRIMARY KEY,
- [is_status_created] AS {expression}
- );
- """);
-
- try
- {
- var dbModel = factory.Create(dacpacPath, options);
- var table = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "processing_status");
- var column = table.Columns.Single(c => c.Name == "is_status_created");
-
- Assert.False(column.IsStored);
- Assert.Equal("bit", column.StoreType);
- Assert.Equal(expectedNullable, column.IsNullable);
- }
- finally
- {
- File.Delete(dacpacPath);
- }
- }
+ var dbModel = factory.Create(dacpacPath, options);
+ var table = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "processing_status");
+ var column = table.Columns.Single(c => c.Name == "is_status_created");
- [Fact]
- public void VectorColumnIsScaffoldedWithDimension()
+ Assert.False(column.IsStored);
+ Assert.Equal("bit", column.StoreType);
+ Assert.Equal(expectedNullable, column.IsNullable);
+ }
+ finally
{
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
- var dacpacPath = BuildDacpac(
- SqlServerVersion.Sql170,
- """
- CREATE TABLE [dbo].[SdrSearch]
- (
- [SdrId] INT NOT NULL PRIMARY KEY,
- [Embedding] VECTOR (1536) NULL
- );
- """);
-
- try
- {
- var dbModel = factory.Create(dacpacPath, options);
- var table = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "SdrSearch");
-
- Assert.Equal(2, table.Columns.Count());
-
- var embedding = table.Columns.Single(c => c.Name == "Embedding");
-
- Assert.Equal("vector(1536)", embedding.StoreType);
- Assert.True(embedding.IsNullable);
- }
- finally
- {
- File.Delete(dacpacPath);
- }
+ File.Delete(dacpacPath);
}
+ }
+
+ [Fact]
+ public void VectorColumnIsScaffoldedWithDimension()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
+ var dacpacPath = BuildDacpac(
+ SqlServerVersion.Sql170,
+ """
+ CREATE TABLE [dbo].[SdrSearch]
+ (
+ [SdrId] INT NOT NULL PRIMARY KEY,
+ [Embedding] VECTOR (1536) NULL
+ );
+ """);
- [Fact]
- public void MultipleTriggersFromDacpacAreCaptured()
+ try
{
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ var dbModel = factory.Create(dacpacPath, options);
+ var table = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "SdrSearch");
- var dbModel = factory.Create(TestPath("AdventureWorks2014.dacpac"), options);
- var table = dbModel.Tables.Single(t => t.Schema == "Production" && t.Name == "WorkOrder");
+ Assert.Equal(2, table.Columns.Count);
- Assert.Equal(
- new[] { "iWorkOrder", "uWorkOrder" }.OrderBy(x => x),
- table.Triggers.Select(t => t.Name).OrderBy(x => x));
- }
+ var embedding = table.Columns.Single(c => c.Name == "Embedding");
- [Theory]
- [InlineData(null, null)]
- [InlineData("N'The location''s address'", "The location's address")]
- [InlineData("'The location''s address'", "The location's address")]
- [InlineData("N'Plain text'", "Plain text")]
- [InlineData("'Plain text'", "Plain text")]
- [InlineData("Plain text", "Plain text")]
- [InlineData("N''''", "'")]
- public void FixExtendedPropertyValueNormalizesSqlStringLiterals(string input, string expected)
+ Assert.Equal("vector(1536)", embedding.StoreType);
+ Assert.True(embedding.IsNullable);
+ }
+ finally
{
- var result = SqlServerDacpacDatabaseModelFactory.FixExtendedPropertyValue(input);
-
- Assert.Equal(expected, result);
+ File.Delete(dacpacPath);
}
+ }
- [Fact]
- public void DescendingIndexFromDacpacIsCaptured()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Fact]
+ public void MultipleTriggersFromDacpacAreCaptured()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- var dbModel = factory.Create(dacpacDescending, options);
- var table = dbModel.Tables.Single(t => t.Schema == "support" && t.Name == "MessageFault");
- var index = table.Indexes.Single(i => i.Name == "IX_support_MessageFault_MessageFaultStatusCode_FaultedTimestamp");
+ var dbModel = factory.Create(TestPath("AdventureWorks2014.dacpac"), options);
+ var table = dbModel.Tables.Single(t => t.Schema == "Production" && t.Name == "WorkOrder");
- Assert.Equal(new[] { "MessageFaultStatusCode", "FaultedTimestamp" }, index.Columns.Select(c => c.Name));
- Assert.Equal(new[] { false, true }, index.IsDescending);
- }
+ Assert.Equal(
+ new[] { "iWorkOrder", "uWorkOrder" }.OrderBy(x => x),
+ table.Triggers.Select(t => t.Name).OrderBy(x => x));
+ }
- [Fact]
- public void ExplicitDefaultConstraintNameFromDacpacIsCaptured()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ [Theory]
+ [InlineData(null, null)]
+ [InlineData("N'The location''s address'", "The location's address")]
+ [InlineData("'The location''s address'", "The location's address")]
+ [InlineData("N'Plain text'", "Plain text")]
+ [InlineData("'Plain text'", "Plain text")]
+ [InlineData("Plain text", "Plain text")]
+ [InlineData("N''''", "'")]
+ public void FixExtendedPropertyValueNormalizesSqlStringLiterals(string input, string expected)
+ {
+ var result = SqlServerDacpacDatabaseModelFactory.FixExtendedPropertyValue(input);
- var dbModel = factory.Create(TestPath("AdventureWorks2014.dacpac"), options);
- var table = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "AWBuildVersion");
- var column = table.Columns.Single(c => c.Name == "ModifiedDate");
+ Assert.Equal(expected, result);
+ }
- Assert.NotNull(column.DefaultValueSql);
- Assert.Equal("DF_AWBuildVersion_ModifiedDate", column["Relational:DefaultConstraintName"]);
- }
+ [Fact]
+ public void DescendingIndexFromDacpacIsCaptured()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- [Fact]
- public void Issue2263SprocWithCte()
- {
- var factory = new SqlServerDacpacStoredProcedureModelFactory(
- new SqlServerDacpacDatabaseModelFactoryOptions{ MergeDacpacs = false });
- var options = new ModuleModelFactoryOptions { FullModel = true, Modules = new List() };
+ var dbModel = factory.Create(dacpacDescending, options);
+ var table = dbModel.Tables.Single(t => t.Schema == "support" && t.Name == "MessageFault");
+ var index = table.Indexes.Single(i => i.Name == "IX_support_MessageFault_MessageFaultStatusCode_FaultedTimestamp");
- // Act
- var dbModel = factory.Create(TestPath("abc.dacpac"), options);
+ Assert.Equal(["MessageFaultStatusCode", "FaultedTimestamp"], index.Columns.Select(c => c.Name));
+ Assert.Equal([false, true], index.IsDescending);
+ }
- // Assert
- Assert.Single(dbModel.Routines);
- Assert.Empty(dbModel.Errors);
+ [Fact]
+ public void ExplicitDefaultConstraintNameFromDacpacIsCaptured()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- var routine = dbModel.Routines.Single();
+ var dbModel = factory.Create(TestPath("AdventureWorks2014.dacpac"), options);
+ var table = dbModel.Tables.Single(t => t.Schema == "dbo" && t.Name == "AWBuildVersion");
+ var column = table.Columns.Single(c => c.Name == "ModifiedDate");
- Assert.Equal("dbo", routine.Schema);
- Assert.Equal("USP_Error", routine.Name);
- Assert.True(routine.HasValidResultSet);
- Assert.Single(routine.Results);
- Assert.Single(routine.Results[0]);
+ Assert.NotNull(column.DefaultValueSql);
+ Assert.Equal("DF_AWBuildVersion_ModifiedDate", column["Relational:DefaultConstraintName"]);
+ }
- var resultColumn = routine.Results[0].Single();
+ [Fact]
+ public void Issue2263SprocWithCte()
+ {
+ var factory = new SqlServerDacpacStoredProcedureModelFactory(
+ new SqlServerDacpacDatabaseModelFactoryOptions { MergeDacpacs = false });
+ var options = new ModuleModelFactoryOptions { FullModel = true, Modules = new List() };
- Assert.Equal("TestColumn", resultColumn.Name);
- Assert.Equal("int", resultColumn.StoreType);
- Assert.False(resultColumn.Nullable);
- }
+ // Act
+ var dbModel = factory.Create(TestPath("abc.dacpac"), options);
- [Fact]
- public void TemporalSupport()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ // Assert
+ Assert.Single(dbModel.Routines);
+ Assert.Empty(dbModel.Errors);
- // Act
- var dbModel = factory.Create(TestPath("Temporal.dacpac"), options);
+ var routine = dbModel.Routines.Single();
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.NotNull(dbModel.Tables.Single().FindAnnotation(SqlServerIsTemporalAnnotation));
- }
+ Assert.Equal("dbo", routine.Schema);
+ Assert.Equal("USP_Error", routine.Name);
+ Assert.True(routine.HasValidResultSet);
+ Assert.Single(routine.Results);
+ Assert.Single(routine.Results[0]);
- [Fact]
- public void VectorSupport()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ var resultColumn = routine.Results[0].Single();
- // Act
- var dbModel = factory.Create(TestPath("Vector.dacpac"), options);
+ Assert.Equal("TestColumn", resultColumn.Name);
+ Assert.Equal("int", resultColumn.StoreType);
+ Assert.False(resultColumn.Nullable);
+ }
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.Equal("vector(1536)", dbModel.Tables.Single().Columns.Single(c => c.Name == "Embedding").StoreType);
- }
+ [Fact]
+ public void TemporalSupport()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- [Fact]
- public void AzureVectorSupport()
- {
- var factory = new SqlServerDacpacDatabaseModelFactory();
- var options = new DatabaseModelFactoryOptions(null, new List());
+ // Act
+ var dbModel = factory.Create(TestPath("Temporal.dacpac"), options);
- // Act
- var dbModel = factory.Create(TestPath("VectorAzure.dacpac"), options);
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.NotNull(dbModel.Tables.Single().FindAnnotation(SqlServerIsTemporalAnnotation));
+ }
- // Assert
- Assert.Single(dbModel.Tables);
- Assert.Equal("vector(1536)", dbModel.Tables.Single().Columns.Single(c => c.Name == "Embedding").StoreType);
- }
+ [Fact]
+ public void VectorSupport()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- [Fact]
- public void Issue2322TvpSprocParameters()
- {
- var factory = new SqlServerDacpacStoredProcedureModelFactory(
- new SqlServerDacpacDatabaseModelFactoryOptions{ MergeDacpacs = false });
- var options = new ModuleModelFactoryOptions { FullModel = true, Modules = new List() };
-
- // Act
- var dbModel = factory.Create(TestPath("TvpParams.dacpac"), options);
-
- // Assert
- Assert.Single(dbModel.Routines);
- Assert.Equal(2, dbModel.Routines[0].Parameters.Count);
- Assert.Equal("NumberIDList", dbModel.Routines[0].Parameters[0].TypeName);
- Assert.Equal("Constant", dbModel.Routines[0].Parameters[0].TypeSchemaName);
- Assert.Equal("structured", dbModel.Routines[0].Parameters[0].StoreType);
- Assert.NotNull(dbModel.Routines[0].Parameters[0].TvpColumns);
- Assert.True(dbModel.Routines[0].Parameters[0].TvpColumns.Count > 0);
-
- // Debug - print TVP columns
- System.Console.WriteLine($"TVP Columns count: {dbModel.Routines[0].Parameters[0].TvpColumns.Count}");
- foreach (var col in dbModel.Routines[0].Parameters[0].TvpColumns)
- {
- System.Console.WriteLine($" Column: {col.Name}, Type: {col.StoreType}");
- }
- }
+ // Act
+ var dbModel = factory.Create(TestPath("Vector.dacpac"), options);
- [Fact]
- public void DacpacDiscoverMultipleResultSetsOptionIsRespected()
- {
- var factory = new SqlServerDacpacStoredProcedureModelFactory(
- new SqlServerDacpacDatabaseModelFactoryOptions { MergeDacpacs = false });
- var module = new List { "[dbo].[uspSearchCandidateResumes]" };
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.Equal("vector(1536)", dbModel.Tables.Single().Columns.Single(c => c.Name == "Embedding").StoreType);
+ }
- var singleResultModel = factory.Create(
- TestPath("AdventureWorks2014.dacpac"),
- new ModuleModelFactoryOptions { FullModel = true, Modules = module, DiscoverMultipleResultSets = false });
+ [Fact]
+ public void AzureVectorSupport()
+ {
+ var factory = new SqlServerDacpacDatabaseModelFactory();
+ var options = new DatabaseModelFactoryOptions(null, new List());
- var multipleResultModel = factory.Create(
- TestPath("AdventureWorks2014.dacpac"),
- new ModuleModelFactoryOptions { FullModel = true, Modules = module, DiscoverMultipleResultSets = true });
+ // Act
+ var dbModel = factory.Create(TestPath("VectorAzure.dacpac"), options);
- var singleResultRoutine = singleResultModel.Routines.Single();
- var multipleResultRoutine = multipleResultModel.Routines.Single();
+ // Assert
+ Assert.Single(dbModel.Tables);
+ Assert.Equal("vector(1536)", dbModel.Tables.Single().Columns.Single(c => c.Name == "Embedding").StoreType);
+ }
- Assert.Single(singleResultRoutine.Results);
- Assert.Equal(4, multipleResultRoutine.Results.Count);
+ [Fact]
+ public void Issue2322TvpSprocParameters()
+ {
+ var factory = new SqlServerDacpacStoredProcedureModelFactory(
+ new SqlServerDacpacDatabaseModelFactoryOptions { MergeDacpacs = false });
+ var options = new ModuleModelFactoryOptions { FullModel = true, Modules = new List() };
- Assert.Equal(new[] { "JobCandidateID", "RANK" }, multipleResultRoutine.Results[0].Select(c => c.Name));
- Assert.Equal(new[] { "JobCandidateID", "RANK" }, multipleResultRoutine.Results[1].Select(c => c.Name));
- }
+ // Act
+ var dbModel = factory.Create(TestPath("TvpParams.dacpac"), options);
+
+ // Assert
+ Assert.Single(dbModel.Routines);
+ Assert.Equal(2, dbModel.Routines[0].Parameters.Count);
+ Assert.Equal("NumberIDList", dbModel.Routines[0].Parameters[0].TypeName);
+ Assert.Equal("Constant", dbModel.Routines[0].Parameters[0].TypeSchemaName);
+ Assert.Equal("structured", dbModel.Routines[0].Parameters[0].StoreType);
+ Assert.NotNull(dbModel.Routines[0].Parameters[0].TvpColumns);
+ Assert.True(dbModel.Routines[0].Parameters[0].TvpColumns.Count > 0);
- private static string BuildDacpac(params string[] sqlScripts)
+ // Debug - print TVP columns
+ Console.WriteLine($"TVP Columns count: {dbModel.Routines[0].Parameters[0].TvpColumns.Count}");
+ foreach (var col in dbModel.Routines[0].Parameters[0].TvpColumns)
{
- return BuildDacpac(SqlServerVersion.Sql160, sqlScripts);
+ Console.WriteLine($" Column: {col.Name}, Type: {col.StoreType}");
}
+ }
- private static string BuildDacpac(SqlServerVersion version, params string[] sqlScripts)
- {
- var path = Path.Combine(Path.GetTempPath(), $"dacpac-test-{Guid.NewGuid():N}.dacpac");
+ [Fact]
+ public void DacpacDiscoverMultipleResultSetsOptionIsRespected()
+ {
+ var factory = new SqlServerDacpacStoredProcedureModelFactory(
+ new SqlServerDacpacDatabaseModelFactoryOptions { MergeDacpacs = false });
+ var module = new List { "[dbo].[uspSearchCandidateResumes]" };
- using var model = new TSqlModel(version, new TSqlModelOptions());
- foreach (var sql in sqlScripts)
- {
- model.AddObjects(sql);
- }
+ var singleResultModel = factory.Create(
+ TestPath("AdventureWorks2014.dacpac"),
+ new ModuleModelFactoryOptions { FullModel = true, Modules = module, DiscoverMultipleResultSets = false });
- DacPackageExtensions.BuildPackage(path, model, new PackageMetadata { Name = "test" });
+ var multipleResultModel = factory.Create(
+ TestPath("AdventureWorks2014.dacpac"),
+ new ModuleModelFactoryOptions { FullModel = true, Modules = module, DiscoverMultipleResultSets = true });
- return path;
- }
+ var singleResultRoutine = singleResultModel.Routines.Single();
+ var multipleResultRoutine = multipleResultModel.Routines.Single();
- private string TestPath(string file)
+ Assert.Single(singleResultRoutine.Results);
+ Assert.Equal(4, multipleResultRoutine.Results.Count);
+
+ Assert.Equal(["JobCandidateID", "RANK"], multipleResultRoutine.Results[0].Select(c => c.Name));
+ Assert.Equal(["JobCandidateID", "RANK"], multipleResultRoutine.Results[1].Select(c => c.Name));
+ }
+
+ private static string BuildDacpac(params string[] sqlScripts) => BuildDacpac(SqlServerVersion.Sql160, sqlScripts);
+
+ private static string BuildDacpac(SqlServerVersion version, params string[] sqlScripts)
+ {
+ var path = Path.Combine(Path.GetTempPath(), $"dacpac-test-{Guid.NewGuid():N}.dacpac");
+
+ using var model = new TSqlModel(version, new TSqlModelOptions());
+ foreach (var sql in sqlScripts)
{
- return Path.Combine(AppContext.BaseDirectory, "Dacpac", file);
+ model.AddObjects(sql);
}
+
+ DacPackageExtensions.BuildPackage(path, model, new PackageMetadata { Name = "test" });
+
+ return path;
}
-}
+
+ private string TestPath(string file) => Path.Combine(AppContext.BaseDirectory, "Dacpac", file);
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/Dgml/DgmlTest.cs b/src/Core/NUnitTestCore/Dgml/DgmlTest.cs
index 668906c4b..25cd845f1 100644
--- a/src/Core/NUnitTestCore/Dgml/DgmlTest.cs
+++ b/src/Core/NUnitTestCore/Dgml/DgmlTest.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -6,228 +6,217 @@
using Dgml;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class DgmlTest
{
- public class DgmlTest
- {
- private string template;
-
- public DgmlTest()
- {
- template = GetTemplate();
- }
-
- [Fact]
- public void ParseDebugViewSample1()
- {
- // Arrange
- var debugView = ReadAllLines("Aw2014Person.txt");
-
- // Act
- var result = DebugViewParser.Parse(debugView, "Test");
-
- // Assert
- Assert.Equal(110, result.Nodes.Count);
- Assert.Equal(122, result.Links.Count);
- Assert.Equal(2, result.Links.Count(n => n.Contains("IsUnique=\"True\"")));
- }
-
- [Fact]
- public void ParseDebugViewFkBug()
- {
- // Arrange
- var debugView = ReadAllLines("Northwind.txt");
-
- // Act
- var result = DebugViewParser.Parse(debugView, "Test");
-
- // Assert
- Assert.Equal(129, result.Nodes.Count);
- Assert.Equal(141, result.Links.Count);
- Assert.Equal(0, result.Links.Count(n => n.Contains("IsUnique=\"True\"")));
- }
-
- [Fact]
- public void ParseDebugViewMultiColFk()
- {
- // Arrange
- var debugView = ReadAllLines("Pfizer.txt");
-
- // Act
- var result = DebugViewParser.Parse(debugView, "Test");
-
- // Assert
- Assert.Equal(160, result.Nodes.Count);
- Assert.Equal(172, result.Links.Count);
- }
-
- [Fact]
- public void ParseDebugViewIssue604()
- {
- // Arrange
- var debugView = ReadAllLines("Issue604.txt");
-
- // Act
- var result = DebugViewParser.Parse(debugView, "Test");
-
- // Assert
- Assert.Equal(124, result.Nodes.Count);
- Assert.Equal(150, result.Links.Count);
- }
-
- [Fact]
- public void BuildChinook()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("ChinookContext.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Chinook.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildSample1()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Aw2014Person.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Aw2014Person.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildNorthwind()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Northwind.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"northwind.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildPfizer()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Pfizer.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"pfizer.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildBNoFk()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("NoFk.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "nofk.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildSingleNav()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("SingleNav.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"singlenav.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildSamurai()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Samurai.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Samurai.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildIssue604()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Issue604.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Issue604.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildIssue687()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Issue687.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Issue687.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildIdentity()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("Identity.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Identity.dgml"), result, Encoding.UTF8);
- }
-
- [Fact]
- public void BuildLongView50()
- {
- // Act
- var result = DgmlBuilder.Build(ReadAllText("longview50.txt"), "test", template);
-
- // Assert
- Assert.NotNull(result);
-
- File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"LongView50.dgml"), result, Encoding.UTF8);
- }
-
- private static string GetTemplate()
- {
- var resourceName = "NUnitTestCore.template.dgml";
-
- using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
- {
- using (var reader = new StreamReader(stream ?? throw new InvalidOperationException()))
- {
- return reader.ReadToEnd();
- }
- }
- }
-
- private string[] ReadAllLines(string file)
- {
- return File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "Dgml", file));
- }
-
- private string ReadAllText(string file)
- {
- return File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Dgml", file));
- }
- }
-}
+ private readonly string template;
+
+ public DgmlTest()
+ {
+ template = GetTemplate();
+ }
+
+ [Fact]
+ public void ParseDebugViewSample1()
+ {
+ // Arrange
+ var debugView = ReadAllLines("Aw2014Person.txt");
+
+ // Act
+ var result = DebugViewParser.Parse(debugView, "Test");
+
+ // Assert
+ Assert.Equal(110, result.Nodes.Count);
+ Assert.Equal(122, result.Links.Count);
+ Assert.Equal(2, result.Links.Count(n => n.Contains("IsUnique=\"True\"")));
+ }
+
+ [Fact]
+ public void ParseDebugViewFkBug()
+ {
+ // Arrange
+ var debugView = ReadAllLines("Northwind.txt");
+
+ // Act
+ var result = DebugViewParser.Parse(debugView, "Test");
+
+ // Assert
+ Assert.Equal(129, result.Nodes.Count);
+ Assert.Equal(141, result.Links.Count);
+ Assert.Equal(0, result.Links.Count(n => n.Contains("IsUnique=\"True\"")));
+ }
+
+ [Fact]
+ public void ParseDebugViewMultiColFk()
+ {
+ // Arrange
+ var debugView = ReadAllLines("Pfizer.txt");
+
+ // Act
+ var result = DebugViewParser.Parse(debugView, "Test");
+
+ // Assert
+ Assert.Equal(160, result.Nodes.Count);
+ Assert.Equal(172, result.Links.Count);
+ }
+
+ [Fact]
+ public void ParseDebugViewIssue604()
+ {
+ // Arrange
+ var debugView = ReadAllLines("Issue604.txt");
+
+ // Act
+ var result = DebugViewParser.Parse(debugView, "Test");
+
+ // Assert
+ Assert.Equal(124, result.Nodes.Count);
+ Assert.Equal(150, result.Links.Count);
+ }
+
+ [Fact]
+ public void BuildChinook()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("ChinookContext.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Chinook.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildSample1()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Aw2014Person.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Aw2014Person.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildNorthwind()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Northwind.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"northwind.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildPfizer()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Pfizer.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"pfizer.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildBNoFk()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("NoFk.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "nofk.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildSingleNav()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("SingleNav.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"singlenav.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildSamurai()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Samurai.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Samurai.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildIssue604()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Issue604.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Issue604.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildIssue687()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Issue687.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Issue687.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildIdentity()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("Identity.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"Identity.dgml"), result, Encoding.UTF8);
+ }
+
+ [Fact]
+ public void BuildLongView50()
+ {
+ // Act
+ var result = DgmlBuilder.Build(ReadAllText("longview50.txt"), "test", template);
+
+ // Assert
+ Assert.NotNull(result);
+
+ File.WriteAllText(Path.Combine(AppContext.BaseDirectory, @"LongView50.dgml"), result, Encoding.UTF8);
+ }
+
+ private static string GetTemplate()
+ {
+ var resourceName = "NUnitTestCore.template.dgml";
+
+ using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
+ using var reader = new StreamReader(stream ?? throw new InvalidOperationException());
+ return reader.ReadToEnd();
+ }
+
+ private string[] ReadAllLines(string file) => File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "Dgml", file));
+
+ private string ReadAllText(string file) => File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Dgml", file));
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/PostgresIndexExclusionTests.cs b/src/Core/NUnitTestCore/PostgresIndexExclusionTests.cs
index e57c88db2..c715dd23a 100644
--- a/src/Core/NUnitTestCore/PostgresIndexExclusionTests.cs
+++ b/src/Core/NUnitTestCore/PostgresIndexExclusionTests.cs
@@ -8,73 +8,72 @@
using RevEng.Core;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class PostgresIndexExclusionTests
{
- public class PostgresIndexExclusionTests
- {
- private const string FilteredIndex = "uq_child_active_parent";
+ private const string FilteredIndex = "uq_child_active_parent";
- [Theory]
- [InlineData(false)]
- [InlineData(true)]
- public void PartialUniqueIndexIsExcludedBeforeRelationshipInference(bool excludeIndex)
+ [Theory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void PartialUniqueIndexIsExcludedBeforeRelationshipInference(bool excludeIndex)
+ {
+ var options = new ReverseEngineerCommandOptions
{
- var options = new ReverseEngineerCommandOptions
+ DatabaseType = DatabaseType.Npgsql,
+ UseInflector = true,
+ Tables = new List
{
- DatabaseType = DatabaseType.Npgsql,
- UseInflector = true,
- Tables = new List
- {
- new SerializationTableModel("public.child", ObjectType.Table, null, excludeIndex ? new[] { FilteredIndex } : null),
- },
- };
- using var services = new ServiceCollection()
- .AddLogging()
- .AddEfpt(options, new List(), new List(), new List())
- .BuildServiceProvider();
+ new("public.child", ObjectType.Table, null, excludeIndex ? new[] { FilteredIndex } : null),
+ },
+ };
+ using var services = new ServiceCollection()
+ .AddLogging()
+ .AddEfpt(options, new List(), new List(), new List())
+ .BuildServiceProvider();
- var model = services.GetRequiredService()
- .Create(CreateDatabase(), new ModelReverseEngineerOptions());
- var child = model.GetEntityTypes().Single(e => e.GetTableName() == "child");
- var foreignKey = Assert.Single(child.GetForeignKeys());
+ var model = services.GetRequiredService()
+ .Create(CreateDatabase(), new ModelReverseEngineerOptions());
+ var child = model.GetEntityTypes().Single(e => e.GetTableName() == "child");
+ var foreignKey = Assert.Single(child.GetForeignKeys());
- // Without an explicit exclusion, preserve the existing upstream inference behavior.
- Assert.Equal(!excludeIndex, foreignKey.IsUnique);
- Assert.Equal(excludeIndex, foreignKey.PrincipalToDependent.IsCollection);
- Assert.Equal(!excludeIndex, child.GetIndexes().Any(i => i.GetDatabaseName() == FilteredIndex));
- }
+ // Without an explicit exclusion, preserve the existing upstream inference behavior.
+ Assert.Equal(!excludeIndex, foreignKey.IsUnique);
+ Assert.Equal(excludeIndex, foreignKey.PrincipalToDependent.IsCollection);
+ Assert.Equal(!excludeIndex, child.GetIndexes().Any(i => i.GetDatabaseName() == FilteredIndex));
+ }
- private static DatabaseModel CreateDatabase()
- {
- var database = new DatabaseModel { DatabaseName = "IndexExclusionTests", DefaultSchema = "public" };
- var parent = new DatabaseTable { Database = database, Name = "parent", Schema = "public" };
- var child = new DatabaseTable { Database = database, Name = "child", Schema = "public" };
- database.Tables.Add(parent);
- database.Tables.Add(child);
+ private static DatabaseModel CreateDatabase()
+ {
+ var database = new DatabaseModel { DatabaseName = "IndexExclusionTests", DefaultSchema = "public" };
+ var parent = new DatabaseTable { Database = database, Name = "parent", Schema = "public" };
+ var child = new DatabaseTable { Database = database, Name = "child", Schema = "public" };
+ database.Tables.Add(parent);
+ database.Tables.Add(child);
- var parentId = new DatabaseColumn { Table = parent, Name = "id", StoreType = "integer" };
- parent.Columns.Add(parentId);
- parent.PrimaryKey = new DatabasePrimaryKey { Table = parent, Name = "pk_parent" };
- parent.PrimaryKey.Columns.Add(parentId);
+ var parentId = new DatabaseColumn { Table = parent, Name = "id", StoreType = "integer" };
+ parent.Columns.Add(parentId);
+ parent.PrimaryKey = new DatabasePrimaryKey { Table = parent, Name = "pk_parent" };
+ parent.PrimaryKey.Columns.Add(parentId);
- var childId = new DatabaseColumn { Table = child, Name = "id", StoreType = "integer" };
- var childParentId = new DatabaseColumn { Table = child, Name = "parent_id", StoreType = "integer" };
- child.Columns.Add(childId);
- child.Columns.Add(childParentId);
- child.Columns.Add(new DatabaseColumn { Table = child, Name = "is_active", StoreType = "boolean" });
- child.PrimaryKey = new DatabasePrimaryKey { Table = child, Name = "pk_child" };
- child.PrimaryKey.Columns.Add(childId);
+ var childId = new DatabaseColumn { Table = child, Name = "id", StoreType = "integer" };
+ var childParentId = new DatabaseColumn { Table = child, Name = "parent_id", StoreType = "integer" };
+ child.Columns.Add(childId);
+ child.Columns.Add(childParentId);
+ child.Columns.Add(new DatabaseColumn { Table = child, Name = "is_active", StoreType = "boolean" });
+ child.PrimaryKey = new DatabasePrimaryKey { Table = child, Name = "pk_child" };
+ child.PrimaryKey.Columns.Add(childId);
- var foreignKey = new DatabaseForeignKey { Table = child, PrincipalTable = parent, Name = "fk_child_parent" };
- foreignKey.Columns.Add(childParentId);
- foreignKey.PrincipalColumns.Add(parentId);
- child.ForeignKeys.Add(foreignKey);
+ var foreignKey = new DatabaseForeignKey { Table = child, PrincipalTable = parent, Name = "fk_child_parent" };
+ foreignKey.Columns.Add(childParentId);
+ foreignKey.PrincipalColumns.Add(parentId);
+ child.ForeignKeys.Add(foreignKey);
- var index = new DatabaseIndex { Table = child, Name = FilteredIndex, IsUnique = true, Filter = "is_active = true" };
- index.Columns.Add(childParentId);
- child.Indexes.Add(index);
+ var index = new DatabaseIndex { Table = child, Name = FilteredIndex, IsUnique = true, Filter = "is_active = true" };
+ index.Columns.Add(childParentId);
+ child.Indexes.Add(index);
- return database;
- }
+ return database;
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/PostgresTypeExtensionsTest.cs b/src/Core/NUnitTestCore/PostgresTypeExtensionsTest.cs
index ca2930145..908578dcb 100644
--- a/src/Core/NUnitTestCore/PostgresTypeExtensionsTest.cs
+++ b/src/Core/NUnitTestCore/PostgresTypeExtensionsTest.cs
@@ -1,19 +1,17 @@
-using System;
using RevEng.Core.Routines.Extensions;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+public class PostgresTypeExtensionsTest
{
- public class PostgresTypeExtensionsTest
+ [Theory]
+ [InlineData(true)]
+ [InlineData(false)]
+ public void CanMapCitextToString(bool isNullable)
{
- [Theory]
- [InlineData(true)]
- [InlineData(false)]
- public void CanMapCitextToString(bool isNullable)
- {
- var result = PostgresNpgsqlTypeExtensions.GetClrType("citext", isNullable, "test");
+ var result = PostgresNpgsqlTypeExtensions.GetClrType("citext", isNullable, "test");
- Assert.Equal(typeof(string), result);
- }
+ Assert.Equal(typeof(string), result);
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/NUnitTestCore/ProcedureScaffolderTests.cs b/src/Core/NUnitTestCore/ProcedureScaffolderTests.cs
index db79e9e53..19f6b6e7f 100644
--- a/src/Core/NUnitTestCore/ProcedureScaffolderTests.cs
+++ b/src/Core/NUnitTestCore/ProcedureScaffolderTests.cs
@@ -2,7 +2,6 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Microsoft.EntityFrameworkCore.Design;
-using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Design.Internal;
using Microsoft.Extensions.DependencyInjection;
using RevEng.Core.Abstractions;
@@ -11,153 +10,149 @@
using RevEng.Core.Routines.Procedures;
using Xunit;
-namespace UnitTests
+namespace UnitTests;
+
+[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test method names")]
+public class ProcedureScaffolderTests
{
- [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test method names")]
- public class ProcedureScaffolderTests
+ [Fact]
+ public void ScaffoldModel_WhenHasValidResultSetFalseAndGenerateEmptyResultTypeFalse_ExcludesRoutineFromOutput()
{
- [Fact]
- public void ScaffoldModel_WhenHasValidResultSetFalseAndGenerateEmptyResultTypeFalse_ExcludesRoutineFromOutput()
+ var scaffolder = CreateScaffolder();
+ var model = new RoutineModel
{
- var scaffolder = CreateScaffolder();
- var model = new RoutineModel
- {
- Routines = new List { CreateProcedureWithInvalidResultSet(generateEmptyResultType: false) },
- Errors = new List(),
- };
- var errors = new List();
- var schemas = new List();
+ Routines = new List { CreateProcedureWithInvalidResultSet(generateEmptyResultType: false) },
+ Errors = new List(),
+ };
+ var errors = new List();
+ var schemas = new List();
- var result = scaffolder.ScaffoldModel(model, CreateScaffolderOptions(), schemas, ref errors);
+ var result = scaffolder.ScaffoldModel(model, CreateScaffolderOptions(), schemas, ref errors);
- Assert.DoesNotContain(result.AdditionalFiles, f => f.Path.Contains("TestProcedureResult"));
- Assert.DoesNotContain("TestProcedure", result.ContextFile.Code);
- }
+ Assert.DoesNotContain(result.AdditionalFiles, f => f.Path.Contains("TestProcedureResult"));
+ Assert.DoesNotContain("TestProcedure", result.ContextFile.Code);
+ }
- [Fact]
- public void ScaffoldModel_WhenHasValidResultSetFalseAndGenerateEmptyResultTypeTrue_IncludesRoutineInOutput()
+ [Fact]
+ public void ScaffoldModel_WhenHasValidResultSetFalseAndGenerateEmptyResultTypeTrue_IncludesRoutineInOutput()
+ {
+ var scaffolder = CreateScaffolder();
+ var model = new RoutineModel
{
- var scaffolder = CreateScaffolder();
- var model = new RoutineModel
- {
- Routines = new List { CreateProcedureWithInvalidResultSet(generateEmptyResultType: true) },
- Errors = new List(),
- };
- var errors = new List();
- var schemas = new List