-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase code coverage through discovery (#398)
* Update IMM * WIP - Multimode function test * Pass configuration in in-process function tests * Make TenancyAPIFeature tests(InProcessEmulateFunction...) pass We've introduced a TenancyResponse type to wrap around HttpResponse so that we can test in different function enviroments * Add separate Bindings class for DirectInvocation To test direct invocation we need to add configuration independent of `ClientBindings`. * WIP DirectInvocation tests for tenancyApiFeature * Fix remaining direct invocation tests * Change IConfiguration to IConfigurationRoot * Avoid specifying well known child tenant Id We get a 409 from Azure Storage because it thinks we're trying to create a container with the same name as one we just deleted. This is because the side effect of specifying a tenant Id causes a container of the same name to be created in Azure Blob Storage. * Address nullability warnings I've made etag parameter for `TenancyService.GetTenantAsync` nullable as the method that refers to it (tenantStore.GetTenantAsync`) also has a nullable etag parameter * Exclude files from code coverage * Update Endjin.RecommendedPractices.Build version * remove unused feature tag Co-authored-by: Ian Griffiths <Ian.Griffiths@endjin.com> Co-authored-by: Ian Griffiths <ian@interact-sw.co.uk>
- Loading branch information
1 parent
b380fed
commit 788571a
Showing
21 changed files
with
1,421 additions
and
148 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
81 changes: 81 additions & 0 deletions
81
Solutions/Marain.Tenancy.Specs/Integration/Bindings/TenancyServiceBindings.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,81 @@ | ||
// <copyright file="TenancyClientBindings.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Marain.Tenancy.Specs.Integration.Bindings | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Corvus.Storage.Azure.BlobStorage; | ||
using Corvus.Testing.SpecFlow; | ||
using Marain.Tenancy.Client; | ||
using Menes; | ||
using Menes.Internal; | ||
using Menes.Links; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
using TechTalk.SpecFlow; | ||
|
||
/// <summary> | ||
/// Bindings for the integration tests for <see cref="TenancyService"/>. | ||
/// </summary> | ||
[Binding] | ||
public static class TenancyServiceBindings | ||
{ | ||
/// <summary> | ||
/// Configures the DI container before tests start. | ||
/// </summary> | ||
/// <param name="featureContext">The SpecFlow test context.</param> | ||
/// | ||
[BeforeFeature("withTenancyClient", Order = ContainerBeforeFeatureOrder.PopulateServiceCollection)] | ||
public static void SetupFeature(FeatureContext featureContext) | ||
{ | ||
ContainerBindings.ConfigureServices( | ||
featureContext, | ||
serviceCollection => | ||
{ | ||
if (FunctionBindings.TestHostMode == MultiHost.TestHostModes.DirectInvocation) | ||
{ | ||
IConfiguration config = new ConfigurationBuilder() | ||
.AddEnvironmentVariables() | ||
.AddJsonFile("local.settings.json", true, true) | ||
.Build(); | ||
serviceCollection.AddSingleton(config); | ||
|
||
serviceCollection.AddSingleton(sp => sp.GetRequiredService<IConfiguration>().Get<TenancyClientOptions>()); | ||
|
||
BlobContainerConfiguration rootStorageConfiguration = config | ||
.GetSection("RootBlobStorageConfiguration") | ||
.Get<BlobContainerConfiguration>(); | ||
|
||
serviceCollection.AddTenantStoreOnAzureBlobStorage(rootStorageConfiguration); | ||
|
||
serviceCollection.AddSingleton<SimpleOpenApiContext>(); | ||
serviceCollection.AddTenancyApiWithOpenApiActionResultHosting(ConfigureOpenApiHost); | ||
} | ||
}); | ||
} | ||
|
||
private static void ConfigureOpenApiHost(IOpenApiHostConfiguration config) | ||
{ | ||
if (config == null) | ||
{ | ||
throw new ArgumentNullException(nameof(config), "AddTenancyApi callback: config"); | ||
} | ||
|
||
if (config.Documents == null) | ||
{ | ||
throw new ArgumentNullException(nameof(config.Documents), "AddTenancyApi callback: config.Documents"); | ||
} | ||
|
||
config.Documents.AddSwaggerEndpoint(); | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
Solutions/Marain.Tenancy.Specs/Integration/Features/TenancyApi.feature.multi.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,14 @@ | ||
using Marain.Tenancy.Specs.MultiHost; | ||
|
||
namespace Marain.Tenancy.Specs.Integration.Features | ||
{ | ||
[MultiHostTest] | ||
|
||
public partial class TenancyApiFeature : MultiTestHostBase | ||
{ | ||
public TenancyApiFeature(TestHostModes hostMode) | ||
: base(hostMode) | ||
{ | ||
} | ||
} | ||
} |
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
Oops, something went wrong.