-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
CleanArchitecture.IntegrationTests/ExternalServices/RedisTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using CleanArchitecture.Domain.Entities; | ||
using CleanArchitecture.Infrastructure.Database; | ||
using CleanArchitecture.IntegrationTests.Fixtures; | ||
using Microsoft.Extensions.Caching.Distributed; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace CleanArchitecture.IntegrationTests.ExternalServices; | ||
|
||
public sealed class RedisTestFixture : TestFixtureBase | ||
{ | ||
public Guid CreatedTenantId { get; } = Guid.NewGuid(); | ||
|
||
public IDistributedCache DistributedCache { get; } | ||
|
||
public RedisTestFixture() | ||
{ | ||
DistributedCache = Factory.Services.GetRequiredService<IDistributedCache>(); | ||
} | ||
|
||
public async Task SeedTestData() | ||
{ | ||
await GlobalSetupFixture.RespawnDatabaseAsync(); | ||
|
||
using var context = Factory.Services.GetRequiredService<ApplicationDbContext>(); | ||
|
||
context.Tenants.Add(new Tenant( | ||
CreatedTenantId, | ||
"Test Tenant")); | ||
|
||
await context.SaveChangesAsync(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
CleanArchitecture.IntegrationTests/ExternalServices/RedisTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Threading.Tasks; | ||
using CleanArchitecture.Application.ViewModels.Tenants; | ||
using CleanArchitecture.Domain; | ||
using CleanArchitecture.Domain.Entities; | ||
using CleanArchitecture.IntegrationTests.Extensions; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Caching.Distributed; | ||
using Newtonsoft.Json; | ||
|
||
namespace CleanArchitecture.IntegrationTests.ExternalServices; | ||
|
||
public sealed class RedisTests | ||
{ | ||
private readonly RedisTestFixture _fixture = new(); | ||
|
||
[OneTimeSetUp] | ||
public async Task Setup() => await _fixture.SeedTestData(); | ||
|
||
[Test, Order(0)] | ||
public async Task Should_Get_Tenant_By_Id_And_Ensure_Cache() | ||
{ | ||
var response = await _fixture.ServerClient.GetAsync($"/api/v1/Tenant/{_fixture.CreatedTenantId}"); | ||
var message = await response.Content.ReadAsJsonAsync<TenantViewModel>(); | ||
message!.Data!.Id.Should().Be(_fixture.CreatedTenantId); | ||
|
||
var json = await _fixture.DistributedCache.GetStringAsync(CacheKeyGenerator.GetEntityCacheKey<Tenant>(_fixture.CreatedTenantId)); | ||
json.Should().NotBeNullOrEmpty(); | ||
|
||
var tenant = JsonConvert.DeserializeObject<TenantViewModel>(json!)!; | ||
|
||
tenant.Should().NotBeNull(); | ||
tenant.Id.Should().Be(_fixture.CreatedTenantId); | ||
} | ||
} |