surwren
surwren
Explore posts from servers
CC#
Created by surwren on 1/22/2025 in #help
Seeding DB for Integration Test
From what I understand I can change my ControllerTests to something like this:
public class ControllerTests : IAsyncLifetime {
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build();
private readonly IServiceProvider _serviceProvider;

public ControllerTests() {
var services = new ServiceCollection();
services.AddSingleton(_msSqlContainer);
services.AddScoped<DatabaseSeeder>();
_serviceProvider = services.BuildServiceProvider();
}

public async Task InitializeAsync() {
await _msSqlContainer.StartAsync();

using (var scope = _serviceProvider.CreateScope()) {
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
dbContext.Database.Migrate();
var seeder = scope.ServiceProvider.GetRequiredService<DatabaseSeeder>();
await seeder.SeedAsync();
}
}
...
public class ControllerTests : IAsyncLifetime {
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build();
private readonly IServiceProvider _serviceProvider;

public ControllerTests() {
var services = new ServiceCollection();
services.AddSingleton(_msSqlContainer);
services.AddScoped<DatabaseSeeder>();
_serviceProvider = services.BuildServiceProvider();
}

public async Task InitializeAsync() {
await _msSqlContainer.StartAsync();

using (var scope = _serviceProvider.CreateScope()) {
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
dbContext.Database.Migrate();
var seeder = scope.ServiceProvider.GetRequiredService<DatabaseSeeder>();
await seeder.SeedAsync();
}
}
...
But is this the best way to do it? Do I need to inject a different service in just to seed? What are the common modern ways used for Integration tests?
2 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
I'll give it a shot next time, ty for heads up
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
then it worked right after restarting I had closed/reopened MSVS multiple times before
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
I didn't do this I just restarted the entire PC when I saw the replies as a last ditch before I attempted it
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
at least it works now
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
TIL
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
yea anyway I didn't know VS could do stuff that required PC restart to kick in 😔
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
next round
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
how to check size before I attempt it
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
I'll try that next time
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
all I did was restart PC
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
No description
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
nvm, VS indeed drunk
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
It doesn't say anything also it got removed after restarting a few times
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
I can also confirm that ..\testcontainers-dotnet\examples\WeatherForecast\Directory.Packages.props has the entry <PackageVersion Include="Selenium.WebDriver.ChromeDriver" Version="131.0.6778.26400" /> Right click -> Restore Nuget packages also does nothing since I get
All packages are already installed and there is nothing to restore.
Time Elapsed: 00:00:00.0077776
========== Finished ==========
All packages are already installed and there is nothing to restore.
Time Elapsed: 00:00:00.0077776
========== Finished ==========
40 replies
CC#
Created by surwren on 1/22/2025 in #help
✅ Nuget Package Manager does not seem to be updating (How to Troubleshoot?)
No description
40 replies
CC#
Created by surwren on 1/20/2025 in #help
✅ Mocking DB operations
thanks
134 replies
CC#
Created by surwren on 1/20/2025 in #help
✅ Mocking DB operations
134 replies
CC#
Created by surwren on 1/20/2025 in #help
✅ Mocking DB operations
ok nvm I found some in their git repo
134 replies
CC#
Created by surwren on 1/20/2025 in #help
✅ Mocking DB operations
Just so I can reference in case I get stuck
134 replies