Skip to content

Commit

Permalink
Add new method for switching AI into offline mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Feb 21, 2022
1 parent a3fba56 commit e81c679
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
19 changes: 3 additions & 16 deletions Lombiq.Tests.UI.Samples/UITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,9 @@ protected override Task ExecuteTestAsync(
configuration.BrowserConfiguration.Headless =
TestConfigurationManager.GetBoolConfiguration("BrowserConfiguration:Headless", defaultValue: false);
// There are event handlers that you can hook into. This is just one but check out the others in
// OrchardCoreConfiguration if you're interested.
configuration.OrchardCoreConfiguration.BeforeAppStart +=
(_, argumentsBuilder) =>
{
// This is quite handy! We're adding a configuration parameter when launching the app. This
// can be used to set configuration for configuration providers, see the docs:
// https://docs.orchardcore.net/en/latest/docs/reference/core/Configuration/.
// What's happening here is that we set the Lombiq Application Insights module's parameter
// to allow us to test it. We'll get back to this later when writing the actual test.
argumentsBuilder
.Add("--OrchardCore:Lombiq_Hosting_Azure_ApplicationInsights:EnableOfflineOperation")
.Add("true");
return Task.CompletedTask;
};
// There are event handlers that you can hook into. This method sets BeforeAppStart which is just
// one of many. Check out the others in OrchardCoreConfiguration if you're interested.
configuration.OrchardCoreConfiguration.EnableApplicationInsightsOfflineOperation();
// Note that automatic HTML markup validation is enabled on every page change by default (you can
// disable it with the below config). With this, you can make sure that the HTML markup the app
Expand Down
21 changes: 21 additions & 0 deletions Lombiq.Tests.UI/Services/OrchardCoreInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ public class OrchardCoreConfiguration
public string SnapshotDirectoryPath { get; set; }
public BeforeAppStartHandler BeforeAppStart { get; set; }
public BeforeTakeSnapshotHandler BeforeTakeSnapshot { get; set; }

/// <summary>
/// Adds a command line argument to the app during <see cref="BeforeAppStart"/> that switches AI into offline
/// mode. This way it won't try to reach out to a remote server with telemetry and the test remains
/// self-sufficient.
/// </summary>
public void EnableApplicationInsightsOfflineOperation() =>
BeforeAppStart +=
(_, argumentsBuilder) =>
{
// This is quite handy! We're adding a configuration parameter when launching the app. This
// can be used to set configuration for configuration providers, see the docs:
// https://docs.orchardcore.net/en/latest/docs/reference/core/Configuration/.
// What's happening here is that we set the Lombiq Application Insights module's parameter
// to allow us to test it. We'll get back to this later when writing the actual test.
argumentsBuilder
.Add("--OrchardCore:Lombiq_Hosting_Azure_ApplicationInsights:EnableOfflineOperation")
.Add("true");
return Task.CompletedTask;
};
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ public void AssertBrowserLogMaybe(IList<BrowserLogMessage> browserLogs, Action<s
!message.Message.ContainsOrdinalIgnoreCase("HTML Imports is deprecated") &&
// The 404 is because of how browsers automatically request /favicon.ico even if a favicon is declared
// to be under a different URL.
!message.IsNotFoundMessage("/favicon.ico") &&
// Ignore if browser telemetry is not available.
!message.Message.ContainsOrdinalIgnoreCase(
"https://dc.services.visualstudio.com/v2/track - Failed to load resource: the server responded with a status of 400");
!message.IsNotFoundMessage("/favicon.ico");
}
}

0 comments on commit e81c679

Please sign in to comment.