-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add base class for armory infrastructure tests
- Loading branch information
1 parent
d1e3889
commit 48354ac
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
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
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,55 @@ | ||
using System; | ||
using System.Linq; | ||
using Armory.Api; | ||
using Armory.Shared.Helpers; | ||
using Armory.Shared.Infrastructure.Persistence.EntityFramework; | ||
using Armory.Shared.Test.Infrastructure; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Armory.Test | ||
{ | ||
public class ArmoryContextInfrastructureTestCase : InfrastructureTestCase<Startup>, IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
Finish(); | ||
} | ||
|
||
protected override void Setup() | ||
{ | ||
} | ||
|
||
protected override Action<IServiceCollection> Services() | ||
{ | ||
return services => | ||
{ | ||
var descriptor = | ||
services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<ArmoryDbContext>)); | ||
if (descriptor is not null) | ||
{ | ||
services.Remove(descriptor); | ||
} | ||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(AppContext.BaseDirectory) | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
services.AddAutoMapper(AssemblyHelper.GetInstance(Assemblies.Armory)); | ||
services.AddMediatR(AssemblyHelper.GetInstance(Assemblies.Armory)); | ||
services.AddAutoMapper(typeof(Startup)); | ||
var serviceProvider = services.AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(); | ||
services.AddDbContext<ArmoryDbContext>(options => | ||
{ | ||
options.UseInMemoryDatabase(Guid.NewGuid().ToString()); | ||
options.UseInternalServiceProvider(serviceProvider); | ||
}); | ||
}; | ||
} | ||
} | ||
} |