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

Fix missing mapping and add test #2774

Merged
merged 1 commit into from
Jan 9, 2025
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
5 changes: 2 additions & 3 deletions src/Core/NUnitTestCore/ClassicHumanizerPluralizerTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;
using RevEng.Core;

namespace UnitTests
Expand All @@ -12,7 +11,7 @@ public void SingularizeUserData()
var sut = new HumanizerPluralizer();
var result = sut.Singularize("UserData");

ClassicAssert.AreEqual("UserDatum", result);
Assert.AreEqual("UserDatum", result);
}

[Test]
Expand All @@ -21,7 +20,7 @@ public void PluralizeUserStatus()
var sut = new HumanizerPluralizer();
var result = sut.Pluralize("UserStatus");

ClassicAssert.AreEqual("UserStatuses", result);
Assert.AreEqual("UserStatuses", result);
}
}
}
72 changes: 72 additions & 0 deletions src/Core/NUnitTestCore/CliConfigMapperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using AutoFixture.NUnit3;
using FluentAssertions;
using NUnit.Framework;
using RevEng.Common;
//using NUnit.Framework.Legacy;
using RevEng.Common.Cli;
using RevEng.Common.Cli.Configuration;

namespace UnitTests
{
[TestFixture]
public class CliConfigMapperTest
{
[Test, AutoData]
public void CanGetOptions(CliConfig config)
{
var options = CliConfigMapper.ToOptions(config, "C:\temp", "C:\tempo");

options.CodeGenerationMode.Should().Be(CodeGenerationMode.EFCore8);
options.ConnectionString.Should().Be(null);
options.ContextClassName.Should().Be(config.Names.DbContextName);
options.ContextNamespace.Should().Be(config.Names.DbContextNamespace);
options.DatabaseType.Should().Be(DatabaseType.Undefined);
options.Dacpac.Should().Be(null);
options.DefaultDacpacSchema.Should().Be(null);
options.FilterSchemas.Should().Be(false);
options.IncludeConnectionString.Should().Be(config.CodeGeneration.EnableOnConfiguring);
options.InstallNuGetPackage.Should().Be(false);
options.ModelNamespace.Should().Be(config.Names.ModelNamespace);
options.OptionsPath.Should().Be(null);
options.OutputContextPath.Should().Be(config.FileLayout.OutputDbContextPath);
options.OutputPath.Should().Be(config.FileLayout.OutputPath);
options.ProjectPath.Should().Be("C:\temp");
options.ProjectRootNamespace.Should().Be(config.Names.RootNamespace);
options.PreserveCasingWithRegex.Should().Be(config.Replacements.PreserveCasingWithRegex);
options.SelectedHandlebarsLanguage.Should().Be(0);
options.SelectedToBeGenerated.Should().Be(0);
options.Tables.Count.Should().BeGreaterThanOrEqualTo(config.Tables.Count);
options.UncountableWords.Should().NotBeEmpty();
options.UseBoolPropertiesWithoutDefaultSql.Should().Be(config.CodeGeneration.RemoveDefaultSqlFromBoolProperties);
options.UseDatabaseNames.Should().Be(config.CodeGeneration.UseDatabaseNames);
options.UseDatabaseNamesForRoutines.Should().Be(config.CodeGeneration.UseDatabaseNamesForRoutines);
options.UseDateOnlyTimeOnly.Should().Be(config.TypeMappings.UseDateOnlyTimeOnly);
options.UseDbContextSplitting.Should().Be(config.FileLayout.SplitDbContextPreview);
options.UseFluentApiOnly.Should().Be(!config.CodeGeneration.UseDataAnnotations);
options.UseHandleBars.Should().Be(false);
options.UseHierarchyId.Should().Be(config.TypeMappings.UseHierarchyId);
options.UseInflector.Should().Be(config.CodeGeneration.UseInflector);
options.UseLegacyPluralizer.Should().Be(config.CodeGeneration.UseLegacyInflector);
options.UseManyToManyEntity.Should().Be(config.CodeGeneration.UseManyToManyEntity);
options.UseNodaTime.Should().Be(config.TypeMappings.UseNodaTime);
options.UseNoDefaultConstructor.Should().Be(false);
options.UseNoNavigations.Should().Be(config.CodeGeneration.UseNoNavigationsPreview);
options.UseNoObjectFilter.Should().Be(false);
options.UseNullableReferences.Should().Be(config.CodeGeneration.UseNullableReferenceTypes);
options.UseSchemaFolders.Should().Be(config.FileLayout.UseSchemaFoldersPreview);
options.UseSchemaNamespaces.Should().Be(config.FileLayout.UseSchemaNamespacesPreview);
options.UseSpatial.Should().Be(config.TypeMappings.UseSpatial);
options.UseT4.Should().Be(config.CodeGeneration.UseT4);
options.UseT4Split.Should().Be(config.CodeGeneration.UseT4Split);

options.GetType().GetProperties().Length.Should().Be(50);

config.GetType().GetProperties().Length.Should().Be(10);
config.Names.GetType().GetProperties().Length.Should().Be(4);
config.CodeGeneration.GetType().GetProperties().Length.Should().Be(23);
config.FileLayout.GetType().GetProperties().Length.Should().Be(5);
config.Replacements.GetType().GetProperties().Length.Should().Be(2);
config.TypeMappings.GetType().GetProperties().Length.Should().Be(4);
}
}
}
82 changes: 41 additions & 41 deletions src/Core/NUnitTestCore/CliObjectListTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using NUnit.Framework;
using NUnit.Framework.Legacy;
//using NUnit.Framework.Legacy;
using RevEng.Common;
using RevEng.Common.Cli;
using RevEng.Common.Cli.Configuration;
Expand Down Expand Up @@ -34,9 +34,9 @@ public void CanGetConfig()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(6, result.Count);
Assert.AreEqual(6, result.Count);
}

