tuitio/test/UnitTests/Tuitio.Application.Tests/LocalSqliteDatabaseTests.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2023-03-13 18:36:59 +02:00
// Copyright (c) 2020 Tudor Stanciu
using Microsoft.EntityFrameworkCore;
2023-03-10 20:11:11 +02:00
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Threading.Tasks;
2023-03-10 20:11:11 +02:00
using Tuitio.Application.Tests.Fixtures;
using Tuitio.Domain.Data.DbContexts;
using Xunit;
namespace Tuitio.Application.Tests
{
public class LocalSqliteDatabaseTests : IClassFixture<DependencyInjectionFixture>, IDisposable
{
private readonly IServiceScope _tuitioScope;
public LocalSqliteDatabaseTests(DependencyInjectionFixture fixture)
{
_tuitioScope = fixture.ServiceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
}
public void Dispose()
{
_tuitioScope.Dispose();
}
[Fact]
public async Task EnsureExpectedDataInLocalDbTest()
{
// Arrange
var _dbContext = _tuitioScope.ServiceProvider.GetRequiredService<TuitioDbContext>();
// Act
var statuses = await _dbContext.UserStatuses.ToArrayAsync();
// Assert
Assert.NotEmpty(statuses);
Assert.True(statuses.All(z => !string.IsNullOrWhiteSpace(z.StatusCode)));
Assert.Contains(statuses, z => z.StatusCode == "ACTIVE");
}
}
}