|
1 | | -# Ephemerally |
| 1 | +# Ephemerally |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +### Packages available on [nuget.org](https://www.nuget.org/packages?q=Ephemerally) |
| 7 | + |
| 8 | +### Full documentation available in [the wiki](../../wiki) |
2 | 9 |
|
3 | 10 | ## Create and automatically cleanup temporary external resources |
4 | 11 |
|
5 | | -Infinitely extensible by design. Just install the packages for the types of resources you'd like to exist ephemerally (or create your own!). |
| 12 | +#### Extensible by design. Just install the appropriate package and start using resources ephemerally. |
| 13 | + |
| 14 | +## Why use this instead of `testcontainers`? |
| 15 | + |
| 16 | +Creating and tearing down entire containers per-test can be time-intensive and slow things down considerably. The best use cases will combine both approaches, using `testcontainers` to provide the infrastructure for the ephemeral resources created by `Ephemerally`, for example using `testcontainers` to provide a Redis instance for the `PooledEphemeralRedisMultiplexerFixture`. |
| 17 | + |
| 18 | +There are also use cases where it is not possible to use temporary containers with something like `testcontainers`, for example when: |
| 19 | +- there is no containerized version of a resource |
| 20 | +- policy forbids it |
| 21 | +- technical challenges make it impractical |
| 22 | +- there is a specific case like performance testing, where you want or need an actual, full-scale resource |
| 23 | + |
| 24 | +## Integration |
| 25 | +Basic integration points are provided in the main `Ephemerally` namespace, typically as extension methods. |
6 | 26 |
|
7 | | -## The Convention |
8 | | -All primary integration points are provided in the main `Ephemerally` namespace, typically as extension methods. |
| 27 | +Test fixtures will be under their respective package names (e.g. `Ephemerally.Azure.Cosmos.Xunit`). |
9 | 28 |
|
10 | | -## Example Usage |
| 29 | +## Create Resources Ephemerally |
11 | 30 | To create a temporary Cosmos database and container for your persistence unit tests: |
12 | 31 | 1. Install the relevant package: |
13 | 32 | ``` |
@@ -43,13 +62,61 @@ public async Task Test_should_pass() |
43 | 62 | } |
44 | 63 | ``` |
45 | 64 |
|
| 65 | +## Test Fixtures |
| 66 | +To utilize the premade fixtures (currently only available for xUnit): |
| 67 | +1. Install the appropriate package: |
| 68 | +``` |
| 69 | +dotnet add package Ephemerally.Azure.Cosmos.Xunit |
| 70 | +``` |
| 71 | +2. Import the namespace |
| 72 | +```csharp |
| 73 | +using Ephemerally.Azure.Cosmos.Xunit; |
| 74 | +``` |
| 75 | +3. Add a fixture to your test class |
| 76 | +```csharp |
| 77 | +using Ephemerally.Azure.Cosmos.Xunit; |
| 78 | +using Xunit; |
| 79 | + |
| 80 | +public class DatabaseFixtureUsageExampleTests(EphemeralCosmosDatabaseFixture fixture) |
| 81 | + : IClassFixture<EphemeralCosmosDatabaseFixture> |
| 82 | +{ |
| 83 | + // TODO: Tests go here |
| 84 | +} |
| 85 | +``` |
| 86 | +4. Use the fixture |
| 87 | +```csharp |
| 88 | +using Ephemerally; |
| 89 | +using Ephemerally.Azure.Cosmos.Xunit; |
| 90 | +using Xunit; |
| 91 | + |
| 92 | +public class DatabaseFixtureUsageExampleTests(EphemeralCosmosDatabaseFixture fixture) |
| 93 | + : IClassFixture<EphemeralCosmosDatabaseFixture> |
| 94 | +{ |
| 95 | + [Fact] |
| 96 | + public async Task TestUsingDatabase() |
| 97 | + { |
| 98 | + // Ephemeral databases go well with ephemeral containers to keep tests isolated |
| 99 | + await using var container = await fixture.Database.CreateEphemeralContainerAsync(); |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
46 | 104 | ## Available Packages |
47 | 105 |
|
48 | 106 | ### `Ephemerally` |
49 | | -The core library with the main types. This will be included automatically as a dependency. |
| 107 | +Base package with shared types. This will be included automatically as a transitive dependency. |
50 | 108 |
|
51 | 109 | ### `Ephemerally.Azure` |
52 | 110 | Placeholder for now to hold general Azure dependencies. |
53 | 111 |
|
54 | 112 | ### `Ephemerally.Azure.Cosmos` |
55 | 113 | Contains types and extension methods for creating and using ephemeral Cosmos DB resources. |
| 114 | + |
| 115 | +### `Ephemerally.Azure.Cosmos.Xunit` |
| 116 | +xUnit fixtures for simplifying test integration with `Ephemerally.Azure.Cosmos` |
| 117 | + |
| 118 | +### `Ephemerally.Redis` |
| 119 | +Classes and methods for creating and managing the lifecycle of ephemeral Redis resources |
| 120 | + |
| 121 | +### `Ephemerally.Redis.Xunit` |
| 122 | +xUnit fixtures for simplifying test integration with `Ephemerally.Redis` |
0 commit comments