Skip to content

Commit b6b10f5

Browse files
committed
ch: update assertions for the dotnenv options tests
1 parent f14de83 commit b6b10f5

2 files changed

Lines changed: 69 additions & 24 deletions

File tree

README.md

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
[![Coverage Status](https://coveralls.io/repos/github/bolorundurowb/dotenv.net/badge.svg?branch=master)](https://coveralls.io/github/bolorundurowb/dotenv.net?branch=master)
66
![NuGet Version](https://img.shields.io/nuget/v/dotenv.net)
77

8-
98
[![project icon](https://res.cloudinary.com/dg2dgzbt4/image/upload/v1587070177/external_assets/open_source/icons/dotenv.png)]()
109

11-
**dotenv.net** is a lightweight and intuitive library designed to simplify the process of managing environment variables in .NET applications. By seamlessly integrating with `.env` files, it allows developers to maintain a clean and secure configuration setup, ensuring that sensitive information is kept out of source code. 🔒
10+
**dotenv.net** is a lightweight and intuitive library designed to simplify the process of managing environment variables
11+
in .NET applications. By seamlessly integrating with `.env` files, it allows developers to maintain a clean and secure
12+
configuration setup, ensuring that sensitive information is kept out of source code. 🔒
1213

13-
Whether you're building a small project or a large-scale application, **dotenv.net** provides the tools you need to efficiently load, read, and manage environment variables, with support for dependency injection (DI) in popular DI systems. 🛠️
14+
Whether you're building a small project or a large-scale application, **dotenv.net** provides the tools you need to
15+
efficiently load, read, and manage environment variables, with support for dependency injection (DI) in popular DI
16+
systems. 🛠️
1417

1518
---
1619

@@ -24,6 +27,45 @@ Whether you're building a small project or a large-scale application, **dotenv.n
2427

2528
---
2629

30+
## What's New in v4? 🚀
31+
32+
**dotenv.net v4** is a major release featuring significant improvements to simplify environment management in .NET
33+
applications. This release includes important fixes, enhanced validation, and new capabilities while maintaining
34+
backward compatibility. 🔥
35+
36+
### Major Improvements
37+
38+
- **Validation Enhancements**: Added strict validation in `DotEnvOptions` to prevent invalid configurations
39+
- **Path Probing Fix**: Fixed environment file path reporting in probe exceptions (#56)
40+
- **SRP Refactoring**: Codebase restructured for better maintainability
41+
- **Comment Escaping**: Support escaping comments with backslash (`\# comment`)
42+
43+
### Breaking Changes ⚠️
44+
45+
1. **Mutually Exclusive Options**:
46+
- `envFilePaths` and `probeForEnv` are now mutually exclusive (throws `InvalidOperationException`)
47+
```csharp
48+
// INVALID: Will throw exception
49+
new DotEnvOptions(
50+
envFilePaths: ["./custom.env"],
51+
probeForEnv: true
52+
);
53+
54+
2. **Order-Sensitive Overwriting**:
55+
- `overwriteExistingVars` now respects file sequence order
56+
```csharp
57+
58+
// Later files override earlier ones when overwrite=true
59+
DotEnv.Load(options: new DotEnvOptions(
60+
envFilePaths: [".env.first", ".env.second"] // .env.second takes precedence
61+
));
62+
```
63+
64+
3. **Deprecated Methods Removed**:
65+
- All pre-v3 deprecated methods have been removed
66+
67+
---
68+
2769
## Getting Started 🚀
2870

2971
### Installation 📦
@@ -42,7 +84,7 @@ You can install **dotenv.net** via NuGet:
4284

4385
- **Manual Installation** (via `.csproj`):
4486
```xml
45-
<PackageReference Include="dotenv.net" Version="3.0.0"/>
87+
<PackageReference Include="dotenv.net" Version="4.0.0"/>
4688
```
4789

4890
---
@@ -81,7 +123,7 @@ You can install **dotenv.net** via NuGet:
81123

82124
- **Search for `.env` Files in Parent Directories**:
83125
```csharp
84-
DotEnv.Load(options: new DotEnvOptions(probeForEnv: true, probeLevelsToSearch: 2));
126+
DotEnv.Load(options: new DotEnvOptions(probeForEnv: true, probeLevelsToSearch: 2)); // will search the assembly dir, the parent and grand-parent dir
85127
```
86128

87129
- **Trim Whitespace from Values**:
@@ -119,17 +161,15 @@ DotEnv.Fluent()
119161
.WithTrimValues()
120162
.WithEncoding(Encoding.ASCII)
121163
.WithOverwriteExistingVars()
122-
.WithProbeForEnv(probeLevelsToSearch: 6)
123164
.Load();
124165

125166
// Read environment variables
126167
var envVars = DotEnv.Fluent()
127168
.WithoutExceptions()
128-
.WithEnvFiles() // Defaults to .env
129169
.WithoutTrimValues()
130170
.WithDefaultEncoding()
131171
.WithoutOverwriteExistingVars()
132-
.WithoutProbeForEnv()
172+
.WithProbeForEnv(probeLevelsToSearch: 6) // searches up 6 parent directories
133173
.Read();
134174
```
135175

@@ -149,25 +189,26 @@ var boolValue = EnvReader.GetBooleanValue("ENABLE_FEATURE");
149189

150190
#### Available Methods 📋
151191

152-
| Method Name | Description | Return Type | Default (if applicable) |
153-
|---------------------------------|-----------------------------------------------------------------------------|-------------|-------------------------|
154-
| `HasValue(string key)` | Checks if a value is set for the given key. | `bool` | `N/A` |
155-
| `GetStringValue(string key)` | Retrieves a string value by key. Throws an exception if not found. | `string` | `N/A` |
156-
| `GetIntValue(string key)` | Retrieves an integer value by key. Throws an exception if not found. | `int` | `N/A` |
157-
| `GetDoubleValue(string key)` | Retrieves a double value by key. Throws an exception if not found. | `double` | `N/A` |
158-
| `GetDecimalValue(string key)` | Retrieves a decimal value by key. Throws an exception if not found. | `decimal` | `N/A` |
159-
| `GetBooleanValue(string key)` | Retrieves a boolean value by key. Throws an exception if not found. | `bool` | `N/A` |
160-
| `TryGetStringValue(string key, out string value)` | Safely retrieves a string value. Returns `true` if successful. | `bool` | `null` |
161-
| `TryGetIntValue(string key, out int value)` | Safely retrieves an integer value. Returns `true` if successful. | `bool` | `0` |
162-
| `TryGetDoubleValue(string key, out double value)` | Safely retrieves a double value. Returns `true` if successful. | `bool` | `0.0` |
163-
| `TryGetDecimalValue(string key, out decimal value)` | Safely retrieves a decimal value. Returns `true` if successful. | `bool` | `0.0m` |
164-
| `TryGetBooleanValue(string key, out bool value)` | Safely retrieves a boolean value. Returns `true` if successful. | `bool` | `false` |
192+
| Method Name | Description | Return Type | Default (if applicable) |
193+
|-----------------------------------------------------|----------------------------------------------------------------------|-------------|-------------------------|
194+
| `HasValue(string key)` | Checks if a value is set for the given key. | `bool` | `N/A` |
195+
| `GetStringValue(string key)` | Retrieves a string value by key. Throws an exception if not found. | `string` | `N/A` |
196+
| `GetIntValue(string key)` | Retrieves an integer value by key. Throws an exception if not found. | `int` | `N/A` |
197+
| `GetDoubleValue(string key)` | Retrieves a double value by key. Throws an exception if not found. | `double` | `N/A` |
198+
| `GetDecimalValue(string key)` | Retrieves a decimal value by key. Throws an exception if not found. | `decimal` | `N/A` |
199+
| `GetBooleanValue(string key)` | Retrieves a boolean value by key. Throws an exception if not found. | `bool` | `N/A` |
200+
| `TryGetStringValue(string key, out string value)` | Safely retrieves a string value. Returns `true` if successful. | `bool` | `null` |
201+
| `TryGetIntValue(string key, out int value)` | Safely retrieves an integer value. Returns `true` if successful. | `bool` | `0` |
202+
| `TryGetDoubleValue(string key, out double value)` | Safely retrieves a double value. Returns `true` if successful. | `bool` | `0.0` |
203+
| `TryGetDecimalValue(string key, out decimal value)` | Safely retrieves a decimal value. Returns `true` if successful. | `bool` | `0.0m` |
204+
| `TryGetBooleanValue(string key, out bool value)` | Safely retrieves a boolean value. Returns `true` if successful. | `bool` | `false` |
165205

166206
---
167207

168208
## Contributing 🤝
169209

170-
We welcome contributions from the community! If you have ideas, bug reports, or feature requests, please [open an issue](https://github.com/bolorundurowb/dotenv.net/issues) or submit a pull request.
210+
We welcome contributions from the community! If you have ideas, bug reports, or feature requests,
211+
please [open an issue](https://github.com/bolorundurowb/dotenv.net/issues) or submit a pull request.
171212

172213
### Special Thanks to Our Contributors 🙏
173214

@@ -177,7 +218,7 @@ A huge shoutout to everyone who has contributed to **dotenv.net**:
177218
[@merqlove](https://github.com/merqlove) [@tracker1](https://github.com/tracker1) [@NaturalWill](https://github.com/NaturalWill)
178219
[@texyh](https://github.com/texyh) [@jonlabelle](https://github.com/jonlabelle) [@Gounlaf](https://github.com/Gounlaf)
179220
[@DTTerastar](https://github.com/DTTerastar) [@Mondonno](https://github.com/Mondonno) [@caveman-dick](https://github.com/caveman-dick)
180-
[@VijoPlays](https://github.com/VijoPlays) [bobbyg603](https://github.com/bobbyg603)
221+
[@VijoPlays](https://github.com/VijoPlays) [@bobbyg603](https://github.com/bobbyg603)
181222

182223
---
183224

@@ -189,6 +230,7 @@ A huge shoutout to everyone who has contributed to **dotenv.net**:
189230

190231
## Get Started Today! 🎉
191232

192-
Simplify your environment variable management with **dotenv.net**. Install the package, follow the quick start guide, and enjoy a cleaner, more secure configuration setup for your .NET applications.
233+
Simplify your environment variable management with **dotenv.net**. Install the package, follow the quick start guide,
234+
and enjoy a cleaner, more secure configuration setup for your .NET applications.
193235

194236
**Happy Coding!** 🚀

src/dotenv.net.Tests/DotEnvOptionsTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public void Read_ComplexExistingEnv_ShouldExtractValidValues()
180180
.WithProbeForEnv()
181181
.Read();
182182

183+
values.Count.ShouldBe(11);
183184
values.ShouldContainKeyAndValue("lower_case_key", "world");
184185
values.ShouldContainKeyAndValue("DOUBLE_QUOTES", "double");
185186
values.ShouldContainKeyAndValue("SINGLE_QUOTES", "single");
@@ -189,5 +190,7 @@ public void Read_ComplexExistingEnv_ShouldExtractValidValues()
189190
values.ShouldContainKeyAndValue("KeyWithNoValue", string.Empty);
190191
values.ShouldContainKeyAndValue("DOUBLE_QUOTE_EVEN_MORE_LINES",
191192
$"""this{Environment.NewLine}is{Environment.NewLine}"a{Environment.NewLine}multi-line{Environment.NewLine} value""");
193+
values.ShouldContainKeyAndValue("OidcAuthentication:ClientId", "your-client-id");
194+
values.ShouldContainKeyAndValue("OidcAuthentication:ClientSecret", "your-client-secret");
192195
}
193196
}

0 commit comments

Comments
 (0)