Skip to content

Commit

Permalink
Revert "Allowed to set more Environment Infos in tests" (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperSchulz authored Feb 15, 2024
1 parent 2201668 commit 9724b46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,12 @@ codeunit 3702 "Environment Information Impl."
DefaultProductionEnvironmentNameTxt: Label 'Production', Locked = true;

procedure IsProduction(): Boolean
var
Production: Boolean;
TestMode: Boolean;
begin
OnBeforeIsProduction(TestMode, Production);
if TestMode then
exit(Production);

exit(NavTenantSettingsHelper.IsProduction())
end;

procedure IsSandbox(): Boolean
var
Sandbox: Boolean;
TestMode: Boolean;
begin
OnBeforeIsSandbox(TestMode, Sandbox);
if TestMode then
exit(Sandbox);

if TestabilitySandbox then
exit(true);

Expand All @@ -60,12 +46,7 @@ codeunit 3702 "Environment Information Impl."
procedure GetEnvironmentName(): Text
var
EnvironmentName: Text;
TestMode: Boolean;
begin
OnBeforeEnvironmentName(TestMode, EnvironmentName);
if TestMode then
exit(EnvironmentName);

EnvironmentName := NavTenantSettingsHelper.GetEnvironmentName();
if EnvironmentName <> '' then
exit(EnvironmentName);
Expand All @@ -89,13 +70,7 @@ codeunit 3702 "Environment Information Impl."
procedure IsSaaS(): Boolean
var
ServerSettings: Codeunit "Server Setting";
TestMode: Boolean;
SaaS: Boolean;
begin
OnBeforeIsSaaS(TestMode, SaaS);
if TestMode then
exit(SaaS);

if TestabilitySoftwareAsAService then
exit(true);

Expand All @@ -110,13 +85,7 @@ codeunit 3702 "Environment Information Impl."
procedure IsSaaSInfrastructure(): Boolean
var
UserAccountHelper: DotNet NavUserAccountHelper;
SaaSInfrastructure: Boolean;
TestMode: Boolean;
begin
OnBeforeIsSaaSInfrastructure(TestMode, SaaSInfrastructure);
if TestMode then
exit(SaaSInfrastructure);

if TestabilitySoftwareAsAService then
exit(true);

Expand All @@ -134,28 +103,15 @@ codeunit 3702 "Environment Information Impl."
end;

procedure GetApplicationFamily(): Text
var
TestMode: Boolean;
ApplicationFamily: Text;
begin
OnBeforeApplicationFamily(TestMode, ApplicationFamily);
if TestMode then
exit(ApplicationFamily);

exit(NavTenantSettingsHelper.GetApplicationFamily());
end;

procedure VersionInstalled(AppID: Guid): Integer
var
AppInfo: ModuleInfo;
WhichVersionInstalled: Integer;
TestMode: Boolean;
begin
OnBeforeVersionInstalled(TestMode, WhichVersionInstalled);
if TestMode then
exit(WhichVersionInstalled);

NavApp.GetModuleInfo(AppId, AppInfo);
NavApp.GetModuleInfo(AppID, AppInfo);
exit(AppInfo.DataVersion.Major());
end;

Expand Down Expand Up @@ -198,54 +154,5 @@ codeunit 3702 "Environment Information Impl."
// An event which asks for the AppId to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeIsSaaSInfrastructure(var TestMode: Boolean; var IsSaaSInfrastructure: Boolean)
begin
// An event which asks for the IsSaaSInfrastructure to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeVersionInstalled(var TestMode: Boolean; var VersionInstalled: Integer)
begin
// An event which asks for the VersionInstalled to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeIsSaaS(var TestMode: Boolean; var IsSaaS: Boolean)
begin
// An event which asks for the IsSaaS to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeEnvironmentName(var TestMode: Boolean; var EnvironmentName: Text)
begin
// An event which asks for the EnvironmentName to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeIsSandbox(var TestMode: Boolean; var IsSandbox: Boolean)
begin
// An event which asks for the IsSandbox to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeIsProduction(var TestMode: Boolean; var IsProduction: Boolean)
begin
// An event which asks for the IsProduction to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;

[InternalEvent(false)]
procedure OnBeforeApplicationFamily(var TestMode: Boolean; var ApplicationFamily: Text)
begin
// An event which asks for the ApplicationFamily to be filled in by the subscriber.
// Do not use this event in a production environment. This should be subscribed to only in tests.
end;
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ codeunit 135094 "Environment Info Test Library"
var
EnvironmentInformationImpl: Codeunit "Environment Information Impl.";
TestAppId: Text;
TestApplicationFamily: Text;
TestIsProduction: Boolean;
TestIsSandbox: Boolean;
TestEnvironmentName: Text;
TestIsSaaS: Boolean;
TestVersionInstalled: Integer;
TestIsSaaSInfrastructure: Boolean;

/// <summary>
/// Sets the testability sandbox flag.
Expand All @@ -30,6 +23,7 @@ codeunit 135094 "Environment Info Test Library"
/// This functions should only be used for testing purposes.
/// </remarks>
/// <param name="EnableSandboxForTest">The value to be set to the testability sandbox flag.</param>
[Scope('OnPrem')]
procedure SetTestabilitySandbox(EnableSandboxForTest: Boolean)
begin
EnvironmentInformationImpl.SetTestabilitySandbox(EnableSandboxForTest);
Expand All @@ -42,91 +36,23 @@ codeunit 135094 "Environment Info Test Library"
/// This functions should only be used for testing purposes.
/// </remarks>
/// <param name="EnableSoftwareAsAServiceForTest">The value to be set to the testability SaaS flag.</param>
[Scope('OnPrem')]
procedure SetTestabilitySoftwareAsAService(EnableSoftwareAsAServiceForTest: Boolean)
begin
EnvironmentInformationImpl.SetTestabilitySoftwareAsAService(EnableSoftwareAsAServiceForTest);
end;

/// <summary>
/// Sets the App ID that of the current application (for example, 'FIN' - Financials) when the subscription is bound.
/// Sets the App ID that of the current application (for example, 'FIN' - Financials) when the sunscription is bound.
/// Uses <see cref="OnBeforeGetApplicationIdentifier"/> event.
/// </summary>
/// <param name="NewAppId">The desired ne App ID.</param>
[Scope('OnPrem')]
procedure SetAppId(NewAppId: Text)
begin
TestAppId := NewAppId;
end;

/// <summary>
/// Sets the Is SaaS Infrastructure that of the current Environment when the subscription is bound.
/// Uses <see cref="OnBeforeIsSaaSInfrastructure"/> event.
/// </summary>
/// <param name="NewIsSaaSInfrastructure">The desired new Is SaaS Infrastructure.</param>
procedure SetIsSaaSInfrastructure(NewIsSaaSInfrastructure: Boolean)
begin
TestIsSaaSInfrastructure := NewIsSaaSInfrastructure;
end;

/// <summary>
/// Sets the App Version that of the current application when the subscription is bound.
/// Uses <see cref="OnBeforeVersionInstalled"/> event.
/// </summary>
/// <param name="NewVersionInstalled">The desired new Version Installed</param>
procedure SetVersionInstalled(NewVersionInstalled: Integer)
begin
TestVersionInstalled := NewVersionInstalled;
end;

/// <summary>
/// Sets the IsSaas of the current environment when the subscription is bound.
/// Uses <see cref="OnBeforeIsSaaS"/> event.
/// </summary>
/// <param name="NewIsSaaS">The desired new Is SaaS</param>
procedure SetIsSaaS(NewIsSaaS: Boolean)
begin
TestIsSaaS := NewIsSaaS;
end;

/// <summary>
/// Sets the Environment Name of the current environment when the subscription is bound.
/// Uses <see cref="OnBeforeEnvironmentName"/> event.
/// </summary>
/// <param name="NewEnvironmentName">The desired new Environment Name.</param>
procedure SetEnvironmentName(NewEnvironmentName: Text)
begin
TestEnvironmentName := NewEnvironmentName;
end;

/// <summary>
/// Sets the IsSandbox that of the current environment when the subscription is bound.
/// Uses <see cref="OnBeforeIsSandbox"/> event.
/// </summary>
/// <param name="NewIsSandbox">The desired ne App ID.</param>
procedure SetIsSandbox(NewIsSandbox: Boolean)
begin
TestIsSandbox := NewIsSandbox;
end;

/// <summary>
/// Sets the IsProduction that of the current environment when the subscription is bound.
/// Uses <see cref="OnBeforeIsProduction"/> event.
/// </summary>
/// <param name="NewIsProduction">The desired new is production.</param>
procedure SetIsProduction(NewIsProduction: Boolean)
begin
TestIsProduction := NewIsProduction;
end;

/// <summary>
/// Sets the Application Family that of the current application when the subscription is bound.
/// Uses <see cref="OnBeforeApplicationFamily"/> event.
/// </summary>
/// <param name="NewApplicationFamily">The desired new Application Family.</param>
procedure SetApplicationFamily(NewApplicationFamily: Text)
begin
TestApplicationFamily := NewApplicationFamily;
end;

/// <summary>
/// Overwrite the current App ID.
/// </summary>
Expand All @@ -136,88 +62,5 @@ codeunit 135094 "Environment Info Test Library"
begin
AppId := TestAppId;
end;

/// <summary>
/// Overwrite the current Application Family
/// </summary>
/// <param name="ApplicationFamily">The current Application Family.</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeApplicationFamily', '', false, false)]
local procedure SetApplicationFamilyOnBeforeApplicationFamily(var TestMode: Boolean; var ApplicationFamily: Text)
begin
TestMode := true;
ApplicationFamily := TestApplicationFamily;
end;

/// <summary>
/// Overwrite Is SaaS Infrastructure.
/// </summary>
/// <param name="TestMode">Sets Test Mode</param>
/// <param name="IsSaaSInfrastructure">The current Is SaaS Infrastructure.</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeIsSaaSInfrastructure', '', false, false)]
local procedure SetIsSaaSInfrastructureOnBeforeIsSaaSInfrastructure(var TestMode: Boolean; var IsSaaSInfrastructure: Boolean)
begin
TestMode := true;
IsSaaSInfrastructure := TestIsSaaSInfrastructure;
end;

/// <summary>
/// Overwrite the current Version Installed.
/// </summary>
/// <param name="TestMode">Sets Test Mode</param>
/// <param name="VersionInstalled">The current Version Installed</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeVersionInstalled', '', false, false)]
local procedure SetVersionInstalledOnBeforeVersionInstalled(var TestMode: Boolean; var VersionInstalled: Integer)
begin
TestMode := true;
VersionInstalled := TestVersionInstalled;
end;

/// <summary>
/// Overwrite the current Is SaaS.
/// </summary>
/// <param name="TestMode">Sets Test Mode</param>
/// <param name="IsSaaS">The current Is SaaS</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeIsSaaS', '', false, false)]
local procedure SetIsSaaSOnBeforeIsSaaS(var TestMode: Boolean; var IsSaaS: Boolean)
begin
TestMode := true;
IsSaaS := TestIsSaaS;
end;

/// <summary>
/// Overwrite the current Environment Name.
/// </summary>
/// <param name="TestMode">Sets Test Mode</param>
/// <param name="EnvironmentName">The current Environment Name.</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeEnvironmentName', '', false, false)]
local procedure SetEnvironmentNameOnBeforeEnvironmentName(var TestMode: Boolean; var EnvironmentName: Text)
begin
TestMode := true;
EnvironmentName := TestEnvironmentName;
end;

/// <summary>
/// Overwrite the current Is Sandbox.
/// </summary>
/// <param name="TestMode">Sets Test Mode</param>
/// <param name="IsSandbox">The current Is Sandbox.</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeIsSandbox', '', false, false)]
local procedure SetIsSandboxOnBeforeIsSandbox(var TestMode: Boolean; var IsSandbox: Boolean)
begin
TestMode := true;
IsSandbox := TestIsSandbox;
end;

/// <summary>
/// Overwrite the current Is Production.
/// </summary>
/// <param name="TestMode">Sets Test Mode</param>
/// <param name="IsSandbox">The current Is Sandbox.</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Information Impl.", 'OnBeforeIsProduction', '', false, false)]
local procedure SetIsProductionOnBeforeIsProduction(var TestMode: Boolean; var IsProduction: Boolean)
begin
TestMode := true;
IsProduction := TestIsProduction;
end;
}

Loading

0 comments on commit 9724b46

Please sign in to comment.