[Test]
Expand All @@ -49,9 +49,9 @@ public void CanUseGobalFilter()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.IsEmpty(result);
Assert.IsEmpty(result);
}

[Test]
Expand All @@ -63,9 +63,9 @@ public void CanAddStartsWithFilter()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(2, result.Count);
Assert.AreEqual(2, result.Count);
}

[Test]
Expand All @@ -77,9 +77,9 @@ public void CanAddStartsWithFilter_2()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(5, result.Count);
Assert.AreEqual(5, result.Count);
}

[Test]
Expand All @@ -93,9 +93,9 @@ public void CanAddStartsWithFilterAndExplicitInclude()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(3, result.Count);
Assert.AreEqual(3, result.Count);
}

[Test]
Expand All @@ -109,9 +109,9 @@ public void MultipleExclusionWildcardExcludes()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(3, result.Count);
Assert.AreEqual(3, result.Count);
}

[Test]
Expand All @@ -123,9 +123,9 @@ public void CanAddEndsWithFilter()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(4, result.Count);
Assert.AreEqual(4, result.Count);
}

[Test]
Expand All @@ -139,9 +139,9 @@ public void CanAddEndsWithFilterAndExplicitInclude()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(4, result.Count);
Assert.AreEqual(4, result.Count);
}

[Test]
Expand All @@ -153,9 +153,9 @@ public void CanAddContainsFilter()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(4, result.Count);
Assert.AreEqual(4, result.Count);
}

[Test]
Expand All @@ -169,9 +169,9 @@ public void CanAddContainsFilterAndExplicitInclude()

var result = CliConfigMapper.BuildObjectList(config);

ClassicAssert.NotNull(result);
Assert.NotNull(result);

ClassicAssert.AreEqual(5, result.Count);
Assert.AreEqual(5, result.Count);
}

[Test]
Expand All @@ -190,17 +190,17 @@ public void TryGetCliConfigWithExistingFileReturnsExpectedConfig()
out CliConfig resultConfig,
out List<string> warnings);

ClassicAssert.True(fetchedConfigSuccess);
Assert.True(fetchedConfigSuccess);

ClassicAssert.NotNull(resultConfig);
Assert.NotNull(resultConfig);

ClassicAssert.True(config.Tables.Count == resultConfig.Tables.Count);
Assert.True(config.Tables.Count == resultConfig.Tables.Count);

