Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add features to support dataverse edmx files, improve performance and maintainability #29

Merged
merged 17 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/pull-request-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ jobs:
- uses: actions/checkout@v3
- name: Build
run: dotnet build --configuration Release EDMXTrimmer
- name: Test
run: dotnet test --logger:nunit --configuration Release EDMXTrimmer
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
with:
files: '**/TestResults/*.xml'
comment_mode: 'off'
- name: Publish
run: dotnet publish --configuration Release EDMXTrimmer --output zip
run: dotnet publish --configuration Release EDMXTrimmer/EDMXTrimmer --output zip
- name: Upload EDMXTrimmer.zip
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 6 additions & 0 deletions EDMXTrimmer/EDMXTrimmer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.28803.202
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDMXTrimmer", "EDMXTrimmer\EDMXTrimmer.csproj", "{CEE5566E-5FFF-46E4-BC78-166980691951}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDMXTrimmerTest", "EDMXTrimmerTest\EDMXTrimmerTest.csproj", "{D555AE09-A8C1-4368-AA62-67AE517230B4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{CEE5566E-5FFF-46E4-BC78-166980691951}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEE5566E-5FFF-46E4-BC78-166980691951}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEE5566E-5FFF-46E4-BC78-166980691951}.Release|Any CPU.Build.0 = Release|Any CPU
{D555AE09-A8C1-4368-AA62-67AE517230B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D555AE09-A8C1-4368-AA62-67AE517230B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D555AE09-A8C1-4368-AA62-67AE517230B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D555AE09-A8C1-4368-AA62-67AE517230B4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
324 changes: 247 additions & 77 deletions EDMXTrimmer/EDMXTrimmer/EdmxTrimmer.cs

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion EDMXTrimmer/EDMXTrimmer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ namespace EDMXTrimmer
{
public class Options
{
private const string EntitiesToKeepName = "entitiestokeep";
private const string EntitiesToExcludeName = "entitiestoexclude";

[Option(
Required = true,
HelpText = "EDMX source file")]
public string EdmxFile { get; set; }

[Option(
longName: EntitiesToKeepName,
Required = false,
HelpText = "Enter the public name & collection name. All values to be separated with commas. Supports ? and * wildcards.",
Separator = ',')]
public IEnumerable<string> EntitiesToKeep { get; set; }

[Option(
longName: EntitiesToExcludeName,
Required = false,
HelpText = "Enter the public name & collection name. All values to be separated with commas. Supports ? and * wildcards.",
Separator = ',')]
Expand Down Expand Up @@ -54,6 +59,23 @@ public class Options
Default = false)]
public bool RemoveActionImports { get; set; }

[Option(
Required = false,
HelpText = "Function imports are removed from the EDMX file",
Default = false)]
public bool RemoveFunctionImports { get; set; }

[Option(
Required = false,
HelpText = "ComplexType nodes are removed from the EDMX file",
Default = false)]
public bool RemoveComplexTypes { get; set; }

[Option(
Required = false,
HelpText = $"Enter action names to keep, works with \"{EntitiesToKeepName}\" and \"{EntitiesToExcludeName}\" options. All values to be separated with commas. Supports ? and * wildcards.",
Separator = ',')]
public IReadOnlyCollection<string> ActionsToKeep { get; set; }
}
class Program
{
Expand All @@ -72,7 +94,11 @@ static void Main(string[] args)
entitiesToExclude:opt.EntitiesToExclude.ToList(),
entitiesAreRegularExpressions:opt.EntitiesAreRegularExpressions,
removePrimaryAnnotations:opt.RemovePrimaryAnnotations,
removeActionImports:opt.RemoveActionImports);
removeActionImports:opt.RemoveActionImports) {
RemoveComplexTypesFlag = opt.RemoveComplexTypes,
RemoveFunctionImportsFlag = opt.RemoveFunctionImports,
ActionsToInclude = opt.ActionsToKeep
};

trimmer.AnalyzeFile();
}
Expand Down
31 changes: 31 additions & 0 deletions EDMXTrimmer/EDMXTrimmerTest/EDMXTrimmerTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="NunitXml.TestLogger" Version="3.1.15" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EDMXTrimmer\EDMXTrimmer.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="TripPin.xml" >
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
176 changes: 176 additions & 0 deletions EDMXTrimmer/EDMXTrimmerTest/EdmxTrimmerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using EDMXTrimmer;

