Skip to content

Commit

Permalink
tweak #551 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Mar 23, 2024
1 parent 0e558a5 commit b1ffe17
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
10 changes: 2 additions & 8 deletions src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using EntityFrameworkCore.Generator.Extensions;
using EntityFrameworkCore.Generator.Metadata.Generation;
Expand Down Expand Up @@ -366,14 +366,8 @@ private DatabaseModel GetDatabaseModel(IDatabaseModelFactory factory)

var database = Options.Database;

//do not evaluate connection string resolving (cfr. { or } in password => crash)
var shouldEvaluate = Options.Variables.ShouldEvaluate;
Options.Variables.ShouldEvaluate = false;

var connectionString = ResolveConnectionString(database);

Options.Variables.ShouldEvaluate = shouldEvaluate;

var options = new DatabaseModelFactoryOptions(database.Tables, database.Schemas);

return factory.Create(connectionString, options);
Expand Down Expand Up @@ -473,4 +467,4 @@ private void ConfigureOracleServices(IServiceCollection services)
var designTimeServices = new Oracle.EntityFrameworkCore.Design.Internal.OracleDesignTimeServices();
designTimeServices.ConfigureDesignTimeServices(services);
}
}
}
18 changes: 3 additions & 15 deletions src/EntityFrameworkCore.Generator.Core/Options/DatabaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,23 @@ public string Name
/// <value>
/// The connection string for reverse engineering the database
/// </value>
public string ConnectionString
{
get => GetProperty();
set => SetProperty(value);
}
public string ConnectionString { get; set; }

/// <summary>
/// Gets or sets the name of the connection in the user secret file.
/// </summary>
/// <value>
/// The name of the connection.
/// </value>
public string ConnectionName
{
get => GetProperty();
set => SetProperty(value);
}
public string ConnectionName { get; set; }

/// <summary>
/// Gets or sets the user secrets identifier. A user secrets ID is unique value used to store and identify a collection of secret configuration values.
/// </summary>
/// <value>
/// The user secrets identifier.
/// </value>
public string UserSecretsId
{
get => GetProperty();
set => SetProperty(value);
}
public string UserSecretsId { get; set; }


/// <summary>
Expand Down
44 changes: 25 additions & 19 deletions test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System.IO;

using EntityFrameworkCore.Generator.Options;

using FluentAssertions;

using FluentCommand.SqlServer.Tests;

using Microsoft.Extensions.Logging.Abstractions;
using System.IO;

using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -40,39 +45,40 @@ public void Generate_Should_Work_For_Password_With_CurlyBrace()

result.Should().BeTrue();
}
[Fact]
public void GenerateSpatial()
{
var generatorOptions = new GeneratorOptions();
generatorOptions.Database.ConnectionString = Database.ConnectionString;

var generator = new CodeGenerator(NullLoggerFactory.Instance);
var result = generator.Generate(generatorOptions);
[Fact]
public void GenerateSpatial()
{
var generatorOptions = new GeneratorOptions();
generatorOptions.Database.ConnectionString = Database.ConnectionString;

var generator = new CodeGenerator(NullLoggerFactory.Instance);
var result = generator.Generate(generatorOptions);

result.Should().BeTrue();
result.Should().BeTrue();

const string spatialTableName = "CitiesSpatial";
const string spatialTableName = "CitiesSpatial";

var citiesSpatialEntityFile = Path.Combine(generatorOptions.Data.Entity.Directory, spatialTableName + ".cs");
var citiesSpatialMappingFile = Path.Combine(generatorOptions.Data.Mapping.Directory, spatialTableName + "Map.cs");
var citiesSpatialEntityFile = Path.Combine(generatorOptions.Data.Entity.Directory, spatialTableName + ".cs");
var citiesSpatialMappingFile = Path.Combine(generatorOptions.Data.Mapping.Directory, spatialTableName + "Map.cs");

var citiesSpatialEntityContent = File.ReadAllText(citiesSpatialEntityFile);
var citiesSpatialMappingContent = File.ReadAllText(citiesSpatialMappingFile);
var citiesSpatialEntityContent = File.ReadAllText(citiesSpatialEntityFile);
var citiesSpatialMappingContent = File.ReadAllText(citiesSpatialMappingFile);

citiesSpatialEntityContent.Contains("public NetTopologySuite.Geometries.Geometry GeometryField { get; set; }").Should().BeTrue();
citiesSpatialEntityContent.Contains("public NetTopologySuite.Geometries.Geometry GeographyField { get; set; }").Should().BeTrue();
citiesSpatialEntityContent.Contains("public NetTopologySuite.Geometries.Geometry GeometryField { get; set; }").Should().BeTrue();
citiesSpatialEntityContent.Contains("public NetTopologySuite.Geometries.Geometry GeographyField { get; set; }").Should().BeTrue();

citiesSpatialMappingContent.Contains("builder.Property(t => t.GeometryField)" + System.Environment.NewLine +
citiesSpatialMappingContent.Contains("builder.Property(t => t.GeometryField)" + System.Environment.NewLine +
" .IsRequired()" + System.Environment.NewLine +
" .HasColumnName(\"GeometryField\")" + System.Environment.NewLine +
" .HasColumnType(\"geometry\");").Should().BeTrue();

citiesSpatialMappingContent.Contains("builder.Property(t => t.GeographyField)" + System.Environment.NewLine +
citiesSpatialMappingContent.Contains("builder.Property(t => t.GeographyField)" + System.Environment.NewLine +
" .IsRequired()" + System.Environment.NewLine +
" .HasColumnName(\"GeographyField\")" + System.Environment.NewLine +
" .HasColumnType(\"geography\");").Should().BeTrue();

}
}

}

0 comments on commit b1ffe17

Please sign in to comment.