for (var i = 0; i < config.Tables.Count; i++)
{
ClassicAssert.AreEqual(config.Tables[i].Name, resultConfig.Tables[i].Name);
ClassicAssert.AreEqual(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
ClassicAssert.AreEqual(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
Assert.AreEqual(config.Tables[i].Name, resultConfig.Tables[i].Name);
Assert.AreEqual(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
Assert.AreEqual(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
}
}
finally
Expand Down Expand Up @@ -248,26 +248,26 @@ public void TryGetCliConfigWithExcludedColumnsReturns()
out CliConfig resultConfig,
out List<string> warnings);

ClassicAssert.True(fetchedConfigSuccess);
Assert.True(fetchedConfigSuccess);

ClassicAssert.NotNull(resultConfig);
Assert.NotNull(resultConfig);

ClassicAssert.True(config.Tables.Count == resultConfig.Tables.Count);
Assert.True(config.Tables.Count == resultConfig.Tables.Count);

for (var i = 0; i < config.Tables.Count; i++)
{
ClassicAssert.AreEqual(config.Tables[i].Name, resultConfig.Tables[i].Name);
ClassicAssert.AreEqual(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
ClassicAssert.AreEqual(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
Assert.AreEqual(config.Tables[i].Name, resultConfig.Tables[i].Name);
Assert.AreEqual(config.Tables[i].Exclude, resultConfig.Tables[i].Exclude);
Assert.AreEqual(config.Tables[i].ExclusionWildcard, resultConfig.Tables[i].ExclusionWildcard);
}

ClassicAssert.True(warnings.Count == 4);
ClassicAssert.True(resultConfig.Tables[0].ExcludedColumns.Count == 3);
ClassicAssert.True(resultConfig.Tables[0].ExcludedColumns[0] == "UserId");
ClassicAssert.True(resultConfig.Views[0].ExcludedColumns.Count == 3);
ClassicAssert.True(resultConfig.Views[0].ExcludedColumns[0] == "UserId");
ClassicAssert.IsNull(resultConfig.Functions[0].ExcludedColumns);
ClassicAssert.IsNull(resultConfig.StoredProcedures[0].ExcludedColumns);
Assert.True(warnings.Count == 4);
Assert.True(resultConfig.Tables[0].ExcludedColumns.Count == 3);
Assert.True(resultConfig.Tables[0].ExcludedColumns[0] == "UserId");
Assert.True(resultConfig.Views[0].ExcludedColumns.Count == 3);
Assert.True(resultConfig.Views[0].ExcludedColumns[0] == "UserId");
Assert.IsNull(resultConfig.Functions[0].ExcludedColumns);
Assert.IsNull(resultConfig.StoredProcedures[0].ExcludedColumns);
}
finally
{
Expand Down
11 changes: 5 additions & 6 deletions src/Core/NUnitTestCore/ConnectionStringResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using MySqlConnector;
using Npgsql;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using Oracle.ManagedDataAccess.Client;
using RevEng.Core;

Expand All @@ -24,7 +23,7 @@ public void CanRedactSql()

var result = resolver.Redact();

ClassicAssert.AreEqual("data source=.", result);
Assert.AreEqual("data source=.", result);
}


Expand All @@ -40,7 +39,7 @@ public void CanRedactNpgsql()

var result = resolver.Redact();

ClassicAssert.AreEqual("host=localhost", result);
Assert.AreEqual("host=localhost", result);
}

[Test]
Expand All @@ -55,7 +54,7 @@ public void CanRedactMysql()

var result = resolver.Redact();

ClassicAssert.AreEqual("server=localhost", result);
Assert.AreEqual("server=localhost", result);
}

[Test]
Expand All @@ -70,7 +69,7 @@ public void CanRedactOracle()

var result = resolver.Redact();

ClassicAssert.AreEqual("data source=localhost", result);
Assert.AreEqual("data source=localhost", result);
}

[Test]
Expand All @@ -85,7 +84,7 @@ public void CanRedactFirebird()

var result = resolver.Redact();

ClassicAssert.AreEqual("data source=localhost", result);
Assert.AreEqual("data source=localhost", result);
}
}
}
5 changes: 2 additions & 3 deletions src/Core/NUnitTestCore/CustomHumanizerPluralizerTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Humanizer.Inflections;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using RevEng.Core;

namespace UnitTests
Expand Down Expand Up @@ -42,7 +41,7 @@ private static void Pluralize(string word)
var sut = new HumanizerPluralizer();
var result = sut.Pluralize(word);

ClassicAssert.True(word == result);
Assert.True(word == result);
}

private static void Singularize(string word)
Expand All @@ -51,7 +50,7 @@ private static void Singularize(string word)
var sut = new HumanizerPluralizer();
var result = sut.Singularize(word);

ClassicAssert.True(word == result);
Assert.True(word == result);
}
}
}
5 changes: 2 additions & 3 deletions src/Core/NUnitTestCore/Dacpac/DacpacConsolidatorTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using GOEddie.Dacpac.References;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace UnitTests
{
Expand All @@ -15,7 +14,7 @@ public void CanConsolidate_Issue_274()
var result = DacpacConsolidator.Consolidate(@"C:\Users\Erik\Downloads\CompositeDatabase\CompositeDatabase\CompositeDatabase\bin\Debug\CompositeDatabase.dacpac");

// Assert
ClassicAssert.IsTrue(result.Contains("\\efpt-"));
Assert.IsTrue(result.Contains("\\efpt-"));
}

[Test]
Expand All @@ -28,7 +27,7 @@ public void CanConsolidate_Without_References_Issue_274()
var result = DacpacConsolidator.Consolidate(dacPath);

// Assert
ClassicAssert.AreEqual(result, dacPath);
Assert.AreEqual(result, dacPath);
}

private string TestPath(string file)
Expand Down
Loading