namespace EDMXTrimmer.Tests
{
public class EdmxTrimmerTests
{
private const string TestEdmxFile = "TripPin.xml";
private const string TestOutputFile = "TripPin-Trimmed.xml";

[SetUp]
public void Setup()
{

}

[TearDown]
public void TearDown()
{
// Delete the test EDMX file and output file
File.Delete(TestOutputFile);
}

[Test]
public void TestEdmxTrimmer()
{
// Arrange
var entitiesToKeep = new List<string> { "Photos", "People" };
var entitiesToExclude = new List<string> { "People" };
var edmxTrimmer = new EdmxTrimmer(TestEdmxFile, TestOutputFile, true, entitiesToKeep, entitiesToExclude);

// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.Multiple(() =>
{
Assert.That(trimmedEdmx, Does.Contain("<EntitySet Name=\"Photos\""));
Assert.That(trimmedEdmx, Does.Contain("<EntityType Name=\"Photo\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntitySet Name=\"People\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntityType Name=\"Person\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntitySet Name=\"Airlines\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntityType Name=\"Airline\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntitySet Name=\"Airports\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntityType Name=\"Airport\""));
});
}

[Test]
public void TestEdmxTrimmer_NoEntitiesToKeepOrExclude()
{
// Arrange
var edmxTrimmer = new EdmxTrimmer(TestEdmxFile, TestOutputFile);

// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.That(trimmedEdmx, Is.EqualTo(File.ReadAllText(TestEdmxFile)));
}

[Test]
public void TestEdmxTrimmer_RemovePrimaryAnnotations()
{
// Arrange
var edmxTrimmer = new EdmxTrimmer(TestEdmxFile, TestOutputFile, removePrimaryAnnotations: true);

// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.That(trimmedEdmx, Does.Not.Contain("Primary"));
}

[Test]
public void TestEdmxTrimmer_RemoveActionImports()
{
// Arrange
var edmxTrimmer = new EdmxTrimmer(TestEdmxFile, TestOutputFile, removeActionImports: true);

// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.That(trimmedEdmx, Does.Not.Contain("ActionImport"));
}

[Test]
public void TestEdmxTrimmer_RemoveFunctionImports()
{
// Arrange
var edmxTrimmer = new EdmxTrimmer(TestEdmxFile, TestOutputFile)
{
RemoveFunctionImportsFlag = true
};


// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.That(trimmedEdmx, Does.Not.Contain("FunctionImport"));
}

[Test]
public void TestEdmxTrimmer_RemoveComplexTypes()
{
// Arrange
var edmxTrimmer = new EdmxTrimmer(TestEdmxFile, TestOutputFile)
{
RemoveComplexTypesFlag = true
};

// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.That(trimmedEdmx, Does.Not.Contain("ComplexType"));
}

[Test]
public void TestEdmxTrimmer_EntitiesAreRegularExpressions()
{
// Arrange

var entitiesToKeep = new List<string> { @"\b\w+s\b" }; // Keep entities that end with "s"
var entitiesToExclude = new List<string> { @"P\w+" }; // Exclude entities that start with "P"
var edmxTrimmer = new EdmxTrimmer(
TestEdmxFile,
TestOutputFile,
entitiesAreRegularExpressions: true,
entitiesToKeep: entitiesToKeep,
entitiesToExclude: entitiesToExclude);

// Act
edmxTrimmer.AnalyzeFile();

// Assert
Assert.That(File.Exists(TestOutputFile), Is.True);

var trimmedEdmx = File.ReadAllText(TestOutputFile);
Assert.Multiple(() =>
{
Assert.That(trimmedEdmx, Does.Not.Contain("<EntitySet Name=\"Photos\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntityType Name=\"Photo\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntitySet Name=\"People\""));
Assert.That(trimmedEdmx, Does.Not.Contain("<EntityType Name=\"Person\""));
Assert.That(trimmedEdmx, Does.Contain("<EntitySet Name=\"Airlines\""));
Assert.That(trimmedEdmx, Does.Contain("<EntityType Name=\"Airline\""));
Assert.That(trimmedEdmx, Does.Contain("<EntitySet Name=\"Airports\""));
Assert.That(trimmedEdmx, Does.Contain("<EntityType Name=\"Airport\""));
});
}
}
}
1 change: 1 addition & 0 deletions EDMXTrimmer/EDMXTrimmerTest/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
Loading