-
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.
CDMS-200 adding decision integration tests & refactoring ApplicationF…
…actory
- Loading branch information
1 parent
1863b79
commit e30d145
Showing
8 changed files
with
175 additions
and
29 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
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,46 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Btms.Common.Extensions; | ||
using Btms.Model; | ||
using Btms.SyncJob; | ||
using Btms.Backend.IntegrationTests.JsonApiClient; | ||
using FluentAssertions; | ||
using System.Net; | ||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization; | ||
using Btms.Backend.IntegrationTests.Extensions; | ||
using Btms.Backend.IntegrationTests.Helpers; | ||
using Json.More; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Btms.Backend.IntegrationTests; | ||
|
||
[Trait("Category", "Integration")] | ||
public class DecsionTests(ScenarioApplicationFactory factory, ITestOutputHelper testOutputHelper) | ||
: BaseApiTests(factory, testOutputHelper), IClassFixture<ScenarioApplicationFactory> | ||
{ | ||
|
||
[Fact] | ||
public async Task SimpleChedPScenario() | ||
{ | ||
// Arrange | ||
await factory.ClearDb(Client); | ||
|
||
// Act | ||
// await MakeSyncClearanceRequest(new SyncClearanceRequestsCommand | ||
// { | ||
// SyncPeriod = SyncPeriod.All, RootFolder = "SmokeTest" | ||
// }); | ||
|
||
// Assert | ||
var jsonClientResponse = Client.AsJsonApiClient().Get("api/movements"); | ||
jsonClientResponse.Data | ||
.Where(x => x.Relationships is not null) | ||
.SelectMany(x => x.Relationships!) | ||
.Any(x => x.Value is { Links: not null }) | ||
.Should().Be(false); | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
Btms.Backend.IntegrationTests/Helpers/ApplicationFactory.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,93 @@ | ||
using Btms.Backend.Data; | ||
using Btms.BlobService; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using MongoDB.Bson.Serialization.Conventions; | ||
using MongoDB.Driver; | ||
using Xunit.Abstractions; | ||
|
||
namespace Btms.Backend.IntegrationTests.Helpers; | ||
|
||
public interface IIntegrationTestsApplicationFactory | ||
{ | ||
ITestOutputHelper TestOutputHelper { get; set; } | ||
string DatabaseName { get; set; } | ||
|
||
HttpClient CreateClient(WebApplicationFactoryClientOptions options); | ||
HttpClient CreateClient(); | ||
IMongoDbContext GetDbContext(); | ||
Task ClearDb(HttpClient client); | ||
} | ||
|
||
public class ApplicationFactory : WebApplicationFactory<Program>, IIntegrationTestsApplicationFactory | ||
{ | ||
// protected override Bef | ||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
// Any integration test overrides could be added here | ||
// And we don't want to load the backend ini file | ||
var configurationValues = new Dictionary<string, string> | ||
{ | ||
{ "DisableLoadIniFile", "true" }, | ||
{ "BlobServiceOptions:CachePath", "../../../Fixtures" }, | ||
{ "BlobServiceOptions:CacheReadEnabled", "true" }, | ||
{ "AuthKeyStore:Credentials:IntTest", "Password" } | ||
}; | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(configurationValues!) | ||
.Build(); | ||
|
||
builder | ||
.UseConfiguration(configuration) | ||
.ConfigureServices(services => | ||
{ | ||
var mongoDatabaseDescriptor = services.SingleOrDefault(d => d.ServiceType == typeof(IMongoDatabase))!; | ||
services.Remove(mongoDatabaseDescriptor); | ||
|
||
var blobOptionsValidatorDescriptor = services.SingleOrDefault(d => d.ServiceType == typeof(IValidateOptions<BlobServiceOptions>))!; | ||
services.Remove(blobOptionsValidatorDescriptor); | ||
|
||
services.AddSingleton(sp => | ||
{ | ||
var options = sp.GetService<IOptions<MongoDbOptions>>()!; | ||
var settings = MongoClientSettings.FromConnectionString(options.Value.DatabaseUri); | ||
var client = new MongoClient(settings); | ||
|
||
var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() }; | ||
// convention must be registered before initialising collection | ||
ConventionRegistry.Register("CamelCase", camelCaseConvention, _ => true); | ||
|
||
var dbName = string.IsNullOrEmpty(DatabaseName) ? Random.Shared.Next().ToString() : DatabaseName; | ||
return client.GetDatabase($"Btms_MongoDb_{dbName}_Test"); | ||
}); | ||
|
||
services.AddLogging(lb => lb.AddXUnit(TestOutputHelper)); | ||
}); | ||
|
||
builder.UseEnvironment("Development"); | ||
} | ||
|
||
public ITestOutputHelper TestOutputHelper { get; set; } = null!; | ||
|
||
public string DatabaseName { get; set; } = null!; | ||
|
||
public IMongoDbContext GetDbContext() | ||
{ | ||
return Services.CreateScope().ServiceProvider.GetRequiredService<IMongoDbContext>(); | ||
} | ||
|
||
// public new HttpClient CreateClient() | ||
// { | ||
// throw new NotImplementedException(); | ||
// } | ||
|
||
public async Task ClearDb(HttpClient client) | ||
{ | ||
await client.GetAsync("mgmt/collections/drop"); | ||
} | ||
} |
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
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