diff --git a/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj b/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj
index afd5ff0..49837a5 100644
--- a/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj
+++ b/ConfiguredSqlConnection/ConfiguredSqlConnection.csproj
@@ -5,8 +5,26 @@
enable
enable
5405e2de-7a05-4014-aea5-3ee845eb7fee
+ True
+
ConfiguredSqlConnection
+ 1.0.0
+ Senia,ArdenHide,Lomet
+ The Poolz
+ https://github.com/The-Poolz/ConfiguredSqlConnection
+ README.md
+ https://github.com/The-Poolz/ConfiguredSqlConnection
+ Database SQL EF
+ MIT
+ The NuGet package is a collection of utilities for working with SQL Server database connections using environment settings and secure connection strings.
+
+
+ True
+ \
+
+
+
diff --git a/ConfiguredSqlConnection/DataBaseContext.cs b/ConfiguredSqlConnection/DataBaseContext.cs
index 715afe3..dde97e8 100644
--- a/ConfiguredSqlConnection/DataBaseContext.cs
+++ b/ConfiguredSqlConnection/DataBaseContext.cs
@@ -11,14 +11,14 @@ public DataBaseContext(DbContextOptions options) : base(options
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
- var actionConnection = EnvManager.GetEnvironmentValue("ACTION_CONNECTION");
+ var actionConnection = EnvManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_ACTION_CONNECTION");
if (!string.IsNullOrEmpty(actionConnection))
{
optionsBuilder.UseSqlServer(actionConnection);
}
if (!optionsBuilder.IsConfigured)
{
- var secretValue = EnvManager.GetEnvironmentValue("SECRET_NAME_OF_CONNECTION", true);
+ var secretValue = EnvManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true);
var connectionString = new SecretManager().GetSecretValue(secretValue, "connectionString");
diff --git a/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs b/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs
index 9b67ae8..acfee50 100644
--- a/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs
+++ b/ConfiguredSqlConnection/Extensions/DbContextEnvironmentFactory.cs
@@ -14,15 +14,15 @@ public DbContextEnvironmentFactory()
public DbContextEnvironmentFactory(DbContextOptionsBuilderFactory optionsBuilderFactory)
: base(optionsBuilderFactory)
{
- dbMode = EnvManager.GetEnvironmentValue("DB_MODE", true);
- dbName = EnvManager.GetEnvironmentValue("DB_NAME");
+ dbMode = EnvManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_DB_MODE", true);
+ dbName = EnvManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_DB_NAME");
}
public virtual DataBaseContext CreateFromEnvironment()
{
- if (!Enum.TryParse(typeof(ContextOption), dbMode, true, out var optionObj) || !(optionObj is ContextOption option))
+ if (!Enum.TryParse(typeof(ContextOption), dbMode, true, out var optionObj) || optionObj is not ContextOption option)
{
- throw new ArgumentException($"Invalid value for environment variable 'DB_MODE': {dbMode}");
+ throw new ArgumentException($"Invalid value for environment variable 'CONFIGUREDSQLCONNECTION_DB_MODE': {dbMode}");
}
return Create(option, dbName);
diff --git a/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderFactory.cs b/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderFactory.cs
index 07fe58f..7674085 100644
--- a/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderFactory.cs
+++ b/ConfiguredSqlConnection/Extensions/DbContextOptionsBuilderFactory.cs
@@ -37,7 +37,7 @@ public virtual DbContextOptionsBuilder Create(ContextOption option, st
protected virtual void ConfigureProdContext()
{
- var secretValue = EnvManager.GetEnvironmentValue("SECRET_NAME_OF_CONNECTION", true);
+ var secretValue = EnvManager.GetEnvironmentValue("CONFIGUREDSQLCONNECTION_SECRET_NAME_OF_CONNECTION", true);
var connectionString = new SecretManager().GetSecretValue(secretValue, "connectionString");
diff --git a/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs b/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs
index b468522..4c05638 100644
--- a/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs
+++ b/ConfiguredSqlConnectionTests/ExtensionsTests/FactoriesTests.cs
@@ -16,14 +16,9 @@ public class FactoriesTests
public FactoriesTests()
{
contextOption = ContextOption.Prod;
-
- optionsBuilder = new DbContextOptionsBuilder()
- .UseInMemoryDatabase("dbName");
-
+ optionsBuilder = new DbContextOptionsBuilder().UseInMemoryDatabase("dbName");
var mockOptionsBuilderFactory = new Mock>();
- mockOptionsBuilderFactory.Setup(x => x.Create(contextOption, null))
- .Returns(optionsBuilder);
-
+ mockOptionsBuilderFactory.Setup(x => x.Create(contextOption, null)).Returns(optionsBuilder);
optionsBuilderFactory = mockOptionsBuilderFactory.Object;
}
@@ -41,8 +36,8 @@ public void Create()
[Fact]
public void CreateFromEnvironment()
{
- Environment.SetEnvironmentVariable("DB_MODE", $"{contextOption}");
- Environment.SetEnvironmentVariable("DB_NAME", "");
+ Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_MODE", $"{contextOption}");
+ Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_NAME", "");
var factory = new Mock(optionsBuilderFactory);
factory.Setup(x => x.Create(contextOption, null)).CallBase();
factory.Setup(x => x.CreateFromEnvironment()).CallBase();
@@ -55,16 +50,15 @@ public void CreateFromEnvironment()
[Fact]
public void CreateFromEnvironment_OptionNotSet_ThrowException()
{
- Environment.SetEnvironmentVariable("DB_MODE", $"");
- Environment.SetEnvironmentVariable("DB_NAME", $"");
+ var expectedExceptionMessage = $"Environment variable 'CONFIGUREDSQLCONNECTION_DB_MODE' is null or empty.";
+ Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_MODE", $"");
+ Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_NAME", $"");
var factory = new Mock(optionsBuilderFactory);
factory.Setup(x => x.Create(contextOption, null)).CallBase();
factory.Setup(x => x.CreateFromEnvironment()).CallBase();
- Action testCode = () => factory.Object.CreateFromEnvironment();
+ var exception = Assert.Throws(() => factory.Object.CreateFromEnvironment());
- var exception = Assert.Throws(testCode);
- var expectedExceptionMessage = $"Environment variable 'DB_MODE' is null or empty.";
Assert.Equal(expectedExceptionMessage, exception?.InnerException?.Message);
}
@@ -72,17 +66,15 @@ public void CreateFromEnvironment_OptionNotSet_ThrowException()
public void CreateFromEnvironment_InvaledOption_ThrowException()
{
var invalidOption = "Production";
- Environment.SetEnvironmentVariable("DB_MODE", $"{invalidOption}");
- Environment.SetEnvironmentVariable("DB_NAME", $"");
+ var expectedExceptionMessage = $"Invalid value for environment variable 'CONFIGUREDSQLCONNECTION_DB_MODE': {invalidOption}";
+ Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_MODE", $"{invalidOption}");
+ Environment.SetEnvironmentVariable("CONFIGUREDSQLCONNECTION_DB_NAME", $"");
var factory = new Mock(optionsBuilderFactory);
factory.Setup(x => x.Create(contextOption, null)).CallBase();
factory.Setup(x => x.CreateFromEnvironment()).CallBase();
- Action testCode = () => factory.Object.CreateFromEnvironment();
-
- var exception = Assert.Throws(testCode);
- var expectedExceptionMessage = $"Invalid value for environment variable 'DB_MODE': {invalidOption}";
+ var exception = Assert.Throws(() => factory.Object.CreateFromEnvironment());
+
Assert.Equal(expectedExceptionMessage, exception.Message);
}
-
}
\ No newline at end of file