Skip to content

Commit

Permalink
add test for media cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
haoranpb committed Sep 30, 2024
1 parent 177669e commit ecefc98
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,46 @@ codeunit 135018 "Media Cleanup Test"
LibraryAssert.IsTrue(TempTenantMedia.IsEmpty(), 'Detached Tenant media was not cleaned up properly.');
end;

[Test]
procedure EnsureNormalMediaArePersisted()
var
TenantMedia: Record "Tenant Media";
TenantMediaSetup: Record "Tenant Media Set";
TestMediaClean: Record "Test Media Cleanup";
TempBlob: Codeunit "Temp Blob";
MediaOutStream: OutStream;
i: Integer;
begin
PermissionsMock.Set('SUPER');

TestMediaClean.Insert();

TempBlob.CreateOutStream(MediaOutStream);
MediaOutStream.WriteText('123');
TestMediaClean."Test Media".ImportStream(TempBlob.CreateInStream(), '');
TestMediaClean.Modify();

clear(TempBlob);
TempBlob.CreateOutStream(MediaOutStream);
for i := 0 to 99 do
MediaOutStream.WriteText('123');
TestMediaClean."Test Media Set".ImportStream(TempBlob.CreateInStream(), '');
TestMediaClean.Modify();

LibraryAssert.IsTrue(TestMediaClean."Test Media".HasValue(), 'Tenant Media is not correctly inserted.');
LibraryAssert.IsTrue(TestMediaClean."Test Media Set".Count() > 0, 'Tenant Media Set is not correctly inserted.');
LibraryAssert.IsFalse(TenantMedia.IsEmpty(), 'Tenant Media is not correctly inserted.');
LibraryAssert.IsFalse(TenantMediaSetup.IsEmpty(), 'Tenant Media Set is not correctly inserted.');

Codeunit.Run(Codeunit::"Media Cleanup Runner");

LibraryAssert.IsFalse(TenantMedia.IsEmpty(), 'Normal tenant media is also affected.');
LibraryAssert.IsFalse(TenantMediaSetup.IsEmpty(), 'Normal tenant media set is also affected.');

PermissionsMock.ClearAssignments();
end;


local procedure GetDetachedTenantMedia(var TempTenantMedia: Record "Tenant Media" temporary)
var
MediaCleanup: Codeunit "Media Cleanup";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Test.DataAdministration;

table 135018 "Test Media Cleanup"
{
DataClassification = CustomerContent;
InherentPermissions = RIMDX;
InherentEntitlements = RIMDX;

fields
{
field(1; "Primary Key"; Integer)
{
}
field(2; "Test Media"; Media)
{
}
field(3; "Test Media Set"; MediaSet)
{
}
}

keys
{
key(PK; "Primary Key")
{
Clustered = true;
}
}
}

0 comments on commit ecefc98

Please sign in to comment.